blob: ff95397c5841abd6b92c8b67ab2941a439374a93 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
1424 mmr.memory = mem;
1425 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1426 m_errorMonitor->SetDesiredFailureMsg(
1427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 ") is less than Memory Object's offset (");
1429 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1430 m_errorMonitor->VerifyFound();
1431 // Now flush range that oversteps mapped range
1432 vkUnmapMemory(m_device->device(), mem);
1433 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1434 ASSERT_VK_SUCCESS(err);
1435 mmr.offset = 16;
1436 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1437 m_errorMonitor->SetDesiredFailureMsg(
1438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 ") exceeds the Memory Object's upper-bound (");
1440 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1441 m_errorMonitor->VerifyFound();
1442
1443 pass =
1444 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1445 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1446 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1447 if (!pass) {
1448 vkFreeMemory(m_device->device(), mem, NULL);
1449 vkDestroyBuffer(m_device->device(), buffer, NULL);
1450 return;
1451 }
1452 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1453 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1454
1455 vkDestroyBuffer(m_device->device(), buffer, NULL);
1456 vkFreeMemory(m_device->device(), mem, NULL);
1457}
1458
Ian Elliott1c32c772016-04-28 14:47:13 -06001459TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1460 VkResult err;
1461 bool pass;
1462
Ian Elliott489eec02016-05-05 14:12:44 -06001463// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1464// following declaration (which is temporarily being moved below):
1465// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001466 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1467 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1468 uint32_t swapchain_image_count = 0;
1469// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1470 uint32_t image_index = 0;
1471// VkPresentInfoKHR present_info = {};
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1476#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1477 // Use the functions from the VK_KHR_android_surface extension without
1478 // enabling that extension:
1479
1480 // Create a surface:
1481 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001482 m_errorMonitor->SetDesiredFailureMsg(
1483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1484 "extension was not enabled for this");
1485 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1486 &surface);
1487 pass = (err != VK_SUCCESS);
1488 ASSERT_TRUE(pass);
1489 m_errorMonitor->VerifyFound();
1490#endif // VK_USE_PLATFORM_ANDROID_KHR
1491
1492
1493#if defined(VK_USE_PLATFORM_MIR_KHR)
1494 // Use the functions from the VK_KHR_mir_surface extension without enabling
1495 // that extension:
1496
1497 // Create a surface:
1498 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001499 m_errorMonitor->SetDesiredFailureMsg(
1500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1501 "extension was not enabled for this");
1502 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1503 pass = (err != VK_SUCCESS);
1504 ASSERT_TRUE(pass);
1505 m_errorMonitor->VerifyFound();
1506
1507 // Tell whether an mir_connection supports presentation:
1508 MirConnection *mir_connection = NULL;
1509 m_errorMonitor->SetDesiredFailureMsg(
1510 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1511 "extension was not enabled for this");
1512 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1513 visual_id);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_MIR_KHR
1516
1517
1518#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1519 // Use the functions from the VK_KHR_wayland_surface extension without
1520 // enabling that extension:
1521
1522 // Create a surface:
1523 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 m_errorMonitor->SetDesiredFailureMsg(
1525 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526 "extension was not enabled for this");
1527 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1528 &surface);
1529 pass = (err != VK_SUCCESS);
1530 ASSERT_TRUE(pass);
1531 m_errorMonitor->VerifyFound();
1532
1533 // Tell whether an wayland_display supports presentation:
1534 struct wl_display wayland_display = {};
1535 m_errorMonitor->SetDesiredFailureMsg(
1536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "extension was not enabled for this");
1538 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1539 &wayland_display);
1540 m_errorMonitor->VerifyFound();
1541#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001542#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001543
1544
1545#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001546// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1547// TO NON-LINUX PLATFORMS:
1548VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 // Use the functions from the VK_KHR_win32_surface extension without
1550 // enabling that extension:
1551
1552 // Create a surface:
1553 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 m_errorMonitor->SetDesiredFailureMsg(
1555 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "extension was not enabled for this");
1557 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1558 &surface);
1559 pass = (err != VK_SUCCESS);
1560 ASSERT_TRUE(pass);
1561 m_errorMonitor->VerifyFound();
1562
1563 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001564 m_errorMonitor->SetDesiredFailureMsg(
1565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1566 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
1573
Ian Elliott1c32c772016-04-28 14:47:13 -06001574#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001575// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1576// TO NON-LINUX PLATFORMS:
1577VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1579 // that extension:
1580
1581 // Create a surface:
1582 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 m_errorMonitor->SetDesiredFailureMsg(
1584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1585 "extension was not enabled for this");
1586 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1587 pass = (err != VK_SUCCESS);
1588 ASSERT_TRUE(pass);
1589 m_errorMonitor->VerifyFound();
1590
1591 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 xcb_visualid_t visual_id = 0;
1594 m_errorMonitor->SetDesiredFailureMsg(
1595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1596 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001598 visual_id);
1599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
1610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001611 m_errorMonitor->SetDesiredFailureMsg(
1612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1613 "extension was not enabled for this");
1614 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1615 pass = (err != VK_SUCCESS);
1616 ASSERT_TRUE(pass);
1617 m_errorMonitor->VerifyFound();
1618
1619 // Tell whether an Xlib VisualID supports presentation:
1620 Display *dpy = NULL;
1621 VisualID visual = 0;
1622 m_errorMonitor->SetDesiredFailureMsg(
1623 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1624 "extension was not enabled for this");
1625 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1626 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001627// Set this (for now, until all platforms are supported and tested):
1628#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001629#endif // VK_USE_PLATFORM_XLIB_KHR
1630
1631
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 // Use the functions from the VK_KHR_surface extension without enabling
1633 // that extension:
1634
Ian Elliott489eec02016-05-05 14:12:44 -06001635#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001636 // Destroy a surface:
1637 m_errorMonitor->SetDesiredFailureMsg(
1638 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1639 "extension was not enabled for this");
1640 vkDestroySurfaceKHR(instance(), surface, NULL);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check if surface supports presentation:
1644 VkBool32 supported = false;
1645 m_errorMonitor->SetDesiredFailureMsg(
1646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1647 "extension was not enabled for this");
1648 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1649 pass = (err != VK_SUCCESS);
1650 ASSERT_TRUE(pass);
1651 m_errorMonitor->VerifyFound();
1652
1653 // Check surface capabilities:
1654 VkSurfaceCapabilitiesKHR capabilities = {};
1655 m_errorMonitor->SetDesiredFailureMsg(
1656 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1657 "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1659 &capabilities);
1660 pass = (err != VK_SUCCESS);
1661 ASSERT_TRUE(pass);
1662 m_errorMonitor->VerifyFound();
1663
1664 // Check surface formats:
1665 uint32_t format_count = 0;
1666 VkSurfaceFormatKHR *formats = NULL;
1667 m_errorMonitor->SetDesiredFailureMsg(
1668 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1669 "extension was not enabled for this");
1670 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1671 &format_count, formats);
1672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Check surface present modes:
1677 uint32_t present_mode_count = 0;
1678 VkSurfaceFormatKHR *present_modes = NULL;
1679 m_errorMonitor->SetDesiredFailureMsg(
1680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1681 "extension was not enabled for this");
1682 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1683 &present_mode_count, present_modes);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001687#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688
1689
1690 // Use the functions from the VK_KHR_swapchain extension without enabling
1691 // that extension:
1692
1693 // Create a swapchain:
1694 m_errorMonitor->SetDesiredFailureMsg(
1695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1696 "extension was not enabled for this");
1697 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1698 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001699 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1700 NULL, &swapchain);
1701 pass = (err != VK_SUCCESS);
1702 ASSERT_TRUE(pass);
1703 m_errorMonitor->VerifyFound();
1704
1705 // Get the images from the swapchain:
1706 m_errorMonitor->SetDesiredFailureMsg(
1707 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "extension was not enabled for this");
1709 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1710 &swapchain_image_count, NULL);
1711 pass = (err != VK_SUCCESS);
1712 ASSERT_TRUE(pass);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Try to acquire an image:
1716 m_errorMonitor->SetDesiredFailureMsg(
1717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1718 "extension was not enabled for this");
1719 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1720 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1721 pass = (err != VK_SUCCESS);
1722 ASSERT_TRUE(pass);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001726 //
1727 // NOTE: Currently can't test this because a real swapchain is needed (as
1728 // opposed to the fake one we created) in order for the layer to lookup the
1729 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001730
1731 // Destroy the swapchain:
1732 m_errorMonitor->SetDesiredFailureMsg(
1733 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1734 "extension was not enabled for this");
1735 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1736 m_errorMonitor->VerifyFound();
1737}
1738
Ian Elliott2c1daf52016-05-12 09:41:46 -06001739TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740
Dustin Graves6c6d8982016-05-17 10:09:21 -06001741#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001743
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744 VkResult err;
1745 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001746 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1747 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001748 // uint32_t swapchain_image_count = 0;
1749 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1750 // uint32_t image_index = 0;
1751 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001752
1753 ASSERT_NO_FATAL_FAILURE(InitState());
1754
1755 // Use the create function from one of the VK_KHR_*_surface extension in
1756 // order to create a surface, testing all known errors in the process,
1757 // before successfully creating a surface:
1758 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001761 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1762 pass = (err != VK_SUCCESS);
1763 ASSERT_TRUE(pass);
1764 m_errorMonitor->VerifyFound();
1765
1766 // Next, try to create a surface with the wrong
1767 // VkXcbSurfaceCreateInfoKHR::sType:
1768 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1769 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1771 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001772 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
Ian Elliott2c1daf52016-05-12 09:41:46 -06001777 // Create a native window, and then correctly create a surface:
1778 xcb_connection_t *connection;
1779 xcb_screen_t *screen;
1780 xcb_window_t xcb_window;
1781 xcb_intern_atom_reply_t *atom_wm_delete_window;
1782
1783 const xcb_setup_t *setup;
1784 xcb_screen_iterator_t iter;
1785 int scr;
1786 uint32_t value_mask, value_list[32];
1787 int width = 1;
1788 int height = 1;
1789
1790 connection = xcb_connect(NULL, &scr);
1791 ASSERT_TRUE(connection != NULL);
1792 setup = xcb_get_setup(connection);
1793 iter = xcb_setup_roots_iterator(setup);
1794 while (scr-- > 0)
1795 xcb_screen_next(&iter);
1796 screen = iter.data;
1797
1798 xcb_window = xcb_generate_id(connection);
1799
1800 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1801 value_list[0] = screen->black_pixel;
1802 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1803 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1804
1805 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1806 screen->root, 0, 0, width, height, 0,
1807 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1808 value_mask, value_list);
1809
1810 /* Magic code that will send notification when window is destroyed */
1811 xcb_intern_atom_cookie_t cookie =
1812 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1813 xcb_intern_atom_reply_t *reply =
1814 xcb_intern_atom_reply(connection, cookie, 0);
1815
1816 xcb_intern_atom_cookie_t cookie2 =
1817 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001818 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001819 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1820 (*reply).atom, 4, 32, 1,
1821 &(*atom_wm_delete_window).atom);
1822 free(reply);
1823
1824 xcb_map_window(connection, xcb_window);
1825
1826 // Force the x/y coordinates to 100,100 results are identical in consecutive
1827 // runs
1828 const uint32_t coords[] = {100, 100};
1829 xcb_configure_window(connection, xcb_window,
1830 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1831
Ian Elliott2c1daf52016-05-12 09:41:46 -06001832 // Finally, try to correctly create a surface:
1833 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1834 xcb_create_info.pNext = NULL;
1835 xcb_create_info.flags = 0;
1836 xcb_create_info.connection = connection;
1837 xcb_create_info.window = xcb_window;
1838 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1839 pass = (err == VK_SUCCESS);
1840 ASSERT_TRUE(pass);
1841
Ian Elliott2c1daf52016-05-12 09:41:46 -06001842 // Check if surface supports presentation:
1843
1844 // 1st, do so without having queried the queue families:
1845 VkBool32 supported = false;
1846 // TODO: Get the following error to come out:
1847 m_errorMonitor->SetDesiredFailureMsg(
1848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1849 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1850 "function");
1851 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1852 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 // ASSERT_TRUE(pass);
1854 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855
1856 // Next, query a queue family index that's too large:
1857 m_errorMonitor->SetDesiredFailureMsg(
1858 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1859 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001860 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1861 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 pass = (err != VK_SUCCESS);
1863 ASSERT_TRUE(pass);
1864 m_errorMonitor->VerifyFound();
1865
1866 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001867 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1868 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001869 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1870 pass = (err == VK_SUCCESS);
1871 ASSERT_TRUE(pass);
1872
Ian Elliott2c1daf52016-05-12 09:41:46 -06001873 // Before proceeding, try to create a swapchain without having called
1874 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1875 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1876 swapchain_create_info.pNext = NULL;
1877 swapchain_create_info.flags = 0;
1878 m_errorMonitor->SetDesiredFailureMsg(
1879 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1880 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001881 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1882 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001883 pass = (err != VK_SUCCESS);
1884 ASSERT_TRUE(pass);
1885 m_errorMonitor->VerifyFound();
1886
Ian Elliott2c1daf52016-05-12 09:41:46 -06001887 // Get the surface capabilities:
1888 VkSurfaceCapabilitiesKHR surface_capabilities;
1889
1890 // Do so correctly (only error logged by this entrypoint is if the
1891 // extension isn't enabled):
1892 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1893 &surface_capabilities);
1894 pass = (err == VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896
Ian Elliott2c1daf52016-05-12 09:41:46 -06001897 // Get the surface formats:
1898 uint32_t surface_format_count;
1899
1900 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1902 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001903 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1904 pass = (err == VK_SUCCESS);
1905 ASSERT_TRUE(pass);
1906 m_errorMonitor->VerifyFound();
1907
1908 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1909 // correctly done a 1st try (to get the count):
1910 m_errorMonitor->SetDesiredFailureMsg(
1911 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1912 "but no prior positive value has been seen for");
1913 surface_format_count = 0;
1914 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001915 gpu(), surface, &surface_format_count,
1916 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001917 pass = (err == VK_SUCCESS);
1918 ASSERT_TRUE(pass);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001922 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1923 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001924 pass = (err == VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926
1927 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001928 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1929 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001930
1931 // Next, do a 2nd try with surface_format_count being set too high:
1932 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1934 "that is greater than the value");
1935 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001936 surface_formats);
1937 pass = (err == VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001942 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1943 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001944 pass = (err == VK_SUCCESS);
1945 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001946 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001947 surface_formats);
1948 pass = (err == VK_SUCCESS);
1949 ASSERT_TRUE(pass);
1950
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951 // Get the surface present modes:
1952 uint32_t surface_present_mode_count;
1953
1954 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1956 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001957 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1958 pass = (err == VK_SUCCESS);
1959 ASSERT_TRUE(pass);
1960 m_errorMonitor->VerifyFound();
1961
1962 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1963 // correctly done a 1st try (to get the count):
1964 m_errorMonitor->SetDesiredFailureMsg(
1965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1966 "but no prior positive value has been seen for");
1967 surface_present_mode_count = 0;
1968 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001969 gpu(), surface, &surface_present_mode_count,
1970 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001971 pass = (err == VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
1975 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001976 vkGetPhysicalDeviceSurfacePresentModesKHR(
1977 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001978 pass = (err == VK_SUCCESS);
1979 ASSERT_TRUE(pass);
1980
1981 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001982 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1983 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001984
1985 // Next, do a 2nd try with surface_format_count being set too high:
1986 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1988 "that is greater than the value");
1989 vkGetPhysicalDeviceSurfacePresentModesKHR(
1990 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001991 pass = (err == VK_SUCCESS);
1992 ASSERT_TRUE(pass);
1993 m_errorMonitor->VerifyFound();
1994
1995 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001996 vkGetPhysicalDeviceSurfacePresentModesKHR(
1997 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 pass = (err == VK_SUCCESS);
1999 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002000 vkGetPhysicalDeviceSurfacePresentModesKHR(
2001 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002002 pass = (err == VK_SUCCESS);
2003 ASSERT_TRUE(pass);
2004
Ian Elliott2c1daf52016-05-12 09:41:46 -06002005 // Create a swapchain:
2006
2007 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2009 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2011 pass = (err != VK_SUCCESS);
2012 ASSERT_TRUE(pass);
2013 m_errorMonitor->VerifyFound();
2014
2015 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2016 // sType:
2017 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2019 "called with the wrong value for");
2020 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2021 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002022 pass = (err != VK_SUCCESS);
2023 ASSERT_TRUE(pass);
2024 m_errorMonitor->VerifyFound();
2025
2026 // Next, call with a NULL swapchain pointer:
2027 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2028 swapchain_create_info.pNext = NULL;
2029 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2031 "called with NULL pointer");
2032 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2033 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002034 pass = (err != VK_SUCCESS);
2035 ASSERT_TRUE(pass);
2036 m_errorMonitor->VerifyFound();
2037
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002038 // TODO: Enhance swapchain layer so that
2039 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002040
2041 // Next, call with a queue family index that's too large:
2042 uint32_t queueFamilyIndex[2] = {100000, 0};
2043 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2044 swapchain_create_info.queueFamilyIndexCount = 2;
2045 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2046 m_errorMonitor->SetDesiredFailureMsg(
2047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2048 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002049 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2050 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002051 pass = (err != VK_SUCCESS);
2052 ASSERT_TRUE(pass);
2053 m_errorMonitor->VerifyFound();
2054
2055 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2056 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2057 swapchain_create_info.queueFamilyIndexCount = 1;
2058 m_errorMonitor->SetDesiredFailureMsg(
2059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2060 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2061 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002062 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2063 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002064 pass = (err != VK_SUCCESS);
2065 ASSERT_TRUE(pass);
2066 m_errorMonitor->VerifyFound();
2067
2068 // Next, call with an invalid imageSharingMode:
2069 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2070 swapchain_create_info.queueFamilyIndexCount = 1;
2071 m_errorMonitor->SetDesiredFailureMsg(
2072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2073 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2075 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002076 pass = (err != VK_SUCCESS);
2077 ASSERT_TRUE(pass);
2078 m_errorMonitor->VerifyFound();
2079 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002080 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2081 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002082 swapchain_create_info.queueFamilyIndexCount = 0;
2083 queueFamilyIndex[0] = 0;
2084 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2085
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002086 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002087 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Destroy the swapchain:
2091
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002092 // TODOs:
2093 //
2094 // - Try destroying the device without first destroying the swapchain
2095 //
2096 // - Try destroying the device without first destroying the surface
2097 //
2098 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002099
2100 // Destroy the surface:
2101 vkDestroySurfaceKHR(instance(), surface, NULL);
2102
Ian Elliott2c1daf52016-05-12 09:41:46 -06002103 // Tear down the window:
2104 xcb_destroy_window(connection, xcb_window);
2105 xcb_disconnect(connection);
2106
2107#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002108 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002109#endif // VK_USE_PLATFORM_XCB_KHR
2110}
2111
Karl Schultz6addd812016-02-02 17:17:23 -07002112TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2113 VkResult err;
2114 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002115
Karl Schultz6addd812016-02-02 17:17:23 -07002116 m_errorMonitor->SetDesiredFailureMsg(
2117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002118 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2119
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121
2122 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002123 VkImage image;
2124 VkDeviceMemory mem;
2125 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002126
Karl Schultz6addd812016-02-02 17:17:23 -07002127 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2128 const int32_t tex_width = 32;
2129 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002130
Tony Barboureb254902015-07-15 12:50:33 -06002131 VkImageCreateInfo image_create_info = {};
2132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002133 image_create_info.pNext = NULL;
2134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2135 image_create_info.format = tex_format;
2136 image_create_info.extent.width = tex_width;
2137 image_create_info.extent.height = tex_height;
2138 image_create_info.extent.depth = 1;
2139 image_create_info.mipLevels = 1;
2140 image_create_info.arrayLayers = 1;
2141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2144 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002145
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002146 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002147 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002148 mem_alloc.pNext = NULL;
2149 mem_alloc.allocationSize = 0;
2150 // Introduce failure, do NOT set memProps to
2151 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2152 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002153
Chia-I Wuf7458c52015-10-26 21:10:41 +08002154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002155 ASSERT_VK_SUCCESS(err);
2156
Karl Schultz6addd812016-02-02 17:17:23 -07002157 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002158
Mark Lobodzinski23065352015-05-29 09:32:35 -05002159 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002160
Karl Schultz6addd812016-02-02 17:17:23 -07002161 pass =
2162 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2163 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2164 if (!pass) { // If we can't find any unmappable memory this test doesn't
2165 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002167 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002169
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002171 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002172 ASSERT_VK_SUCCESS(err);
2173
2174 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002175 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002176 ASSERT_VK_SUCCESS(err);
2177
2178 // Map memory as if to initialize the image
2179 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002180 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2181 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002183 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002184
Chia-I Wuf7458c52015-10-26 21:10:41 +08002185 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002186 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002187}
2188
Karl Schultz6addd812016-02-02 17:17:23 -07002189TEST_F(VkLayerTest, RebindMemory) {
2190 VkResult err;
2191 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002192
Karl Schultz6addd812016-02-02 17:17:23 -07002193 m_errorMonitor->SetDesiredFailureMsg(
2194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002195 "which has already been bound to mem object");
2196
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002197 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198
2199 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002200 VkImage image;
2201 VkDeviceMemory mem1;
2202 VkDeviceMemory mem2;
2203 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002204
Karl Schultz6addd812016-02-02 17:17:23 -07002205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2206 const int32_t tex_width = 32;
2207 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002208
Tony Barboureb254902015-07-15 12:50:33 -06002209 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2211 image_create_info.pNext = NULL;
2212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2213 image_create_info.format = tex_format;
2214 image_create_info.extent.width = tex_width;
2215 image_create_info.extent.height = tex_height;
2216 image_create_info.extent.depth = 1;
2217 image_create_info.mipLevels = 1;
2218 image_create_info.arrayLayers = 1;
2219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2222 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002223
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002224 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002225 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2226 mem_alloc.pNext = NULL;
2227 mem_alloc.allocationSize = 0;
2228 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002229
Karl Schultz6addd812016-02-02 17:17:23 -07002230 // Introduce failure, do NOT set memProps to
2231 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002232 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002234 ASSERT_VK_SUCCESS(err);
2235
Karl Schultz6addd812016-02-02 17:17:23 -07002236 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002237
2238 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002239 pass =
2240 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002241 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002242
2243 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002245 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002247 ASSERT_VK_SUCCESS(err);
2248
2249 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002250 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002251 ASSERT_VK_SUCCESS(err);
2252
Karl Schultz6addd812016-02-02 17:17:23 -07002253 // Introduce validation failure, try to bind a different memory object to
2254 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002255 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002258
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 vkDestroyImage(m_device->device(), image, NULL);
2260 vkFreeMemory(m_device->device(), mem1, NULL);
2261 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002262}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002263
Karl Schultz6addd812016-02-02 17:17:23 -07002264TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002265 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002266
Karl Schultz6addd812016-02-02 17:17:23 -07002267 m_errorMonitor->SetDesiredFailureMsg(
2268 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2269 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002270
2271 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002272 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2273 fenceInfo.pNext = NULL;
2274 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002275
Tony Barbour300a6082015-04-07 13:44:53 -06002276 ASSERT_NO_FATAL_FAILURE(InitState());
2277 ASSERT_NO_FATAL_FAILURE(InitViewport());
2278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2279
Tony Barbourfe3351b2015-07-28 10:17:20 -06002280 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2282 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002283 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002284
2285 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002286
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002287 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002288 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2289 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002290 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002291 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002292 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002293 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002295 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002296 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002297
2298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002299 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002301 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002302}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002303// This is a positive test. We used to expect error in this case but spec now
2304// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002305TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002306 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002307 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002308 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002309 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2310 fenceInfo.pNext = NULL;
2311
Tony Barbour0b4d9562015-04-09 10:48:04 -06002312 ASSERT_NO_FATAL_FAILURE(InitState());
2313 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002314 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002315 VkResult result = vkResetFences(m_device->device(), 1, fences);
2316 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002317
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002318 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002319}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002320
Chris Forbes18127d12016-06-08 16:52:28 +12002321TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2322{
2323 m_errorMonitor->ExpectSuccess();
2324
2325 ASSERT_NO_FATAL_FAILURE(InitState());
2326 VkResult err;
2327
2328 // Record (empty!) command buffer that can be submitted multiple times
2329 // simultaneously.
2330 VkCommandBufferBeginInfo cbbi = {
2331 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2332 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2333 };
2334 m_commandBuffer->BeginCommandBuffer(&cbbi);
2335 m_commandBuffer->EndCommandBuffer();
2336
2337 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2338 VkFence fence;
2339 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2343 VkSemaphore s1, s2;
2344 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2345 ASSERT_VK_SUCCESS(err);
2346 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2347 ASSERT_VK_SUCCESS(err);
2348
2349 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2350 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2351 1, &m_commandBuffer->handle(), 1, &s1 };
2352 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2353 ASSERT_VK_SUCCESS(err);
2354
2355 // Submit CB again, signaling s2.
2356 si.pSignalSemaphores = &s2;
2357 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2358 ASSERT_VK_SUCCESS(err);
2359
2360 // Wait for fence.
2361 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2362 ASSERT_VK_SUCCESS(err);
2363
2364 // CB is still in flight from second submission, but semaphore s1 is no
2365 // longer in flight. delete it.
2366 vkDestroySemaphore(m_device->device(), s1, nullptr);
2367
2368 m_errorMonitor->VerifyNotFound();
2369
2370 // Force device idle and clean up remaining objects
2371 vkDeviceWaitIdle(m_device->device());
2372 vkDestroySemaphore(m_device->device(), s2, nullptr);
2373 vkDestroyFence(m_device->device(), fence, nullptr);
2374}
2375
Tobin Ehlis41376e12015-07-03 08:45:14 -06002376TEST_F(VkLayerTest, InvalidUsageBits)
2377{
Tony Barbourf92621a2016-05-02 14:28:12 -06002378 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002379 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002380 "Initialize buffer with wrong usage then perform copy expecting errors "
2381 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002383 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002384
2385 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002386 VkImageObj image(m_device);
2387 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002388 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002389 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2390 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002391
Tony Barbourf92621a2016-05-02 14:28:12 -06002392 VkImageView dsv;
2393 VkImageViewCreateInfo dsvci = {};
2394 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2395 dsvci.image = image.handle();
2396 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2397 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2398 dsvci.subresourceRange.layerCount = 1;
2399 dsvci.subresourceRange.baseMipLevel = 0;
2400 dsvci.subresourceRange.levelCount = 1;
2401 dsvci.subresourceRange.aspectMask =
2402 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002403
Tony Barbourf92621a2016-05-02 14:28:12 -06002404 // Create a view with depth / stencil aspect for image with different usage
2405 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002408
2409 // Initialize buffer with TRANSFER_DST usage
2410 vk_testing::Buffer buffer;
2411 VkMemoryPropertyFlags reqs = 0;
2412 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2413 VkBufferImageCopy region = {};
2414 region.bufferRowLength = 128;
2415 region.bufferImageHeight = 128;
2416 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2417 region.imageSubresource.layerCount = 1;
2418 region.imageExtent.height = 16;
2419 region.imageExtent.width = 16;
2420 region.imageExtent.depth = 1;
2421
2422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2423 "Invalid usage flag for buffer ");
2424 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2425 // TRANSFER_DST
2426 BeginCommandBuffer();
2427 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2428 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2429 1, &region);
2430 m_errorMonitor->VerifyFound();
2431
2432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2433 "Invalid usage flag for image ");
2434 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2435 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2436 1, &region);
2437 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002438}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002439#endif // MEM_TRACKER_TESTS
2440
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002441#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002442
2443TEST_F(VkLayerTest, LeakAnObject) {
2444 VkResult err;
2445
2446 TEST_DESCRIPTION(
2447 "Create a fence and destroy its device without first destroying the fence.");
2448
2449 // Note that we have to create a new device since destroying the
2450 // framework's device causes Teardown() to fail and just calling Teardown
2451 // will destroy the errorMonitor.
2452
2453 m_errorMonitor->SetDesiredFailureMsg(
2454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2455 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2456
2457 ASSERT_NO_FATAL_FAILURE(InitState());
2458
2459 const std::vector<VkQueueFamilyProperties> queue_props =
2460 m_device->queue_props;
2461 std::vector<VkDeviceQueueCreateInfo> queue_info;
2462 queue_info.reserve(queue_props.size());
2463 std::vector<std::vector<float>> queue_priorities;
2464 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2465 VkDeviceQueueCreateInfo qi = {};
2466 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2467 qi.pNext = NULL;
2468 qi.queueFamilyIndex = i;
2469 qi.queueCount = queue_props[i].queueCount;
2470 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2471 qi.pQueuePriorities = queue_priorities[i].data();
2472 queue_info.push_back(qi);
2473 }
2474
2475 std::vector<const char *> device_layer_names;
2476 std::vector<const char *> device_extension_names;
2477 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2478 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2479 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2480 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2481 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2482 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2483 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2484
2485 // The sacrificial device object
2486 VkDevice testDevice;
2487 VkDeviceCreateInfo device_create_info = {};
2488 auto features = m_device->phy().features();
2489 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2490 device_create_info.pNext = NULL;
2491 device_create_info.queueCreateInfoCount = queue_info.size();
2492 device_create_info.pQueueCreateInfos = queue_info.data();
2493 device_create_info.enabledLayerCount = device_layer_names.size();
2494 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2495 device_create_info.pEnabledFeatures = &features;
2496 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2497 ASSERT_VK_SUCCESS(err);
2498
2499 VkFence fence;
2500 VkFenceCreateInfo fence_create_info = {};
2501 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2502 fence_create_info.pNext = NULL;
2503 fence_create_info.flags = 0;
2504 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 // Induce failure by not calling vkDestroyFence
2508 vkDestroyDevice(testDevice, NULL);
2509 m_errorMonitor->VerifyFound();
2510}
2511
2512TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2513
2514 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2515 "attempt to delete them from another.");
2516
2517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2518 "FreeCommandBuffers is attempting to free Command Buffer");
2519
2520 VkCommandPool command_pool_one;
2521 VkCommandPool command_pool_two;
2522
2523 VkCommandPoolCreateInfo pool_create_info{};
2524 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2525 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2526 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2527
2528 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2529 &command_pool_one);
2530
2531 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2532 &command_pool_two);
2533
2534 VkCommandBuffer command_buffer[9];
2535 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2536 command_buffer_allocate_info.sType =
2537 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2538 command_buffer_allocate_info.commandPool = command_pool_one;
2539 command_buffer_allocate_info.commandBufferCount = 9;
2540 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2541 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2542 command_buffer);
2543
2544 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2545 &command_buffer[3]);
2546
2547 m_errorMonitor->VerifyFound();
2548
2549 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2550 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2551}
2552
2553TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2554 VkResult err;
2555
2556 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2557 "attempt to delete them from another.");
2558
2559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2560 "FreeDescriptorSets is attempting to free descriptorSet");
2561
2562 ASSERT_NO_FATAL_FAILURE(InitState());
2563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2564
2565 VkDescriptorPoolSize ds_type_count = {};
2566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2567 ds_type_count.descriptorCount = 1;
2568
2569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2571 ds_pool_ci.pNext = NULL;
2572 ds_pool_ci.flags = 0;
2573 ds_pool_ci.maxSets = 1;
2574 ds_pool_ci.poolSizeCount = 1;
2575 ds_pool_ci.pPoolSizes = &ds_type_count;
2576
2577 VkDescriptorPool ds_pool_one;
2578 err =
2579 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2580 ASSERT_VK_SUCCESS(err);
2581
2582 // Create a second descriptor pool
2583 VkDescriptorPool ds_pool_two;
2584 err =
2585 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2586 ASSERT_VK_SUCCESS(err);
2587
2588 VkDescriptorSetLayoutBinding dsl_binding = {};
2589 dsl_binding.binding = 0;
2590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2591 dsl_binding.descriptorCount = 1;
2592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2593 dsl_binding.pImmutableSamplers = NULL;
2594
2595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2597 ds_layout_ci.pNext = NULL;
2598 ds_layout_ci.bindingCount = 1;
2599 ds_layout_ci.pBindings = &dsl_binding;
2600
2601 VkDescriptorSetLayout ds_layout;
2602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2603 &ds_layout);
2604 ASSERT_VK_SUCCESS(err);
2605
2606 VkDescriptorSet descriptorSet;
2607 VkDescriptorSetAllocateInfo alloc_info = {};
2608 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2609 alloc_info.descriptorSetCount = 1;
2610 alloc_info.descriptorPool = ds_pool_one;
2611 alloc_info.pSetLayouts = &ds_layout;
2612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2613 &descriptorSet);
2614 ASSERT_VK_SUCCESS(err);
2615
2616 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2617
2618 m_errorMonitor->VerifyFound();
2619
2620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2621 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2622 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2623}
2624
2625TEST_F(VkLayerTest, CreateUnknownObject) {
2626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2627 "Invalid VkImage Object ");
2628
2629 TEST_DESCRIPTION(
2630 "Pass an invalid image object handle into a Vulkan API call.");
2631
2632 ASSERT_NO_FATAL_FAILURE(InitState());
2633
2634 // Pass bogus handle into GetImageMemoryRequirements
2635 VkMemoryRequirements mem_reqs;
2636 uint64_t fakeImageHandle = 0xCADECADE;
2637 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2638
2639 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2640
2641 m_errorMonitor->VerifyFound();
2642}
2643
Karl Schultz6addd812016-02-02 17:17:23 -07002644TEST_F(VkLayerTest, PipelineNotBound) {
2645 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002646
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002647 TEST_DESCRIPTION(
2648 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2649
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002651 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002655
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2658 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002659
2660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2662 ds_pool_ci.pNext = NULL;
2663 ds_pool_ci.maxSets = 1;
2664 ds_pool_ci.poolSizeCount = 1;
2665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002666
2667 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002668 err =
2669 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002670 ASSERT_VK_SUCCESS(err);
2671
2672 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002673 dsl_binding.binding = 0;
2674 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2675 dsl_binding.descriptorCount = 1;
2676 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2677 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002678
2679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2681 ds_layout_ci.pNext = NULL;
2682 ds_layout_ci.bindingCount = 1;
2683 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002684
2685 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2687 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002688 ASSERT_VK_SUCCESS(err);
2689
2690 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002691 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002693 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002694 alloc_info.descriptorPool = ds_pool;
2695 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002696 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2697 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002701 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2702 pipeline_layout_ci.pNext = NULL;
2703 pipeline_layout_ci.setLayoutCount = 1;
2704 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002705
2706 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2708 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002709 ASSERT_VK_SUCCESS(err);
2710
Mark Youngad779052016-01-06 14:26:04 -07002711 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712
2713 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2715 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002717 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002718
Chia-I Wuf7458c52015-10-26 21:10:41 +08002719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002722}
2723
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002724TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2725 VkResult err;
2726
2727 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2728 "during bind[Buffer|Image]Memory time");
2729
2730 m_errorMonitor->SetDesiredFailureMsg(
2731 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2732 "for this object type are not compatible with the memory");
2733
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // Create an image, allocate memory, set a bad typeIndex and then try to
2737 // bind it
2738 VkImage image;
2739 VkDeviceMemory mem;
2740 VkMemoryRequirements mem_reqs;
2741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
2744
2745 VkImageCreateInfo image_create_info = {};
2746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
2759
2760 VkMemoryAllocateInfo mem_alloc = {};
2761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
2765
2766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2767 ASSERT_VK_SUCCESS(err);
2768
2769 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2770 mem_alloc.allocationSize = mem_reqs.size;
2771 // Introduce Failure, select likely invalid TypeIndex
2772 mem_alloc.memoryTypeIndex = 31;
2773
2774 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2775 ASSERT_VK_SUCCESS(err);
2776
2777 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2778 (void)err;
2779
2780 m_errorMonitor->VerifyFound();
2781
2782 vkDestroyImage(m_device->device(), image, NULL);
2783 vkFreeMemory(m_device->device(), mem, NULL);
2784}
2785
Karl Schultz6addd812016-02-02 17:17:23 -07002786TEST_F(VkLayerTest, BindInvalidMemory) {
2787 VkResult err;
2788 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002789
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002791 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002792
Tobin Ehlisec598302015-09-15 15:02:17 -06002793 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002794
2795 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002796 VkImage image;
2797 VkDeviceMemory mem;
2798 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002799
Karl Schultz6addd812016-02-02 17:17:23 -07002800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2801 const int32_t tex_width = 32;
2802 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002803
2804 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2806 image_create_info.pNext = NULL;
2807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2808 image_create_info.format = tex_format;
2809 image_create_info.extent.width = tex_width;
2810 image_create_info.extent.height = tex_height;
2811 image_create_info.extent.depth = 1;
2812 image_create_info.mipLevels = 1;
2813 image_create_info.arrayLayers = 1;
2814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2815 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2816 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2817 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002818
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002819 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002820 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2821 mem_alloc.pNext = NULL;
2822 mem_alloc.allocationSize = 0;
2823 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002824
Chia-I Wuf7458c52015-10-26 21:10:41 +08002825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002826 ASSERT_VK_SUCCESS(err);
2827
Karl Schultz6addd812016-02-02 17:17:23 -07002828 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002829
2830 mem_alloc.allocationSize = mem_reqs.size;
2831
Karl Schultz6addd812016-02-02 17:17:23 -07002832 pass =
2833 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002834 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002835
2836 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002837 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002838 ASSERT_VK_SUCCESS(err);
2839
2840 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002841 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002842
2843 // Try to bind free memory that has been freed
2844 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2845 // This may very well return an error.
2846 (void)err;
2847
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002848 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002849
Chia-I Wuf7458c52015-10-26 21:10:41 +08002850 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002851}
2852
Karl Schultz6addd812016-02-02 17:17:23 -07002853TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2854 VkResult err;
2855 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002856
Karl Schultz6addd812016-02-02 17:17:23 -07002857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2858 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002859
Tobin Ehlisec598302015-09-15 15:02:17 -06002860 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002861
Karl Schultz6addd812016-02-02 17:17:23 -07002862 // Create an image object, allocate memory, destroy the object and then try
2863 // to bind it
2864 VkImage image;
2865 VkDeviceMemory mem;
2866 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002867
Karl Schultz6addd812016-02-02 17:17:23 -07002868 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2869 const int32_t tex_width = 32;
2870 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002871
2872 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002873 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2874 image_create_info.pNext = NULL;
2875 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2876 image_create_info.format = tex_format;
2877 image_create_info.extent.width = tex_width;
2878 image_create_info.extent.height = tex_height;
2879 image_create_info.extent.depth = 1;
2880 image_create_info.mipLevels = 1;
2881 image_create_info.arrayLayers = 1;
2882 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2883 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2884 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2885 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002886
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002887 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002888 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2889 mem_alloc.pNext = NULL;
2890 mem_alloc.allocationSize = 0;
2891 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002892
Chia-I Wuf7458c52015-10-26 21:10:41 +08002893 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002894 ASSERT_VK_SUCCESS(err);
2895
Karl Schultz6addd812016-02-02 17:17:23 -07002896 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002897
2898 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002899 pass =
2900 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002901 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002902
2903 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002904 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002905 ASSERT_VK_SUCCESS(err);
2906
2907 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002908 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002909 ASSERT_VK_SUCCESS(err);
2910
2911 // Now Try to bind memory to this destroyed object
2912 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2913 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002914 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002915
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002916 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002917
Chia-I Wuf7458c52015-10-26 21:10:41 +08002918 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002919}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002920
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002921#endif // OBJ_TRACKER_TESTS
2922
Tobin Ehlis0788f522015-05-26 16:11:58 -06002923#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002924
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002925// This is a positive test. No errors are expected.
2926TEST_F(VkLayerTest, StencilLoadOp) {
2927 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2928 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2929 VkResult result = VK_SUCCESS;
2930 VkImageFormatProperties formatProps;
2931 vkGetPhysicalDeviceImageFormatProperties(
2932 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2933 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2934 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2935 0, &formatProps);
2936 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2937 return;
2938 }
2939
2940 ASSERT_NO_FATAL_FAILURE(InitState());
2941 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2942 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2943 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2944 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2945 VkAttachmentDescription att = {};
2946 VkAttachmentReference ref = {};
2947 att.format = depth_stencil_fmt;
2948 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2949 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2950 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2951 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2952 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2953 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2954
2955 VkClearValue clear;
2956 clear.depthStencil.depth = 1.0;
2957 clear.depthStencil.stencil = 0;
2958 ref.attachment = 0;
2959 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2960
2961 VkSubpassDescription subpass = {};
2962 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
2963 subpass.flags = 0;
2964 subpass.inputAttachmentCount = 0;
2965 subpass.pInputAttachments = NULL;
2966 subpass.colorAttachmentCount = 0;
2967 subpass.pColorAttachments = NULL;
2968 subpass.pResolveAttachments = NULL;
2969 subpass.pDepthStencilAttachment = &ref;
2970 subpass.preserveAttachmentCount = 0;
2971 subpass.pPreserveAttachments = NULL;
2972
2973 VkRenderPass rp;
2974 VkRenderPassCreateInfo rp_info = {};
2975 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2976 rp_info.attachmentCount = 1;
2977 rp_info.pAttachments = &att;
2978 rp_info.subpassCount = 1;
2979 rp_info.pSubpasses = &subpass;
2980 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
2981 ASSERT_VK_SUCCESS(result);
2982
2983 VkImageView *depthView = m_depthStencil->BindInfo();
2984 VkFramebufferCreateInfo fb_info = {};
2985 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
2986 fb_info.pNext = NULL;
2987 fb_info.renderPass = rp;
2988 fb_info.attachmentCount = 1;
2989 fb_info.pAttachments = depthView;
2990 fb_info.width = 100;
2991 fb_info.height = 100;
2992 fb_info.layers = 1;
2993 VkFramebuffer fb;
2994 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
2995 ASSERT_VK_SUCCESS(result);
2996
2997
2998 VkRenderPassBeginInfo rpbinfo = {};
2999 rpbinfo.clearValueCount = 1;
3000 rpbinfo.pClearValues = &clear;
3001 rpbinfo.pNext = NULL;
3002 rpbinfo.renderPass = rp;
3003 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3004 rpbinfo.renderArea.extent.width = 100;
3005 rpbinfo.renderArea.extent.height = 100;
3006 rpbinfo.renderArea.offset.x = 0;
3007 rpbinfo.renderArea.offset.y = 0;
3008 rpbinfo.framebuffer = fb;
3009
3010 VkFence fence = {};
3011 VkFenceCreateInfo fence_ci = {};
3012 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3013 fence_ci.pNext = nullptr;
3014 fence_ci.flags = 0;
3015 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3016 ASSERT_VK_SUCCESS(result);
3017
3018
3019 m_commandBuffer->BeginCommandBuffer();
3020 m_commandBuffer->BeginRenderPass(rpbinfo);
3021 m_commandBuffer->EndRenderPass();
3022 m_commandBuffer->EndCommandBuffer();
3023 m_commandBuffer->QueueCommandBuffer(fence);
3024
3025 VkImageObj destImage(m_device);
3026 destImage.init(100, 100, depth_stencil_fmt,
3027 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3028 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3029 VK_IMAGE_TILING_OPTIMAL, 0);
3030 VkImageMemoryBarrier barrier = {};
3031 VkImageSubresourceRange range;
3032 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3033 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3034 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3035 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3036 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3037 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3038 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3039 barrier.image = m_depthStencil->handle();
3040 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3041 range.baseMipLevel = 0;
3042 range.levelCount = 1;
3043 range.baseArrayLayer = 0;
3044 range.layerCount = 1;
3045 barrier.subresourceRange = range;
3046 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3047 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3048 cmdbuf.BeginCommandBuffer();
3049 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3050 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3051 nullptr, 1, &barrier);
3052 barrier.srcAccessMask = 0;
3053 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3054 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3055 barrier.image = destImage.handle();
3056 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3057 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3058 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3059 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3060 nullptr, 1, &barrier);
3061 VkImageCopy cregion;
3062 cregion.srcSubresource.aspectMask =
3063 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3064 cregion.srcSubresource.mipLevel = 0;
3065 cregion.srcSubresource.baseArrayLayer = 0;
3066 cregion.srcSubresource.layerCount = 1;
3067 cregion.srcOffset.x = 0;
3068 cregion.srcOffset.y = 0;
3069 cregion.srcOffset.z = 0;
3070 cregion.dstSubresource.aspectMask =
3071 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3072 cregion.dstSubresource.mipLevel = 0;
3073 cregion.dstSubresource.baseArrayLayer = 0;
3074 cregion.dstSubresource.layerCount = 1;
3075 cregion.dstOffset.x = 0;
3076 cregion.dstOffset.y = 0;
3077 cregion.dstOffset.z = 0;
3078 cregion.extent.width = 100;
3079 cregion.extent.height = 100;
3080 cregion.extent.depth = 1;
3081 cmdbuf.CopyImage(m_depthStencil->handle(),
3082 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3083 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3084 cmdbuf.EndCommandBuffer();
3085
3086 VkSubmitInfo submit_info;
3087 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3088 submit_info.pNext = NULL;
3089 submit_info.waitSemaphoreCount = 0;
3090 submit_info.pWaitSemaphores = NULL;
3091 submit_info.pWaitDstStageMask = NULL;
3092 submit_info.commandBufferCount = 1;
3093 submit_info.pCommandBuffers = &cmdbuf.handle();
3094 submit_info.signalSemaphoreCount = 0;
3095 submit_info.pSignalSemaphores = NULL;
3096
3097 m_errorMonitor->ExpectSuccess();
3098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3099 m_errorMonitor->VerifyNotFound();
3100
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003101 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003102 vkDestroyFence(m_device->device(), fence, nullptr);
3103 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3104 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3105}
3106
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003107TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3108 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3109 "attachment reference of VK_ATTACHMENT_UNUSED");
3110
3111 ASSERT_NO_FATAL_FAILURE(InitState());
3112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3113
3114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3115 "must not be VK_ATTACHMENT_UNUSED");
3116
3117 VkAttachmentReference color_attach = {};
3118 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3119 color_attach.attachment = 0;
3120 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3121 VkSubpassDescription subpass = {};
3122 subpass.colorAttachmentCount = 1;
3123 subpass.pColorAttachments = &color_attach;
3124 subpass.preserveAttachmentCount = 1;
3125 subpass.pPreserveAttachments = &preserve_attachment;
3126
3127 VkRenderPassCreateInfo rpci = {};
3128 rpci.subpassCount = 1;
3129 rpci.pSubpasses = &subpass;
3130 rpci.attachmentCount = 1;
3131 VkAttachmentDescription attach_desc = {};
3132 attach_desc.format = VK_FORMAT_UNDEFINED;
3133 rpci.pAttachments = &attach_desc;
3134 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3135 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003137
3138 m_errorMonitor->VerifyFound();
3139
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003140 if (result == VK_SUCCESS) {
3141 vkDestroyRenderPass(m_device->device(), rp, NULL);
3142 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003143}
3144
3145TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3146 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3147 "in the depthStencil attachment point");
3148
3149 ASSERT_NO_FATAL_FAILURE(InitState());
3150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3151
3152 m_errorMonitor->SetDesiredFailureMsg(
3153 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3154 "conflicts with the image's IMAGE_USAGE flags");
3155
3156 // Create a renderPass with a depth-stencil attachment created with
3157 // IMAGE_USAGE_COLOR_ATTACHMENT
3158 VkAttachmentReference attach = {};
3159 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3160 VkSubpassDescription subpass = {};
3161 // Add our color attachment to pDepthStencilAttachment
3162 subpass.pDepthStencilAttachment = &attach;
3163 VkRenderPassCreateInfo rpci = {};
3164 rpci.subpassCount = 1;
3165 rpci.pSubpasses = &subpass;
3166 rpci.attachmentCount = 1;
3167 VkAttachmentDescription attach_desc = {};
3168 attach_desc.format = VK_FORMAT_UNDEFINED;
3169 rpci.pAttachments = &attach_desc;
3170 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3171 VkRenderPass rp;
3172 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3173 ASSERT_VK_SUCCESS(err);
3174
3175 VkImageView imageView =
3176 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3177 VkFramebufferCreateInfo fb_info = {};
3178 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3179 fb_info.pNext = NULL;
3180 fb_info.renderPass = rp;
3181 fb_info.attachmentCount = 1;
3182 fb_info.pAttachments = &imageView;
3183 fb_info.width = 100;
3184 fb_info.height = 100;
3185 fb_info.layers = 1;
3186
3187 VkFramebuffer fb;
3188 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3189
3190 m_errorMonitor->VerifyFound();
3191
3192 if (err == VK_SUCCESS) {
3193 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3194 }
3195 vkDestroyRenderPass(m_device->device(), rp, NULL);
3196}
3197
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003198// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003199TEST_F(VkLayerTest, WaitEventThenSet) {
3200 TEST_DESCRIPTION(
3201 "Wait on a event then set it after the wait has been submitted.");
3202
Michael Lentine860b0fe2016-05-20 10:14:00 -05003203 m_errorMonitor->ExpectSuccess();
3204
3205 VkEvent event;
3206 VkEventCreateInfo event_create_info{};
3207 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3208 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3209
3210 VkCommandPool command_pool;
3211 VkCommandPoolCreateInfo pool_create_info{};
3212 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3213 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3214 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3215 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3216 &command_pool);
3217
3218 VkCommandBuffer command_buffer;
3219 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3220 command_buffer_allocate_info.sType =
3221 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3222 command_buffer_allocate_info.commandPool = command_pool;
3223 command_buffer_allocate_info.commandBufferCount = 1;
3224 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3225 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3226 &command_buffer);
3227
3228 VkQueue queue = VK_NULL_HANDLE;
3229 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003230 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003231
3232 {
3233 VkCommandBufferBeginInfo begin_info{};
3234 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3235 vkBeginCommandBuffer(command_buffer, &begin_info);
3236
3237 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3238 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3239 nullptr, 0, nullptr);
3240 vkCmdResetEvent(command_buffer, event,
3241 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3242 vkEndCommandBuffer(command_buffer);
3243 }
3244 {
3245 VkSubmitInfo submit_info{};
3246 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3247 submit_info.commandBufferCount = 1;
3248 submit_info.pCommandBuffers = &command_buffer;
3249 submit_info.signalSemaphoreCount = 0;
3250 submit_info.pSignalSemaphores = nullptr;
3251 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3252 }
3253 { vkSetEvent(m_device->device(), event); }
3254
3255 vkQueueWaitIdle(queue);
3256
3257 vkDestroyEvent(m_device->device(), event, nullptr);
3258 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3259 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3260
3261 m_errorMonitor->VerifyNotFound();
3262}
Michael Lentine5627e692016-05-20 17:45:02 -05003263// This is a positive test. No errors should be generated.
3264TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3265 TEST_DESCRIPTION(
3266 "Issue a query and copy from it on a second command buffer.");
3267
3268 if ((m_device->queue_props.empty()) ||
3269 (m_device->queue_props[0].queueCount < 2))
3270 return;
3271
3272 m_errorMonitor->ExpectSuccess();
3273
3274 VkQueryPool query_pool;
3275 VkQueryPoolCreateInfo query_pool_create_info{};
3276 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3277 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3278 query_pool_create_info.queryCount = 1;
3279 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3280 &query_pool);
3281
3282 VkCommandPool command_pool;
3283 VkCommandPoolCreateInfo pool_create_info{};
3284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3288 &command_pool);
3289
3290 VkCommandBuffer command_buffer[2];
3291 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3292 command_buffer_allocate_info.sType =
3293 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3294 command_buffer_allocate_info.commandPool = command_pool;
3295 command_buffer_allocate_info.commandBufferCount = 2;
3296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3298 command_buffer);
3299
3300 VkQueue queue = VK_NULL_HANDLE;
3301 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3302 1, &queue);
3303
3304 uint32_t qfi = 0;
3305 VkBufferCreateInfo buff_create_info = {};
3306 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3307 buff_create_info.size = 1024;
3308 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3309 buff_create_info.queueFamilyIndexCount = 1;
3310 buff_create_info.pQueueFamilyIndices = &qfi;
3311
3312 VkResult err;
3313 VkBuffer buffer;
3314 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3315 ASSERT_VK_SUCCESS(err);
3316 VkMemoryAllocateInfo mem_alloc = {};
3317 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3318 mem_alloc.pNext = NULL;
3319 mem_alloc.allocationSize = 1024;
3320 mem_alloc.memoryTypeIndex = 0;
3321
3322 VkMemoryRequirements memReqs;
3323 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3324 bool pass =
3325 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3326 if (!pass) {
3327 vkDestroyBuffer(m_device->device(), buffer, NULL);
3328 return;
3329 }
3330
3331 VkDeviceMemory mem;
3332 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3333 ASSERT_VK_SUCCESS(err);
3334 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3335 ASSERT_VK_SUCCESS(err);
3336
3337 {
3338 VkCommandBufferBeginInfo begin_info{};
3339 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3340 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3341
3342 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3343 vkCmdWriteTimestamp(command_buffer[0],
3344 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3345
3346 vkEndCommandBuffer(command_buffer[0]);
3347
3348 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3349
3350 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3351 0, 0, 0);
3352
3353 vkEndCommandBuffer(command_buffer[1]);
3354 }
3355 {
3356 VkSubmitInfo submit_info{};
3357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3358 submit_info.commandBufferCount = 2;
3359 submit_info.pCommandBuffers = command_buffer;
3360 submit_info.signalSemaphoreCount = 0;
3361 submit_info.pSignalSemaphores = nullptr;
3362 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3363 }
3364
3365 vkQueueWaitIdle(queue);
3366
3367 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3368 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3369 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003370 vkDestroyBuffer(m_device->device(), buffer, NULL);
3371 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003372
3373 m_errorMonitor->VerifyNotFound();
3374}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003375
3376TEST_F(VkLayerTest, ResetEventThenSet) {
3377 TEST_DESCRIPTION(
3378 "Reset an event then set it after the reset has been submitted.");
3379
Michael Lentine860b0fe2016-05-20 10:14:00 -05003380 m_errorMonitor->ExpectSuccess();
3381
3382 VkEvent event;
3383 VkEventCreateInfo event_create_info{};
3384 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3385 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3386
3387 VkCommandPool command_pool;
3388 VkCommandPoolCreateInfo pool_create_info{};
3389 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3390 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3391 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3392 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3393 &command_pool);
3394
3395 VkCommandBuffer command_buffer;
3396 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3397 command_buffer_allocate_info.sType =
3398 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3399 command_buffer_allocate_info.commandPool = command_pool;
3400 command_buffer_allocate_info.commandBufferCount = 1;
3401 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3402 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3403 &command_buffer);
3404
3405 VkQueue queue = VK_NULL_HANDLE;
3406 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003407 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003408
3409 {
3410 VkCommandBufferBeginInfo begin_info{};
3411 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3412 vkBeginCommandBuffer(command_buffer, &begin_info);
3413
3414 vkCmdResetEvent(command_buffer, event,
3415 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3416 vkCmdWaitEvents(command_buffer, 1, &event,
3417 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3418 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3419 nullptr, 0, nullptr);
3420 vkEndCommandBuffer(command_buffer);
3421 }
3422 {
3423 VkSubmitInfo submit_info{};
3424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3425 submit_info.commandBufferCount = 1;
3426 submit_info.pCommandBuffers = &command_buffer;
3427 submit_info.signalSemaphoreCount = 0;
3428 submit_info.pSignalSemaphores = nullptr;
3429 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3430 }
3431 {
3432 m_errorMonitor->SetDesiredFailureMsg(
3433 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3434 "0x1 that is already in use by a "
3435 "command buffer.");
3436 vkSetEvent(m_device->device(), event);
3437 m_errorMonitor->VerifyFound();
3438 }
3439
3440 vkQueueWaitIdle(queue);
3441
3442 vkDestroyEvent(m_device->device(), event, nullptr);
3443 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3444 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3445}
3446
3447// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003448TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3449 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3450 "run through a Submit & WaitForFences cycle 3 times. This "
3451 "previously revealed a bug so running this positive test "
3452 "to prevent a regression.");
3453 m_errorMonitor->ExpectSuccess();
3454
3455 ASSERT_NO_FATAL_FAILURE(InitState());
3456 VkQueue queue = VK_NULL_HANDLE;
3457 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3458 0, &queue);
3459
3460 static const uint32_t NUM_OBJECTS = 2;
3461 static const uint32_t NUM_FRAMES = 3;
3462 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3463 VkFence fences[NUM_OBJECTS] = {};
3464
3465 VkCommandPool cmd_pool;
3466 VkCommandPoolCreateInfo cmd_pool_ci = {};
3467 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3468 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3469 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3470 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3471 nullptr, &cmd_pool);
3472 ASSERT_VK_SUCCESS(err);
3473
3474 VkCommandBufferAllocateInfo cmd_buf_info = {};
3475 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3476 cmd_buf_info.commandPool = cmd_pool;
3477 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3478 cmd_buf_info.commandBufferCount = 1;
3479
3480 VkFenceCreateInfo fence_ci = {};
3481 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3482 fence_ci.pNext = nullptr;
3483 fence_ci.flags = 0;
3484
3485 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3486 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3487 &cmd_buffers[i]);
3488 ASSERT_VK_SUCCESS(err);
3489 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3490 ASSERT_VK_SUCCESS(err);
3491 }
3492
3493 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003494 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3495 // Create empty cmd buffer
3496 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3497 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003498
Tobin Ehlisf9025162016-05-26 06:55:21 -06003499 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3500 ASSERT_VK_SUCCESS(err);
3501 err = vkEndCommandBuffer(cmd_buffers[obj]);
3502 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003503
Tobin Ehlisf9025162016-05-26 06:55:21 -06003504 VkSubmitInfo submit_info = {};
3505 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3506 submit_info.commandBufferCount = 1;
3507 submit_info.pCommandBuffers = &cmd_buffers[obj];
3508 // Submit cmd buffer and wait for fence
3509 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3510 ASSERT_VK_SUCCESS(err);
3511 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3512 UINT64_MAX);
3513 ASSERT_VK_SUCCESS(err);
3514 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3515 ASSERT_VK_SUCCESS(err);
3516 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003517 }
3518 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003519 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3520 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3521 vkDestroyFence(m_device->device(), fences[i], nullptr);
3522 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003523}
3524// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003525TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3526
3527 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3528 "submitted on separate queues followed by a QueueWaitIdle.");
3529
Dustin Graves48458142016-04-29 16:11:55 -06003530 if ((m_device->queue_props.empty()) ||
3531 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003532 return;
3533
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003534 m_errorMonitor->ExpectSuccess();
3535
3536 VkSemaphore semaphore;
3537 VkSemaphoreCreateInfo semaphore_create_info{};
3538 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3539 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3540 &semaphore);
3541
3542 VkCommandPool command_pool;
3543 VkCommandPoolCreateInfo pool_create_info{};
3544 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3545 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3546 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3547 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3548 &command_pool);
3549
3550 VkCommandBuffer command_buffer[2];
3551 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3552 command_buffer_allocate_info.sType =
3553 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3554 command_buffer_allocate_info.commandPool = command_pool;
3555 command_buffer_allocate_info.commandBufferCount = 2;
3556 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3557 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3558 command_buffer);
3559
3560 VkQueue queue = VK_NULL_HANDLE;
3561 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3562 1, &queue);
3563
3564 {
3565 VkCommandBufferBeginInfo begin_info{};
3566 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3567 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3568
3569 vkCmdPipelineBarrier(command_buffer[0],
3570 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3571 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3572 0, nullptr, 0, nullptr);
3573
3574 VkViewport viewport{};
3575 viewport.maxDepth = 1.0f;
3576 viewport.minDepth = 0.0f;
3577 viewport.width = 512;
3578 viewport.height = 512;
3579 viewport.x = 0;
3580 viewport.y = 0;
3581 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3582 vkEndCommandBuffer(command_buffer[0]);
3583 }
3584 {
3585 VkCommandBufferBeginInfo begin_info{};
3586 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3587 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3588
3589 VkViewport viewport{};
3590 viewport.maxDepth = 1.0f;
3591 viewport.minDepth = 0.0f;
3592 viewport.width = 512;
3593 viewport.height = 512;
3594 viewport.x = 0;
3595 viewport.y = 0;
3596 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3597 vkEndCommandBuffer(command_buffer[1]);
3598 }
3599 {
3600 VkSubmitInfo submit_info{};
3601 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3602 submit_info.commandBufferCount = 1;
3603 submit_info.pCommandBuffers = &command_buffer[0];
3604 submit_info.signalSemaphoreCount = 1;
3605 submit_info.pSignalSemaphores = &semaphore;
3606 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3607 }
3608 {
3609 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3610 VkSubmitInfo submit_info{};
3611 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3612 submit_info.commandBufferCount = 1;
3613 submit_info.pCommandBuffers = &command_buffer[1];
3614 submit_info.waitSemaphoreCount = 1;
3615 submit_info.pWaitSemaphores = &semaphore;
3616 submit_info.pWaitDstStageMask = flags;
3617 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3618 }
3619
3620 vkQueueWaitIdle(m_device->m_queue);
3621
3622 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3623 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3624 &command_buffer[0]);
3625 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3626
3627 m_errorMonitor->VerifyNotFound();
3628}
3629
3630// This is a positive test. No errors should be generated.
3631TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3632
3633 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3634 "submitted on separate queues, the second having a fence"
3635 "followed by a QueueWaitIdle.");
3636
Dustin Graves48458142016-04-29 16:11:55 -06003637 if ((m_device->queue_props.empty()) ||
3638 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003639 return;
3640
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003641 m_errorMonitor->ExpectSuccess();
3642
3643 VkFence fence;
3644 VkFenceCreateInfo fence_create_info{};
3645 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3646 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3647
3648 VkSemaphore semaphore;
3649 VkSemaphoreCreateInfo semaphore_create_info{};
3650 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3651 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3652 &semaphore);
3653
3654 VkCommandPool command_pool;
3655 VkCommandPoolCreateInfo pool_create_info{};
3656 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3657 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3658 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3659 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3660 &command_pool);
3661
3662 VkCommandBuffer command_buffer[2];
3663 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3664 command_buffer_allocate_info.sType =
3665 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3666 command_buffer_allocate_info.commandPool = command_pool;
3667 command_buffer_allocate_info.commandBufferCount = 2;
3668 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3669 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3670 command_buffer);
3671
3672 VkQueue queue = VK_NULL_HANDLE;
3673 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3674 1, &queue);
3675
3676 {
3677 VkCommandBufferBeginInfo begin_info{};
3678 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3679 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3680
3681 vkCmdPipelineBarrier(command_buffer[0],
3682 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3683 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3684 0, nullptr, 0, nullptr);
3685
3686 VkViewport viewport{};
3687 viewport.maxDepth = 1.0f;
3688 viewport.minDepth = 0.0f;
3689 viewport.width = 512;
3690 viewport.height = 512;
3691 viewport.x = 0;
3692 viewport.y = 0;
3693 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3694 vkEndCommandBuffer(command_buffer[0]);
3695 }
3696 {
3697 VkCommandBufferBeginInfo begin_info{};
3698 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3699 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3700
3701 VkViewport viewport{};
3702 viewport.maxDepth = 1.0f;
3703 viewport.minDepth = 0.0f;
3704 viewport.width = 512;
3705 viewport.height = 512;
3706 viewport.x = 0;
3707 viewport.y = 0;
3708 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3709 vkEndCommandBuffer(command_buffer[1]);
3710 }
3711 {
3712 VkSubmitInfo submit_info{};
3713 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3714 submit_info.commandBufferCount = 1;
3715 submit_info.pCommandBuffers = &command_buffer[0];
3716 submit_info.signalSemaphoreCount = 1;
3717 submit_info.pSignalSemaphores = &semaphore;
3718 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3719 }
3720 {
3721 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3722 VkSubmitInfo submit_info{};
3723 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3724 submit_info.commandBufferCount = 1;
3725 submit_info.pCommandBuffers = &command_buffer[1];
3726 submit_info.waitSemaphoreCount = 1;
3727 submit_info.pWaitSemaphores = &semaphore;
3728 submit_info.pWaitDstStageMask = flags;
3729 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3730 }
3731
3732 vkQueueWaitIdle(m_device->m_queue);
3733
3734 vkDestroyFence(m_device->device(), fence, nullptr);
3735 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3736 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3737 &command_buffer[0]);
3738 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3739
3740 m_errorMonitor->VerifyNotFound();
3741}
3742
3743// This is a positive test. No errors should be generated.
3744TEST_F(VkLayerTest,
3745 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3746
3747 TEST_DESCRIPTION(
3748 "Two command buffers, each in a separate QueueSubmit call "
3749 "submitted on separate queues, the second having a fence"
3750 "followed by two consecutive WaitForFences calls on the same fence.");
3751
Dustin Graves48458142016-04-29 16:11:55 -06003752 if ((m_device->queue_props.empty()) ||
3753 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003754 return;
3755
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003756 m_errorMonitor->ExpectSuccess();
3757
3758 VkFence fence;
3759 VkFenceCreateInfo fence_create_info{};
3760 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3761 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3762
3763 VkSemaphore semaphore;
3764 VkSemaphoreCreateInfo semaphore_create_info{};
3765 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3766 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3767 &semaphore);
3768
3769 VkCommandPool command_pool;
3770 VkCommandPoolCreateInfo pool_create_info{};
3771 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3772 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3773 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3774 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3775 &command_pool);
3776
3777 VkCommandBuffer command_buffer[2];
3778 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3779 command_buffer_allocate_info.sType =
3780 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3781 command_buffer_allocate_info.commandPool = command_pool;
3782 command_buffer_allocate_info.commandBufferCount = 2;
3783 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3784 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3785 command_buffer);
3786
3787 VkQueue queue = VK_NULL_HANDLE;
3788 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3789 1, &queue);
3790
3791 {
3792 VkCommandBufferBeginInfo begin_info{};
3793 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3794 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3795
3796 vkCmdPipelineBarrier(command_buffer[0],
3797 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3798 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3799 0, nullptr, 0, nullptr);
3800
3801 VkViewport viewport{};
3802 viewport.maxDepth = 1.0f;
3803 viewport.minDepth = 0.0f;
3804 viewport.width = 512;
3805 viewport.height = 512;
3806 viewport.x = 0;
3807 viewport.y = 0;
3808 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3809 vkEndCommandBuffer(command_buffer[0]);
3810 }
3811 {
3812 VkCommandBufferBeginInfo begin_info{};
3813 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3814 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3815
3816 VkViewport viewport{};
3817 viewport.maxDepth = 1.0f;
3818 viewport.minDepth = 0.0f;
3819 viewport.width = 512;
3820 viewport.height = 512;
3821 viewport.x = 0;
3822 viewport.y = 0;
3823 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3824 vkEndCommandBuffer(command_buffer[1]);
3825 }
3826 {
3827 VkSubmitInfo submit_info{};
3828 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3829 submit_info.commandBufferCount = 1;
3830 submit_info.pCommandBuffers = &command_buffer[0];
3831 submit_info.signalSemaphoreCount = 1;
3832 submit_info.pSignalSemaphores = &semaphore;
3833 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3834 }
3835 {
3836 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3837 VkSubmitInfo submit_info{};
3838 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3839 submit_info.commandBufferCount = 1;
3840 submit_info.pCommandBuffers = &command_buffer[1];
3841 submit_info.waitSemaphoreCount = 1;
3842 submit_info.pWaitSemaphores = &semaphore;
3843 submit_info.pWaitDstStageMask = flags;
3844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3845 }
3846
3847 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3848 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3849
3850 vkDestroyFence(m_device->device(), fence, nullptr);
3851 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3852 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3853 &command_buffer[0]);
3854 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3855
3856 m_errorMonitor->VerifyNotFound();
3857}
3858
3859// This is a positive test. No errors should be generated.
3860TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3861
3862 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3863 "submitted on separate queues, the second having a fence, "
3864 "followed by a WaitForFences call.");
3865
Dustin Graves48458142016-04-29 16:11:55 -06003866 if ((m_device->queue_props.empty()) ||
3867 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003868 return;
3869
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003870 m_errorMonitor->ExpectSuccess();
3871
3872 VkFence fence;
3873 VkFenceCreateInfo fence_create_info{};
3874 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3875 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3876
3877 VkSemaphore semaphore;
3878 VkSemaphoreCreateInfo semaphore_create_info{};
3879 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3880 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3881 &semaphore);
3882
3883 VkCommandPool command_pool;
3884 VkCommandPoolCreateInfo pool_create_info{};
3885 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3886 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3887 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3888 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3889 &command_pool);
3890
3891 VkCommandBuffer command_buffer[2];
3892 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3893 command_buffer_allocate_info.sType =
3894 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3895 command_buffer_allocate_info.commandPool = command_pool;
3896 command_buffer_allocate_info.commandBufferCount = 2;
3897 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3898 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3899 command_buffer);
3900
3901 VkQueue queue = VK_NULL_HANDLE;
3902 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3903 1, &queue);
3904
3905
3906 {
3907 VkCommandBufferBeginInfo begin_info{};
3908 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3909 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3910
3911 vkCmdPipelineBarrier(command_buffer[0],
3912 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3913 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3914 0, nullptr, 0, nullptr);
3915
3916 VkViewport viewport{};
3917 viewport.maxDepth = 1.0f;
3918 viewport.minDepth = 0.0f;
3919 viewport.width = 512;
3920 viewport.height = 512;
3921 viewport.x = 0;
3922 viewport.y = 0;
3923 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3924 vkEndCommandBuffer(command_buffer[0]);
3925 }
3926 {
3927 VkCommandBufferBeginInfo begin_info{};
3928 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3929 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3930
3931 VkViewport viewport{};
3932 viewport.maxDepth = 1.0f;
3933 viewport.minDepth = 0.0f;
3934 viewport.width = 512;
3935 viewport.height = 512;
3936 viewport.x = 0;
3937 viewport.y = 0;
3938 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3939 vkEndCommandBuffer(command_buffer[1]);
3940 }
3941 {
3942 VkSubmitInfo submit_info{};
3943 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3944 submit_info.commandBufferCount = 1;
3945 submit_info.pCommandBuffers = &command_buffer[0];
3946 submit_info.signalSemaphoreCount = 1;
3947 submit_info.pSignalSemaphores = &semaphore;
3948 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3949 }
3950 {
3951 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3952 VkSubmitInfo submit_info{};
3953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3954 submit_info.commandBufferCount = 1;
3955 submit_info.pCommandBuffers = &command_buffer[1];
3956 submit_info.waitSemaphoreCount = 1;
3957 submit_info.pWaitSemaphores = &semaphore;
3958 submit_info.pWaitDstStageMask = flags;
3959 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3960 }
3961
3962 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3963
3964 vkDestroyFence(m_device->device(), fence, nullptr);
3965 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3966 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3967 &command_buffer[0]);
3968 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3969
3970 m_errorMonitor->VerifyNotFound();
3971}
3972
3973// This is a positive test. No errors should be generated.
3974TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3975
3976 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3977 "on the same queue, sharing a signal/wait semaphore, the "
3978 "second having a fence, "
3979 "followed by a WaitForFences call.");
3980
3981 m_errorMonitor->ExpectSuccess();
3982
3983 VkFence fence;
3984 VkFenceCreateInfo fence_create_info{};
3985 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3986 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3987
3988 VkSemaphore semaphore;
3989 VkSemaphoreCreateInfo semaphore_create_info{};
3990 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3991 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3992 &semaphore);
3993
3994 VkCommandPool command_pool;
3995 VkCommandPoolCreateInfo pool_create_info{};
3996 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3997 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3998 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3999 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4000 &command_pool);
4001
4002 VkCommandBuffer command_buffer[2];
4003 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4004 command_buffer_allocate_info.sType =
4005 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4006 command_buffer_allocate_info.commandPool = command_pool;
4007 command_buffer_allocate_info.commandBufferCount = 2;
4008 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4009 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4010 command_buffer);
4011
4012 {
4013 VkCommandBufferBeginInfo begin_info{};
4014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4015 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4016
4017 vkCmdPipelineBarrier(command_buffer[0],
4018 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4019 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4020 0, nullptr, 0, nullptr);
4021
4022 VkViewport viewport{};
4023 viewport.maxDepth = 1.0f;
4024 viewport.minDepth = 0.0f;
4025 viewport.width = 512;
4026 viewport.height = 512;
4027 viewport.x = 0;
4028 viewport.y = 0;
4029 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4030 vkEndCommandBuffer(command_buffer[0]);
4031 }
4032 {
4033 VkCommandBufferBeginInfo begin_info{};
4034 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4035 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4036
4037 VkViewport viewport{};
4038 viewport.maxDepth = 1.0f;
4039 viewport.minDepth = 0.0f;
4040 viewport.width = 512;
4041 viewport.height = 512;
4042 viewport.x = 0;
4043 viewport.y = 0;
4044 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4045 vkEndCommandBuffer(command_buffer[1]);
4046 }
4047 {
4048 VkSubmitInfo submit_info{};
4049 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4050 submit_info.commandBufferCount = 1;
4051 submit_info.pCommandBuffers = &command_buffer[0];
4052 submit_info.signalSemaphoreCount = 1;
4053 submit_info.pSignalSemaphores = &semaphore;
4054 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4055 }
4056 {
4057 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4058 VkSubmitInfo submit_info{};
4059 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4060 submit_info.commandBufferCount = 1;
4061 submit_info.pCommandBuffers = &command_buffer[1];
4062 submit_info.waitSemaphoreCount = 1;
4063 submit_info.pWaitSemaphores = &semaphore;
4064 submit_info.pWaitDstStageMask = flags;
4065 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4066 }
4067
4068 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4069
4070 vkDestroyFence(m_device->device(), fence, nullptr);
4071 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4072 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4073 &command_buffer[0]);
4074 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4075
4076 m_errorMonitor->VerifyNotFound();
4077}
4078
4079// This is a positive test. No errors should be generated.
4080TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4081
4082 TEST_DESCRIPTION(
4083 "Two command buffers, each in a separate QueueSubmit call "
4084 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4085 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4086
4087 m_errorMonitor->ExpectSuccess();
4088
4089 VkFence fence;
4090 VkFenceCreateInfo fence_create_info{};
4091 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4092 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4093
4094 VkCommandPool command_pool;
4095 VkCommandPoolCreateInfo pool_create_info{};
4096 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4097 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4098 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4099 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4100 &command_pool);
4101
4102 VkCommandBuffer command_buffer[2];
4103 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4104 command_buffer_allocate_info.sType =
4105 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4106 command_buffer_allocate_info.commandPool = command_pool;
4107 command_buffer_allocate_info.commandBufferCount = 2;
4108 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4109 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4110 command_buffer);
4111
4112 {
4113 VkCommandBufferBeginInfo begin_info{};
4114 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4115 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4116
4117 vkCmdPipelineBarrier(command_buffer[0],
4118 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4119 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4120 0, nullptr, 0, nullptr);
4121
4122 VkViewport viewport{};
4123 viewport.maxDepth = 1.0f;
4124 viewport.minDepth = 0.0f;
4125 viewport.width = 512;
4126 viewport.height = 512;
4127 viewport.x = 0;
4128 viewport.y = 0;
4129 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4130 vkEndCommandBuffer(command_buffer[0]);
4131 }
4132 {
4133 VkCommandBufferBeginInfo begin_info{};
4134 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4135 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4136
4137 VkViewport viewport{};
4138 viewport.maxDepth = 1.0f;
4139 viewport.minDepth = 0.0f;
4140 viewport.width = 512;
4141 viewport.height = 512;
4142 viewport.x = 0;
4143 viewport.y = 0;
4144 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4145 vkEndCommandBuffer(command_buffer[1]);
4146 }
4147 {
4148 VkSubmitInfo submit_info{};
4149 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4150 submit_info.commandBufferCount = 1;
4151 submit_info.pCommandBuffers = &command_buffer[0];
4152 submit_info.signalSemaphoreCount = 0;
4153 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4155 }
4156 {
4157 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4158 VkSubmitInfo submit_info{};
4159 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4160 submit_info.commandBufferCount = 1;
4161 submit_info.pCommandBuffers = &command_buffer[1];
4162 submit_info.waitSemaphoreCount = 0;
4163 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4164 submit_info.pWaitDstStageMask = flags;
4165 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4166 }
4167
4168 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4169
4170 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4171
4172 vkDestroyFence(m_device->device(), fence, nullptr);
4173 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4174 &command_buffer[0]);
4175 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4176
4177 m_errorMonitor->VerifyNotFound();
4178}
4179
4180// This is a positive test. No errors should be generated.
4181TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4182
4183 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4184 "on the same queue, the second having a fence, followed "
4185 "by a WaitForFences call.");
4186
4187 m_errorMonitor->ExpectSuccess();
4188
4189 VkFence fence;
4190 VkFenceCreateInfo fence_create_info{};
4191 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4192 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4193
4194 VkCommandPool command_pool;
4195 VkCommandPoolCreateInfo pool_create_info{};
4196 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4197 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4198 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4199 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4200 &command_pool);
4201
4202 VkCommandBuffer command_buffer[2];
4203 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4204 command_buffer_allocate_info.sType =
4205 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4206 command_buffer_allocate_info.commandPool = command_pool;
4207 command_buffer_allocate_info.commandBufferCount = 2;
4208 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4209 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4210 command_buffer);
4211
4212 {
4213 VkCommandBufferBeginInfo begin_info{};
4214 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4215 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4216
4217 vkCmdPipelineBarrier(command_buffer[0],
4218 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4219 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4220 0, nullptr, 0, nullptr);
4221
4222 VkViewport viewport{};
4223 viewport.maxDepth = 1.0f;
4224 viewport.minDepth = 0.0f;
4225 viewport.width = 512;
4226 viewport.height = 512;
4227 viewport.x = 0;
4228 viewport.y = 0;
4229 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4230 vkEndCommandBuffer(command_buffer[0]);
4231 }
4232 {
4233 VkCommandBufferBeginInfo begin_info{};
4234 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4235 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4236
4237 VkViewport viewport{};
4238 viewport.maxDepth = 1.0f;
4239 viewport.minDepth = 0.0f;
4240 viewport.width = 512;
4241 viewport.height = 512;
4242 viewport.x = 0;
4243 viewport.y = 0;
4244 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4245 vkEndCommandBuffer(command_buffer[1]);
4246 }
4247 {
4248 VkSubmitInfo submit_info{};
4249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4250 submit_info.commandBufferCount = 1;
4251 submit_info.pCommandBuffers = &command_buffer[0];
4252 submit_info.signalSemaphoreCount = 0;
4253 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4254 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4255 }
4256 {
4257 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4258 VkSubmitInfo submit_info{};
4259 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4260 submit_info.commandBufferCount = 1;
4261 submit_info.pCommandBuffers = &command_buffer[1];
4262 submit_info.waitSemaphoreCount = 0;
4263 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4264 submit_info.pWaitDstStageMask = flags;
4265 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4266 }
4267
4268 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4269
4270 vkDestroyFence(m_device->device(), fence, nullptr);
4271 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4272 &command_buffer[0]);
4273 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4274
4275 m_errorMonitor->VerifyNotFound();
4276}
4277
4278// This is a positive test. No errors should be generated.
4279TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4280
4281 TEST_DESCRIPTION(
4282 "Two command buffers each in a separate SubmitInfo sent in a single "
4283 "QueueSubmit call followed by a WaitForFences call.");
4284
4285 m_errorMonitor->ExpectSuccess();
4286
4287 VkFence fence;
4288 VkFenceCreateInfo fence_create_info{};
4289 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4290 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4291
4292 VkSemaphore semaphore;
4293 VkSemaphoreCreateInfo semaphore_create_info{};
4294 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4295 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4296 &semaphore);
4297
4298 VkCommandPool command_pool;
4299 VkCommandPoolCreateInfo pool_create_info{};
4300 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4301 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4302 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4303 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4304 &command_pool);
4305
4306 VkCommandBuffer command_buffer[2];
4307 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4308 command_buffer_allocate_info.sType =
4309 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4310 command_buffer_allocate_info.commandPool = command_pool;
4311 command_buffer_allocate_info.commandBufferCount = 2;
4312 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4313 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4314 command_buffer);
4315
4316 {
4317 VkCommandBufferBeginInfo begin_info{};
4318 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4319 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4320
4321 vkCmdPipelineBarrier(command_buffer[0],
4322 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4323 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4324 0, nullptr, 0, nullptr);
4325
4326 VkViewport viewport{};
4327 viewport.maxDepth = 1.0f;
4328 viewport.minDepth = 0.0f;
4329 viewport.width = 512;
4330 viewport.height = 512;
4331 viewport.x = 0;
4332 viewport.y = 0;
4333 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4334 vkEndCommandBuffer(command_buffer[0]);
4335 }
4336 {
4337 VkCommandBufferBeginInfo begin_info{};
4338 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4339 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4340
4341 VkViewport viewport{};
4342 viewport.maxDepth = 1.0f;
4343 viewport.minDepth = 0.0f;
4344 viewport.width = 512;
4345 viewport.height = 512;
4346 viewport.x = 0;
4347 viewport.y = 0;
4348 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4349 vkEndCommandBuffer(command_buffer[1]);
4350 }
4351 {
4352 VkSubmitInfo submit_info[2];
4353 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4354
4355 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4356 submit_info[0].pNext = NULL;
4357 submit_info[0].commandBufferCount = 1;
4358 submit_info[0].pCommandBuffers = &command_buffer[0];
4359 submit_info[0].signalSemaphoreCount = 1;
4360 submit_info[0].pSignalSemaphores = &semaphore;
4361 submit_info[0].waitSemaphoreCount = 0;
4362 submit_info[0].pWaitSemaphores = NULL;
4363 submit_info[0].pWaitDstStageMask = 0;
4364
4365 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4366 submit_info[1].pNext = NULL;
4367 submit_info[1].commandBufferCount = 1;
4368 submit_info[1].pCommandBuffers = &command_buffer[1];
4369 submit_info[1].waitSemaphoreCount = 1;
4370 submit_info[1].pWaitSemaphores = &semaphore;
4371 submit_info[1].pWaitDstStageMask = flags;
4372 submit_info[1].signalSemaphoreCount = 0;
4373 submit_info[1].pSignalSemaphores = NULL;
4374 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4375 }
4376
4377 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4378
4379 vkDestroyFence(m_device->device(), fence, nullptr);
4380 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4381 &command_buffer[0]);
4382 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004383 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004384
4385 m_errorMonitor->VerifyNotFound();
4386}
4387
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004388TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004389 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004390 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4391 "state is required but not correctly bound.");
4392
4393 // Dynamic depth bias
4394 m_errorMonitor->SetDesiredFailureMsg(
4395 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4396 "Dynamic depth bias state not set for this command buffer");
4397 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4398 BsoFailDepthBias);
4399 m_errorMonitor->VerifyFound();
4400}
4401
4402TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4403 TEST_DESCRIPTION(
4404 "Run a simple draw calls to validate failure when Line Width dynamic "
4405 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004406
4407 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004408 m_errorMonitor->SetDesiredFailureMsg(
4409 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004410 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004411 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4412 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004413 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004414}
4415
4416TEST_F(VkLayerTest, DynamicViewportNotBound) {
4417 TEST_DESCRIPTION(
4418 "Run a simple draw calls to validate failure when Viewport dynamic "
4419 "state is required but not correctly bound.");
4420
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004421 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004422 m_errorMonitor->SetDesiredFailureMsg(
4423 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004424 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004425 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4426 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004427 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004428}
4429
4430TEST_F(VkLayerTest, DynamicScissorNotBound) {
4431 TEST_DESCRIPTION(
4432 "Run a simple draw calls to validate failure when Scissor dynamic "
4433 "state is required but not correctly bound.");
4434
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004435 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004436 m_errorMonitor->SetDesiredFailureMsg(
4437 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004438 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004439 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4440 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004441 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004442}
4443
Tobin Ehlis21c88352016-05-26 06:15:45 -06004444TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004445 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004446 "Run a simple draw calls to validate failure when Blend Constants "
4447 "dynamic state is required but not correctly bound.");
4448 // Dynamic blend constant state
4449 m_errorMonitor->SetDesiredFailureMsg(
4450 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4451 "Dynamic blend constants state not set for this command buffer");
4452 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4453 BsoFailBlend);
4454 m_errorMonitor->VerifyFound();
4455}
4456
4457TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4458 TEST_DESCRIPTION(
4459 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004460 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004461 if (!m_device->phy().features().depthBounds) {
4462 printf("Device does not support depthBounds test; skipped.\n");
4463 return;
4464 }
4465 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004466 m_errorMonitor->SetDesiredFailureMsg(
4467 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004468 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004469 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4470 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004471 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004472}
4473
4474TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4475 TEST_DESCRIPTION(
4476 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4477 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004478 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004479 m_errorMonitor->SetDesiredFailureMsg(
4480 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004481 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004482 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4483 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004484 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004485}
4486
4487TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4488 TEST_DESCRIPTION(
4489 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4490 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004491 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004492 m_errorMonitor->SetDesiredFailureMsg(
4493 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004494 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004495 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4496 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004497 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004498}
4499
4500TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4501 TEST_DESCRIPTION(
4502 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4503 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004504 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004505 m_errorMonitor->SetDesiredFailureMsg(
4506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004507 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004508 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4509 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004510 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004511}
4512
Karl Schultz6addd812016-02-02 17:17:23 -07004513TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004514 m_errorMonitor->SetDesiredFailureMsg(
4515 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4516 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4517 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004518
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004519 ASSERT_NO_FATAL_FAILURE(InitState());
4520 ASSERT_NO_FATAL_FAILURE(InitViewport());
4521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4522
Karl Schultz6addd812016-02-02 17:17:23 -07004523 // We luck out b/c by default the framework creates CB w/ the
4524 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004525 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004526 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4527 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004528 EndCommandBuffer();
4529
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004530 // Bypass framework since it does the waits automatically
4531 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004532 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004533 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4534 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004535 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004536 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004537 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004538 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004539 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004540 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004541 submit_info.pSignalSemaphores = NULL;
4542
Chris Forbes40028e22016-06-13 09:59:34 +12004543 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004544 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004545
Karl Schultz6addd812016-02-02 17:17:23 -07004546 // Cause validation error by re-submitting cmd buffer that should only be
4547 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004548 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004549
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004550 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004551}
4552
Karl Schultz6addd812016-02-02 17:17:23 -07004553TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004554 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004555 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004556
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004558 "Unable to allocate 1 descriptors of "
4559 "type "
4560 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004561
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004562 ASSERT_NO_FATAL_FAILURE(InitState());
4563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004564
Karl Schultz6addd812016-02-02 17:17:23 -07004565 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4566 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004567 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004568 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4569 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004570
4571 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004572 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4573 ds_pool_ci.pNext = NULL;
4574 ds_pool_ci.flags = 0;
4575 ds_pool_ci.maxSets = 1;
4576 ds_pool_ci.poolSizeCount = 1;
4577 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004578
4579 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004580 err =
4581 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004582 ASSERT_VK_SUCCESS(err);
4583
4584 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004585 dsl_binding.binding = 0;
4586 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4587 dsl_binding.descriptorCount = 1;
4588 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4589 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004590
4591 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004592 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4593 ds_layout_ci.pNext = NULL;
4594 ds_layout_ci.bindingCount = 1;
4595 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004596
4597 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4599 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004600 ASSERT_VK_SUCCESS(err);
4601
4602 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004603 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004605 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004606 alloc_info.descriptorPool = ds_pool;
4607 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4609 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004610
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004611 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004612
Chia-I Wuf7458c52015-10-26 21:10:41 +08004613 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4614 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004615}
4616
Karl Schultz6addd812016-02-02 17:17:23 -07004617TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4618 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004619
Karl Schultz6addd812016-02-02 17:17:23 -07004620 m_errorMonitor->SetDesiredFailureMsg(
4621 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4622 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4623 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004624
Tobin Ehlise735c692015-10-08 13:13:50 -06004625 ASSERT_NO_FATAL_FAILURE(InitState());
4626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004627
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004628 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004629 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4630 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004631
4632 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004633 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4634 ds_pool_ci.pNext = NULL;
4635 ds_pool_ci.maxSets = 1;
4636 ds_pool_ci.poolSizeCount = 1;
4637 ds_pool_ci.flags = 0;
4638 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4639 // app can only call vkResetDescriptorPool on this pool.;
4640 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004641
4642 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004643 err =
4644 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004645 ASSERT_VK_SUCCESS(err);
4646
4647 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004648 dsl_binding.binding = 0;
4649 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4650 dsl_binding.descriptorCount = 1;
4651 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4652 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004653
4654 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004655 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4656 ds_layout_ci.pNext = NULL;
4657 ds_layout_ci.bindingCount = 1;
4658 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004659
4660 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004661 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4662 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004663 ASSERT_VK_SUCCESS(err);
4664
4665 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004666 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004668 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004669 alloc_info.descriptorPool = ds_pool;
4670 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004671 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4672 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004673 ASSERT_VK_SUCCESS(err);
4674
4675 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004676 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004677
Chia-I Wuf7458c52015-10-26 21:10:41 +08004678 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4679 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004680}
4681
Karl Schultz6addd812016-02-02 17:17:23 -07004682TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004683 // Attempt to clear Descriptor Pool with bad object.
4684 // ObjectTracker should catch this.
4685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4686 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004687 uint64_t fake_pool_handle = 0xbaad6001;
4688 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4689 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004690 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004691}
4692
Karl Schultz6addd812016-02-02 17:17:23 -07004693TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004694 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4695 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004696 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004697 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004698
4699 uint64_t fake_set_handle = 0xbaad6001;
4700 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004701 VkResult err;
4702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4703 "Invalid VkDescriptorSet Object 0xbaad6001");
4704
4705 ASSERT_NO_FATAL_FAILURE(InitState());
4706
4707 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4708 layout_bindings[0].binding = 0;
4709 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4710 layout_bindings[0].descriptorCount = 1;
4711 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4712 layout_bindings[0].pImmutableSamplers = NULL;
4713
4714 VkDescriptorSetLayout descriptor_set_layout;
4715 VkDescriptorSetLayoutCreateInfo dslci = {};
4716 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4717 dslci.pNext = NULL;
4718 dslci.bindingCount = 1;
4719 dslci.pBindings = layout_bindings;
4720 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004721 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004722
4723 VkPipelineLayout pipeline_layout;
4724 VkPipelineLayoutCreateInfo plci = {};
4725 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4726 plci.pNext = NULL;
4727 plci.setLayoutCount = 1;
4728 plci.pSetLayouts = &descriptor_set_layout;
4729 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004730 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004731
4732 BeginCommandBuffer();
4733 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004734 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004735 m_errorMonitor->VerifyFound();
4736 EndCommandBuffer();
4737 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4738 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004739}
4740
Karl Schultz6addd812016-02-02 17:17:23 -07004741TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004742 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4743 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004744 uint64_t fake_layout_handle = 0xbaad6001;
4745 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4747 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4748
4749 VkPipelineLayout pipeline_layout;
4750 VkPipelineLayoutCreateInfo plci = {};
4751 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4752 plci.pNext = NULL;
4753 plci.setLayoutCount = 1;
4754 plci.pSetLayouts = &bad_layout;
4755 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4756
4757 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004758}
4759
Mark Muellerd4914412016-06-13 17:52:06 -06004760TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4761 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4762 "1) A uniform buffer update must have a valid buffer index."
4763 "2) When using an array of descriptors in a single WriteDescriptor,"
4764 " the descriptor types and stageflags must all be the same."
4765 "3) Immutable Sampler state must match across descriptors");
4766
4767 const char *invalid_BufferInfo_ErrorMessage =
4768 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4769 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4770 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4771 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004772 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004773 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004774 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004775
Mark Muellerd4914412016-06-13 17:52:06 -06004776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4777
4778 ASSERT_NO_FATAL_FAILURE(InitState());
4779 VkDescriptorPoolSize ds_type_count[4] = {};
4780 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4781 ds_type_count[0].descriptorCount = 1;
4782 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4783 ds_type_count[1].descriptorCount = 1;
4784 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4785 ds_type_count[2].descriptorCount = 1;
4786 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4787 ds_type_count[3].descriptorCount = 1;
4788
4789 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4790 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4791 ds_pool_ci.maxSets = 1;
4792 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4793 ds_pool_ci.pPoolSizes = ds_type_count;
4794
4795 VkDescriptorPool ds_pool;
4796 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4797 ASSERT_VK_SUCCESS(err);
4798
Mark Muellerb9896722016-06-16 09:54:29 -06004799 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004800 layout_binding[0].binding = 0;
4801 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4802 layout_binding[0].descriptorCount = 1;
4803 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4804 layout_binding[0].pImmutableSamplers = NULL;
4805
4806 layout_binding[1].binding = 1;
4807 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4808 layout_binding[1].descriptorCount = 1;
4809 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4810 layout_binding[1].pImmutableSamplers = NULL;
4811
4812 VkSamplerCreateInfo sampler_ci = {};
4813 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4814 sampler_ci.pNext = NULL;
4815 sampler_ci.magFilter = VK_FILTER_NEAREST;
4816 sampler_ci.minFilter = VK_FILTER_NEAREST;
4817 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4818 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4819 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4820 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4821 sampler_ci.mipLodBias = 1.0;
4822 sampler_ci.anisotropyEnable = VK_FALSE;
4823 sampler_ci.maxAnisotropy = 1;
4824 sampler_ci.compareEnable = VK_FALSE;
4825 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4826 sampler_ci.minLod = 1.0;
4827 sampler_ci.maxLod = 1.0;
4828 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4829 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4830 VkSampler sampler;
4831
4832 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4833 ASSERT_VK_SUCCESS(err);
4834
4835 layout_binding[2].binding = 2;
4836 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4837 layout_binding[2].descriptorCount = 1;
4838 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4839 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4840
Mark Muellerd4914412016-06-13 17:52:06 -06004841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4843 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4844 ds_layout_ci.pBindings = layout_binding;
4845 VkDescriptorSetLayout ds_layout;
4846 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4847 ASSERT_VK_SUCCESS(err);
4848
4849 VkDescriptorSetAllocateInfo alloc_info = {};
4850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4851 alloc_info.descriptorSetCount = 1;
4852 alloc_info.descriptorPool = ds_pool;
4853 alloc_info.pSetLayouts = &ds_layout;
4854 VkDescriptorSet descriptorSet;
4855 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4856 ASSERT_VK_SUCCESS(err);
4857
4858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4860 pipeline_layout_ci.pNext = NULL;
4861 pipeline_layout_ci.setLayoutCount = 1;
4862 pipeline_layout_ci.pSetLayouts = &ds_layout;
4863
4864 VkPipelineLayout pipeline_layout;
4865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4866 ASSERT_VK_SUCCESS(err);
4867
Mark Mueller5c838ce2016-06-16 09:54:29 -06004868 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004869 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4870 descriptor_write.dstSet = descriptorSet;
4871 descriptor_write.dstBinding = 0;
4872 descriptor_write.descriptorCount = 1;
4873 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4874
Mark Mueller5c838ce2016-06-16 09:54:29 -06004875 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004876 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4877 m_errorMonitor->VerifyFound();
4878
4879 // Create a buffer to update the descriptor with
4880 uint32_t qfi = 0;
4881 VkBufferCreateInfo buffCI = {};
4882 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4883 buffCI.size = 1024;
4884 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4885 buffCI.queueFamilyIndexCount = 1;
4886 buffCI.pQueueFamilyIndices = &qfi;
4887
4888 VkBuffer dyub;
4889 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4890 ASSERT_VK_SUCCESS(err);
4891 VkDescriptorBufferInfo buffInfo = {};
4892 buffInfo.buffer = dyub;
4893 buffInfo.offset = 0;
4894 buffInfo.range = 1024;
4895
4896 descriptor_write.pBufferInfo = &buffInfo;
4897 descriptor_write.descriptorCount = 2;
4898
Mark Mueller5c838ce2016-06-16 09:54:29 -06004899 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4902 m_errorMonitor->VerifyFound();
4903
Mark Mueller5c838ce2016-06-16 09:54:29 -06004904 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4905 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004906 descriptor_write.dstBinding = 1;
4907 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004908
4909
4910 // Make pImageInfo index non-null to avoid complaints of it missing
4911 VkDescriptorImageInfo imageInfo = {};
4912 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4913 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4915 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4916 m_errorMonitor->VerifyFound();
4917
Mark Muellerd4914412016-06-13 17:52:06 -06004918 vkDestroyBuffer(m_device->device(), dyub, NULL);
4919 vkDestroySampler(m_device->device(), sampler, NULL);
4920 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4921 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4922 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4923}
4924
Karl Schultz6addd812016-02-02 17:17:23 -07004925TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004926 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4927 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004928 // Create a valid cmd buffer
4929 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004930 uint64_t fake_pipeline_handle = 0xbaad6001;
4931 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4933 "Invalid VkPipeline Object 0xbaad6001");
4934 ASSERT_NO_FATAL_FAILURE(InitState());
4935 BeginCommandBuffer();
4936 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4937 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4938 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004939 // Now issue a draw call with no pipeline bound
4940 m_errorMonitor->SetDesiredFailureMsg(
4941 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4942 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004943
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004944 BeginCommandBuffer();
4945 Draw(1, 0, 0, 0);
4946 m_errorMonitor->VerifyFound();
4947 // Finally same check once more but with Dispatch/Compute
4948 m_errorMonitor->SetDesiredFailureMsg(
4949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4950 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004951 BeginCommandBuffer();
4952 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4953 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004954}
4955
Karl Schultz6addd812016-02-02 17:17:23 -07004956TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4957 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4958 // CommandBuffer
4959 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004960
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004962 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004963
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004964 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004965 ASSERT_NO_FATAL_FAILURE(InitViewport());
4966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004967 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004968 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4969 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004970
4971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4973 ds_pool_ci.pNext = NULL;
4974 ds_pool_ci.maxSets = 1;
4975 ds_pool_ci.poolSizeCount = 1;
4976 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004977
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004978 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004979 err =
4980 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004981 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004982
Tony Barboureb254902015-07-15 12:50:33 -06004983 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004984 dsl_binding.binding = 0;
4985 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4986 dsl_binding.descriptorCount = 1;
4987 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4988 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004989
Tony Barboureb254902015-07-15 12:50:33 -06004990 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004991 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4992 ds_layout_ci.pNext = NULL;
4993 ds_layout_ci.bindingCount = 1;
4994 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004995 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4997 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004998 ASSERT_VK_SUCCESS(err);
4999
5000 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005001 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005003 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005004 alloc_info.descriptorPool = ds_pool;
5005 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5007 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005008 ASSERT_VK_SUCCESS(err);
5009
Tony Barboureb254902015-07-15 12:50:33 -06005010 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005011 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5012 pipeline_layout_ci.pNext = NULL;
5013 pipeline_layout_ci.setLayoutCount = 1;
5014 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005015
5016 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5018 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005019 ASSERT_VK_SUCCESS(err);
5020
Karl Schultz6addd812016-02-02 17:17:23 -07005021 VkShaderObj vs(m_device, bindStateVertShaderText,
5022 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005023 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005024 // on more devices
5025 VkShaderObj fs(m_device, bindStateFragShaderText,
5026 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005027
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005028 VkPipelineObj pipe(m_device);
5029 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005030 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005031 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005032 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005033
5034 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005035 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5036 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5038 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5039 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005041 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005042
Chia-I Wuf7458c52015-10-26 21:10:41 +08005043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005046}
5047
Karl Schultz6addd812016-02-02 17:17:23 -07005048TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005049 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005050 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005051
Karl Schultz6addd812016-02-02 17:17:23 -07005052 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005053 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5054 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005055
5056 ASSERT_NO_FATAL_FAILURE(InitState());
5057 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005058 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5059 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005060
5061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5063 ds_pool_ci.pNext = NULL;
5064 ds_pool_ci.maxSets = 1;
5065 ds_pool_ci.poolSizeCount = 1;
5066 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005067
5068 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005069 err =
5070 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005071 ASSERT_VK_SUCCESS(err);
5072
5073 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005074 dsl_binding.binding = 0;
5075 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5076 dsl_binding.descriptorCount = 1;
5077 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5078 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005079
5080 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005081 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5082 ds_layout_ci.pNext = NULL;
5083 ds_layout_ci.bindingCount = 1;
5084 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005085 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5087 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005088 ASSERT_VK_SUCCESS(err);
5089
5090 VkDescriptorSet descriptorSet;
5091 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005092 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005093 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005094 alloc_info.descriptorPool = ds_pool;
5095 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005096 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5097 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005098 ASSERT_VK_SUCCESS(err);
5099
Karl Schultz6addd812016-02-02 17:17:23 -07005100 VkBufferView view =
5101 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005102 VkWriteDescriptorSet descriptor_write;
5103 memset(&descriptor_write, 0, sizeof(descriptor_write));
5104 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5105 descriptor_write.dstSet = descriptorSet;
5106 descriptor_write.dstBinding = 0;
5107 descriptor_write.descriptorCount = 1;
5108 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5109 descriptor_write.pTexelBufferView = &view;
5110
5111 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5112
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005113 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005114
5115 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5116 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5117}
5118
Karl Schultz6addd812016-02-02 17:17:23 -07005119TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5120 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5121 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005122 // 1. No dynamicOffset supplied
5123 // 2. Too many dynamicOffsets supplied
5124 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005125 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005127 " requires 1 dynamicOffsets, but only "
5128 "0 dynamicOffsets are left in "
5129 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005130
5131 ASSERT_NO_FATAL_FAILURE(InitState());
5132 ASSERT_NO_FATAL_FAILURE(InitViewport());
5133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5134
5135 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005136 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5137 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005138
5139 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005140 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5141 ds_pool_ci.pNext = NULL;
5142 ds_pool_ci.maxSets = 1;
5143 ds_pool_ci.poolSizeCount = 1;
5144 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005145
5146 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005147 err =
5148 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005149 ASSERT_VK_SUCCESS(err);
5150
5151 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005152 dsl_binding.binding = 0;
5153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5154 dsl_binding.descriptorCount = 1;
5155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5156 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005157
5158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5160 ds_layout_ci.pNext = NULL;
5161 ds_layout_ci.bindingCount = 1;
5162 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005163 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5165 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005166 ASSERT_VK_SUCCESS(err);
5167
5168 VkDescriptorSet descriptorSet;
5169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005171 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005172 alloc_info.descriptorPool = ds_pool;
5173 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5175 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005176 ASSERT_VK_SUCCESS(err);
5177
5178 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005179 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5180 pipeline_layout_ci.pNext = NULL;
5181 pipeline_layout_ci.setLayoutCount = 1;
5182 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005183
5184 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005185 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5186 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005187 ASSERT_VK_SUCCESS(err);
5188
5189 // Create a buffer to update the descriptor with
5190 uint32_t qfi = 0;
5191 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005192 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5193 buffCI.size = 1024;
5194 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5195 buffCI.queueFamilyIndexCount = 1;
5196 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005197
5198 VkBuffer dyub;
5199 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5200 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005201 // Allocate memory and bind to buffer so we can make it to the appropriate
5202 // error
5203 VkMemoryAllocateInfo mem_alloc = {};
5204 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5205 mem_alloc.pNext = NULL;
5206 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005207 mem_alloc.memoryTypeIndex = 0;
5208
5209 VkMemoryRequirements memReqs;
5210 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5211 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5212 0);
5213 if (!pass) {
5214 vkDestroyBuffer(m_device->device(), dyub, NULL);
5215 return;
5216 }
5217
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005218 VkDeviceMemory mem;
5219 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5220 ASSERT_VK_SUCCESS(err);
5221 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5222 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005223 // Correctly update descriptor to avoid "NOT_UPDATED" error
5224 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005225 buffInfo.buffer = dyub;
5226 buffInfo.offset = 0;
5227 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005228
5229 VkWriteDescriptorSet descriptor_write;
5230 memset(&descriptor_write, 0, sizeof(descriptor_write));
5231 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5232 descriptor_write.dstSet = descriptorSet;
5233 descriptor_write.dstBinding = 0;
5234 descriptor_write.descriptorCount = 1;
5235 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5236 descriptor_write.pBufferInfo = &buffInfo;
5237
5238 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5239
5240 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5242 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5243 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005244 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005245 uint32_t pDynOff[2] = {512, 756};
5246 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005247 m_errorMonitor->SetDesiredFailureMsg(
5248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005249 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5251 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5252 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005253 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005254 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5256 " dynamic offset 512 combined with "
5257 "offset 0 and range 1024 that "
5258 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005259 // Create PSO to be used for draw-time errors below
5260 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005261 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005262 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005263 "out gl_PerVertex { \n"
5264 " vec4 gl_Position;\n"
5265 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005266 "void main(){\n"
5267 " gl_Position = vec4(1);\n"
5268 "}\n";
5269 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005270 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005271 "\n"
5272 "layout(location=0) out vec4 x;\n"
5273 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5274 "void main(){\n"
5275 " x = vec4(bar.y);\n"
5276 "}\n";
5277 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5278 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5279 VkPipelineObj pipe(m_device);
5280 pipe.AddShader(&vs);
5281 pipe.AddShader(&fs);
5282 pipe.AddColorAttachment();
5283 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5284
Karl Schultz6addd812016-02-02 17:17:23 -07005285 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5286 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5287 // This update should succeed, but offset size of 512 will overstep buffer
5288 // /w range 1024 & size 1024
5289 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5290 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5291 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005292 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005293 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005294
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005295 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005296 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005297
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5301}
5302
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005303TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005304 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005305 ASSERT_NO_FATAL_FAILURE(InitState());
5306 ASSERT_NO_FATAL_FAILURE(InitViewport());
5307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5308
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005309 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005310 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005311 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5312 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5313 pipeline_layout_ci.pushConstantRangeCount = 1;
5314 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5315
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005316 //
5317 // Check for invalid push constant ranges in pipeline layouts.
5318 //
5319 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005320 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005321 char const *msg;
5322 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005323
Karl Schultzc81037d2016-05-12 08:11:23 -06005324 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5325 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5326 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5327 "vkCreatePipelineLayout() call has push constants index 0 with "
5328 "size 0."},
5329 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5330 "vkCreatePipelineLayout() call has push constants index 0 with "
5331 "size 1."},
5332 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5333 "vkCreatePipelineLayout() call has push constants index 0 with "
5334 "size 1."},
5335 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5336 "vkCreatePipelineLayout() call has push constants index 0 with "
5337 "size 0."},
5338 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5339 "vkCreatePipelineLayout() call has push constants index 0 with "
5340 "offset 1. Offset must"},
5341 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5342 "vkCreatePipelineLayout() call has push constants index 0 "
5343 "with offset "},
5344 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5345 "vkCreatePipelineLayout() call has push constants "
5346 "index 0 with offset "},
5347 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5348 "vkCreatePipelineLayout() call has push constants index 0 "
5349 "with offset "},
5350 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5351 "vkCreatePipelineLayout() call has push "
5352 "constants index 0 with offset "},
5353 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5354 "vkCreatePipelineLayout() call has push "
5355 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005356 }};
5357
5358 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005359 for (const auto &iter : range_tests) {
5360 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5362 iter.msg);
5363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5364 NULL, &pipeline_layout);
5365 m_errorMonitor->VerifyFound();
5366 if (VK_SUCCESS == err) {
5367 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5368 }
5369 }
5370
5371 // Check for invalid stage flag
5372 pc_range.offset = 0;
5373 pc_range.size = 16;
5374 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005375 m_errorMonitor->SetDesiredFailureMsg(
5376 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005377 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005378 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5379 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005380 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005381 if (VK_SUCCESS == err) {
5382 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5383 }
5384
5385 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005386 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005387 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005388 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005389 char const *msg;
5390 };
5391
Karl Schultzc81037d2016-05-12 08:11:23 -06005392 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005393 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5394 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5395 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5396 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5397 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5398 "vkCreatePipelineLayout() call has push constants with overlapping "
5399 "ranges: 0:[0, 4), 1:[0, 4)"},
5400 {
5401 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5402 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5403 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5404 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5405 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5406 "vkCreatePipelineLayout() call has push constants with "
5407 "overlapping "
5408 "ranges: 3:[12, 20), 4:[16, 20)",
5409 },
5410 {
5411 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5412 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5413 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5414 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5415 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5416 "vkCreatePipelineLayout() call has push constants with "
5417 "overlapping "
5418 "ranges: 0:[16, 20), 1:[12, 20)",
5419 },
5420 {
5421 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5422 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5423 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5424 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5425 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5426 "vkCreatePipelineLayout() call has push constants with "
5427 "overlapping "
5428 "ranges: 0:[16, 20), 3:[12, 20)",
5429 },
5430 {
5431 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5432 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5433 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5434 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5435 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5436 "vkCreatePipelineLayout() call has push constants with "
5437 "overlapping "
5438 "ranges: 0:[16, 20), 2:[4, 100)",
5439 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005440
Karl Schultzc81037d2016-05-12 08:11:23 -06005441 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005442 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005443 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005445 iter.msg);
5446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5447 NULL, &pipeline_layout);
5448 m_errorMonitor->VerifyFound();
5449 if (VK_SUCCESS == err) {
5450 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5451 }
5452 }
5453
5454 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005455 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5456 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5457 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5458 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5459 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5460 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5461 ""},
5462 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5463 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5464 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5465 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5466 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5467 ""}}};
5468 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005469 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5470 m_errorMonitor->ExpectSuccess();
5471 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5472 NULL, &pipeline_layout);
5473 m_errorMonitor->VerifyNotFound();
5474 if (VK_SUCCESS == err) {
5475 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5476 }
5477 }
5478
5479 //
5480 // CmdPushConstants tests
5481 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005482 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005483
5484 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005485 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5486 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5487 "vkCmdPushConstants() call has push constants with size 0. Size "
5488 "must be greater than zero and a multiple of 4."},
5489 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5490 "vkCmdPushConstants() call has push constants with size 1. Size "
5491 "must be greater than zero and a multiple of 4."},
5492 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5493 "vkCmdPushConstants() call has push constants with size 1. Size "
5494 "must be greater than zero and a multiple of 4."},
5495 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5496 "vkCmdPushConstants() call has push constants with offset 1. "
5497 "Offset must be a multiple of 4."},
5498 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5499 "vkCmdPushConstants() call has push constants with offset 1. "
5500 "Offset must be a multiple of 4."},
5501 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5502 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5503 "0x1 not within flag-matching ranges in pipeline layout"},
5504 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5505 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5506 "0x1 not within flag-matching ranges in pipeline layout"},
5507 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5508 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5509 "0x1 not within flag-matching ranges in pipeline layout"},
5510 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5511 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5512 "0x1 not within flag-matching ranges in pipeline layout"},
5513 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5514 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5515 "any of the ranges in pipeline layout"},
5516 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5517 0, 16},
5518 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5519 "any of the ranges in pipeline layout"},
5520 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005521 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005522 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005523 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005524 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005525 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005526 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005527 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005528 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005529 "vkCmdPushConstants() call has push constants with offset "},
5530 }};
5531
5532 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005533 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005534 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005535 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005536 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005537 pipeline_layout_ci.pushConstantRangeCount =
5538 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005539 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005540 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5541 &pipeline_layout);
5542 ASSERT_VK_SUCCESS(err);
5543 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005544 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5546 iter.msg);
5547 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005548 iter.range.stageFlags, iter.range.offset,
5549 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005550 m_errorMonitor->VerifyFound();
5551 }
5552
5553 // Check for invalid stage flag
5554 m_errorMonitor->SetDesiredFailureMsg(
5555 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5556 "vkCmdPushConstants() call has no stageFlags set.");
5557 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005558 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005559 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005560 EndCommandBuffer();
5561 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5562 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005563
Karl Schultzc81037d2016-05-12 08:11:23 -06005564 // overlapping range tests with cmd
5565 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5566 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5567 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5568 "0x1 not within flag-matching ranges in pipeline layout"},
5569 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5570 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5571 "0x1 not within flag-matching ranges in pipeline layout"},
5572 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5573 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5574 "0x1 not within flag-matching ranges in pipeline layout"},
5575 }};
5576 const VkPushConstantRange pc_range3[] = {
5577 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5578 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5579 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5580 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5581 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5582 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5583 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5584 };
5585 pipeline_layout_ci.pushConstantRangeCount =
5586 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5587 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5588 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5589 &pipeline_layout);
5590 ASSERT_VK_SUCCESS(err);
5591 BeginCommandBuffer();
5592 for (const auto &iter : cmd_overlap_tests) {
5593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5594 iter.msg);
5595 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5596 iter.range.stageFlags, iter.range.offset,
5597 iter.range.size, dummy_values);
5598 m_errorMonitor->VerifyFound();
5599 }
5600 EndCommandBuffer();
5601 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5603
5604 // positive overlapping range tests with cmd
5605 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5606 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5607 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5608 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5609 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5610 }};
5611 const VkPushConstantRange pc_range4[] = {
5612 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5613 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5614 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5615 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5616 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5617 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5618 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5619 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5620 };
5621 pipeline_layout_ci.pushConstantRangeCount =
5622 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5623 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5624 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5625 &pipeline_layout);
5626 ASSERT_VK_SUCCESS(err);
5627 BeginCommandBuffer();
5628 for (const auto &iter : cmd_overlap_tests_pos) {
5629 m_errorMonitor->ExpectSuccess();
5630 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5631 iter.range.stageFlags, iter.range.offset,
5632 iter.range.size, dummy_values);
5633 m_errorMonitor->VerifyNotFound();
5634 }
5635 EndCommandBuffer();
5636 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005637 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5638}
5639
Karl Schultz6addd812016-02-02 17:17:23 -07005640TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005641 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005642 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005643
5644 ASSERT_NO_FATAL_FAILURE(InitState());
5645 ASSERT_NO_FATAL_FAILURE(InitViewport());
5646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5647
5648 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5649 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005650 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5651 ds_type_count[0].descriptorCount = 10;
5652 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5653 ds_type_count[1].descriptorCount = 2;
5654 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5655 ds_type_count[2].descriptorCount = 2;
5656 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5657 ds_type_count[3].descriptorCount = 5;
5658 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5659 // type
5660 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5661 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5662 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005663
5664 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5666 ds_pool_ci.pNext = NULL;
5667 ds_pool_ci.maxSets = 5;
5668 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5669 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005670
5671 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005672 err =
5673 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005674 ASSERT_VK_SUCCESS(err);
5675
5676 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5677 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005678 dsl_binding[0].binding = 0;
5679 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5680 dsl_binding[0].descriptorCount = 5;
5681 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5682 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005683
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005684 // Create layout identical to set0 layout but w/ different stageFlags
5685 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005686 dsl_fs_stage_only.binding = 0;
5687 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5688 dsl_fs_stage_only.descriptorCount = 5;
5689 dsl_fs_stage_only.stageFlags =
5690 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5691 // bind time
5692 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005693 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005694 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5695 ds_layout_ci.pNext = NULL;
5696 ds_layout_ci.bindingCount = 1;
5697 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005698 static const uint32_t NUM_LAYOUTS = 4;
5699 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005700 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005701 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5702 // layout for error case
5703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5704 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005705 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005706 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5708 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005709 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005710 dsl_binding[0].binding = 0;
5711 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005712 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005713 dsl_binding[1].binding = 1;
5714 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5715 dsl_binding[1].descriptorCount = 2;
5716 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5717 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005718 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005719 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005720 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5721 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005722 ASSERT_VK_SUCCESS(err);
5723 dsl_binding[0].binding = 0;
5724 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005725 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005726 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5728 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005729 ASSERT_VK_SUCCESS(err);
5730 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005731 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005732 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5733 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005734 ASSERT_VK_SUCCESS(err);
5735
5736 static const uint32_t NUM_SETS = 4;
5737 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5738 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005739 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005740 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005741 alloc_info.descriptorPool = ds_pool;
5742 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005743 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5744 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005745 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005746 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005747 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005748 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005749 err =
5750 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005751 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005752
5753 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005754 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5755 pipeline_layout_ci.pNext = NULL;
5756 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5757 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005758
5759 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005760 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5761 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005762 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005763 // Create pipelineLayout with only one setLayout
5764 pipeline_layout_ci.setLayoutCount = 1;
5765 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5767 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005768 ASSERT_VK_SUCCESS(err);
5769 // Create pipelineLayout with 2 descriptor setLayout at index 0
5770 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5771 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5773 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005774 ASSERT_VK_SUCCESS(err);
5775 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5776 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5777 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005778 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5779 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005780 ASSERT_VK_SUCCESS(err);
5781 // Create pipelineLayout with UB type, but stageFlags for FS only
5782 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5783 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5785 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005786 ASSERT_VK_SUCCESS(err);
5787 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5788 VkDescriptorSetLayout pl_bad_s0[2] = {};
5789 pl_bad_s0[0] = ds_layout_fs_only;
5790 pl_bad_s0[1] = ds_layout[1];
5791 pipeline_layout_ci.setLayoutCount = 2;
5792 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5793 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005794 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5795 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005796 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005797
5798 // Create a buffer to update the descriptor with
5799 uint32_t qfi = 0;
5800 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005801 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5802 buffCI.size = 1024;
5803 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5804 buffCI.queueFamilyIndexCount = 1;
5805 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005806
5807 VkBuffer dyub;
5808 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5809 ASSERT_VK_SUCCESS(err);
5810 // Correctly update descriptor to avoid "NOT_UPDATED" error
5811 static const uint32_t NUM_BUFFS = 5;
5812 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005813 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005814 buffInfo[i].buffer = dyub;
5815 buffInfo[i].offset = 0;
5816 buffInfo[i].range = 1024;
5817 }
Karl Schultz6addd812016-02-02 17:17:23 -07005818 VkImage image;
5819 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5820 const int32_t tex_width = 32;
5821 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005822 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5824 image_create_info.pNext = NULL;
5825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5826 image_create_info.format = tex_format;
5827 image_create_info.extent.width = tex_width;
5828 image_create_info.extent.height = tex_height;
5829 image_create_info.extent.depth = 1;
5830 image_create_info.mipLevels = 1;
5831 image_create_info.arrayLayers = 1;
5832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5833 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5835 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5837 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005838
Karl Schultz6addd812016-02-02 17:17:23 -07005839 VkMemoryRequirements memReqs;
5840 VkDeviceMemory imageMem;
5841 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005842 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005843 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5844 memAlloc.pNext = NULL;
5845 memAlloc.allocationSize = 0;
5846 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005847 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5848 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005849 pass =
5850 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005851 ASSERT_TRUE(pass);
5852 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5853 ASSERT_VK_SUCCESS(err);
5854 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5855 ASSERT_VK_SUCCESS(err);
5856
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005857 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005858 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5859 image_view_create_info.image = image;
5860 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5861 image_view_create_info.format = tex_format;
5862 image_view_create_info.subresourceRange.layerCount = 1;
5863 image_view_create_info.subresourceRange.baseMipLevel = 0;
5864 image_view_create_info.subresourceRange.levelCount = 1;
5865 image_view_create_info.subresourceRange.aspectMask =
5866 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005867
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005868 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005869 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5870 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005871 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005872 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005873 imageInfo[0].imageView = view;
5874 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5875 imageInfo[1].imageView = view;
5876 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005877 imageInfo[2].imageView = view;
5878 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5879 imageInfo[3].imageView = view;
5880 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005881
5882 static const uint32_t NUM_SET_UPDATES = 3;
5883 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5884 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5885 descriptor_write[0].dstSet = descriptorSet[0];
5886 descriptor_write[0].dstBinding = 0;
5887 descriptor_write[0].descriptorCount = 5;
5888 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5889 descriptor_write[0].pBufferInfo = buffInfo;
5890 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5891 descriptor_write[1].dstSet = descriptorSet[1];
5892 descriptor_write[1].dstBinding = 0;
5893 descriptor_write[1].descriptorCount = 2;
5894 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5895 descriptor_write[1].pImageInfo = imageInfo;
5896 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5897 descriptor_write[2].dstSet = descriptorSet[1];
5898 descriptor_write[2].dstBinding = 1;
5899 descriptor_write[2].descriptorCount = 2;
5900 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005901 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005902
5903 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005904
Tobin Ehlis88452832015-12-03 09:40:56 -07005905 // Create PSO to be used for draw-time errors below
5906 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005907 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005908 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005909 "out gl_PerVertex {\n"
5910 " vec4 gl_Position;\n"
5911 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005912 "void main(){\n"
5913 " gl_Position = vec4(1);\n"
5914 "}\n";
5915 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005916 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005917 "\n"
5918 "layout(location=0) out vec4 x;\n"
5919 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5920 "void main(){\n"
5921 " x = vec4(bar.y);\n"
5922 "}\n";
5923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005925 VkPipelineObj pipe(m_device);
5926 pipe.AddShader(&vs);
5927 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005928 pipe.AddColorAttachment();
5929 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005930
5931 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005932
Karl Schultz6addd812016-02-02 17:17:23 -07005933 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5934 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5935 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5936 // of PSO
5937 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5938 // cmd_pipeline.c
5939 // due to the fact that cmd_alloc_dset_data() has not been called in
5940 // cmd_bind_graphics_pipeline()
5941 // TODO : Want to cause various binding incompatibility issues here to test
5942 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005943 // First cause various verify_layout_compatibility() fails
5944 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005945 // verify_set_layout_compatibility fail cases:
5946 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5948 " due to: invalid VkPipelineLayout ");
5949 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5950 VK_PIPELINE_BIND_POINT_GRAPHICS,
5951 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5952 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005953 m_errorMonitor->VerifyFound();
5954
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005955 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5957 " attempting to bind set to index 1");
5958 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5959 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5960 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005961 m_errorMonitor->VerifyFound();
5962
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005963 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005964 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5965 // descriptors
5966 m_errorMonitor->SetDesiredFailureMsg(
5967 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005968 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005969 vkCmdBindDescriptorSets(
5970 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5971 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005972 m_errorMonitor->VerifyFound();
5973
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005974 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5975 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005976 m_errorMonitor->SetDesiredFailureMsg(
5977 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005978 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005979 vkCmdBindDescriptorSets(
5980 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5981 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005982 m_errorMonitor->VerifyFound();
5983
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005984 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5985 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005986 m_errorMonitor->SetDesiredFailureMsg(
5987 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005988 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005989 vkCmdBindDescriptorSets(
5990 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5991 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005992 m_errorMonitor->VerifyFound();
5993
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005994 // Cause INFO messages due to disturbing previously bound Sets
5995 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005996 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5997 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5998 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005999 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006000 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006001 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006002 " previously bound as set #0 was disturbed ");
6003 vkCmdBindDescriptorSets(
6004 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6005 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006006 m_errorMonitor->VerifyFound();
6007
Karl Schultz6addd812016-02-02 17:17:23 -07006008 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6009 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6010 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006011 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006013 " newly bound as set #0 so set #1 and "
6014 "any subsequent sets were disturbed ");
6015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6016 VK_PIPELINE_BIND_POINT_GRAPHICS,
6017 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006018 m_errorMonitor->VerifyFound();
6019
Tobin Ehlis88452832015-12-03 09:40:56 -07006020 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006021 // 1. Error due to not binding required set (we actually use same code as
6022 // above to disturb set0)
6023 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6024 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6025 2, &descriptorSet[0], 0, NULL);
6026 vkCmdBindDescriptorSets(
6027 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6028 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6029 m_errorMonitor->SetDesiredFailureMsg(
6030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6031 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006032 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006033 m_errorMonitor->VerifyFound();
6034
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006035 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006036 // 2. Error due to bound set not being compatible with PSO's
6037 // VkPipelineLayout (diff stageFlags in this case)
6038 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6039 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6040 2, &descriptorSet[0], 0, NULL);
6041 m_errorMonitor->SetDesiredFailureMsg(
6042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6043 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006044 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006045 m_errorMonitor->VerifyFound();
6046
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006047 // Remaining clean-up
6048 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006049 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006050 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6051 }
6052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006053 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6054 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006055 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006056 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006058 vkFreeMemory(m_device->device(), imageMem, NULL);
6059 vkDestroyImage(m_device->device(), image, NULL);
6060 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006061}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006062
Karl Schultz6addd812016-02-02 17:17:23 -07006063TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006064
Karl Schultz6addd812016-02-02 17:17:23 -07006065 m_errorMonitor->SetDesiredFailureMsg(
6066 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006067 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006068
6069 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006070 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006071 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006072 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006073
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006074 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006075}
6076
Karl Schultz6addd812016-02-02 17:17:23 -07006077TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6078 VkResult err;
6079 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006080
Karl Schultz6addd812016-02-02 17:17:23 -07006081 m_errorMonitor->SetDesiredFailureMsg(
6082 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006083 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006084
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006085 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006086
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006087 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006088 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006089 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006090 cmd.commandPool = m_commandPool;
6091 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006092 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006093
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006094 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006095 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006096
6097 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006098 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006099 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006100 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006101 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006102 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6103 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006104 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006105
6106 // The error should be caught by validation of the BeginCommandBuffer call
6107 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6108
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006109 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006110 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006111}
6112
Karl Schultz6addd812016-02-02 17:17:23 -07006113TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006114 // Cause error due to Begin while recording CB
6115 // Then cause 2 errors for attempting to reset CB w/o having
6116 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6117 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006119 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006120
6121 ASSERT_NO_FATAL_FAILURE(InitState());
6122
6123 // Calls AllocateCommandBuffers
6124 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6125
Karl Schultz6addd812016-02-02 17:17:23 -07006126 // Force the failure by setting the Renderpass and Framebuffer fields with
6127 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006128 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006129 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006130 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6131 cmd_buf_info.pNext = NULL;
6132 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006133 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006134
6135 // Begin CB to transition to recording state
6136 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6137 // Can't re-begin. This should trigger error
6138 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006139 m_errorMonitor->VerifyFound();
6140
Karl Schultz6addd812016-02-02 17:17:23 -07006141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6142 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006143 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6144 // Reset attempt will trigger error due to incorrect CommandPool state
6145 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006146 m_errorMonitor->VerifyFound();
6147
Karl Schultz6addd812016-02-02 17:17:23 -07006148 m_errorMonitor->SetDesiredFailureMsg(
6149 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6150 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006151 // Transition CB to RECORDED state
6152 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6153 // Now attempting to Begin will implicitly reset, which triggers error
6154 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006155 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006156}
6157
Karl Schultz6addd812016-02-02 17:17:23 -07006158TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006159 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006160 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006161
Karl Schultz6addd812016-02-02 17:17:23 -07006162 m_errorMonitor->SetDesiredFailureMsg(
6163 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006164 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6165
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006168
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006169 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006170 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6171 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006172
6173 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006174 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6175 ds_pool_ci.pNext = NULL;
6176 ds_pool_ci.maxSets = 1;
6177 ds_pool_ci.poolSizeCount = 1;
6178 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006179
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006180 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006181 err =
6182 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006183 ASSERT_VK_SUCCESS(err);
6184
Tony Barboureb254902015-07-15 12:50:33 -06006185 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006186 dsl_binding.binding = 0;
6187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6188 dsl_binding.descriptorCount = 1;
6189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6190 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006191
Tony Barboureb254902015-07-15 12:50:33 -06006192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6194 ds_layout_ci.pNext = NULL;
6195 ds_layout_ci.bindingCount = 1;
6196 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006197
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006198 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006199 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6200 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006201 ASSERT_VK_SUCCESS(err);
6202
6203 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006204 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006206 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006207 alloc_info.descriptorPool = ds_pool;
6208 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6210 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006211 ASSERT_VK_SUCCESS(err);
6212
Tony Barboureb254902015-07-15 12:50:33 -06006213 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006214 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6215 pipeline_layout_ci.setLayoutCount = 1;
6216 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006217
6218 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006219 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6220 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006221 ASSERT_VK_SUCCESS(err);
6222
Tobin Ehlise68360f2015-10-01 11:15:13 -06006223 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006224 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006225
6226 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006227 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6228 vp_state_ci.scissorCount = 1;
6229 vp_state_ci.pScissors = &sc;
6230 vp_state_ci.viewportCount = 1;
6231 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006232
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006233 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6234 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6235 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6236 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6237 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6238 rs_state_ci.depthClampEnable = VK_FALSE;
6239 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6240 rs_state_ci.depthBiasEnable = VK_FALSE;
6241
Tony Barboureb254902015-07-15 12:50:33 -06006242 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006243 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6244 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006245 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006246 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6247 gp_ci.layout = pipeline_layout;
6248 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006249
6250 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006251 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6252 pc_ci.initialDataSize = 0;
6253 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006254
6255 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006256 VkPipelineCache pipelineCache;
6257
Karl Schultz6addd812016-02-02 17:17:23 -07006258 err =
6259 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006260 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006261 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6262 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006263
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006264 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006265
Chia-I Wuf7458c52015-10-26 21:10:41 +08006266 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6267 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6268 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6269 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006270}
Tobin Ehlis912df022015-09-17 08:46:18 -06006271/*// TODO : This test should be good, but needs Tess support in compiler to run
6272TEST_F(VkLayerTest, InvalidPatchControlPoints)
6273{
6274 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006275 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006278 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6279primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006280
Tobin Ehlis912df022015-09-17 08:46:18 -06006281 ASSERT_NO_FATAL_FAILURE(InitState());
6282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006283
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006284 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006285 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006286 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006287
6288 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6289 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6290 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006291 ds_pool_ci.poolSizeCount = 1;
6292 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006293
6294 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006295 err = vkCreateDescriptorPool(m_device->device(),
6296VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006297 ASSERT_VK_SUCCESS(err);
6298
6299 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006300 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006301 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006302 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006303 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6304 dsl_binding.pImmutableSamplers = NULL;
6305
6306 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006307 ds_layout_ci.sType =
6308VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006309 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006310 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006311 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006312
6313 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006314 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6315&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006316 ASSERT_VK_SUCCESS(err);
6317
6318 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006319 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6320VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006321 ASSERT_VK_SUCCESS(err);
6322
6323 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006324 pipeline_layout_ci.sType =
6325VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006326 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006327 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006328 pipeline_layout_ci.pSetLayouts = &ds_layout;
6329
6330 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6332&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006333 ASSERT_VK_SUCCESS(err);
6334
6335 VkPipelineShaderStageCreateInfo shaderStages[3];
6336 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6337
Karl Schultz6addd812016-02-02 17:17:23 -07006338 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6339this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006340 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006341 VkShaderObj
6342tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6343this);
6344 VkShaderObj
6345te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6346this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006347
Karl Schultz6addd812016-02-02 17:17:23 -07006348 shaderStages[0].sType =
6349VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006350 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006351 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006352 shaderStages[1].sType =
6353VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006354 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006355 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006356 shaderStages[2].sType =
6357VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006358 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006359 shaderStages[2].shader = te.handle();
6360
6361 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006362 iaCI.sType =
6363VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006364 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006365
6366 VkPipelineTessellationStateCreateInfo tsCI = {};
6367 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6368 tsCI.patchControlPoints = 0; // This will cause an error
6369
6370 VkGraphicsPipelineCreateInfo gp_ci = {};
6371 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6372 gp_ci.pNext = NULL;
6373 gp_ci.stageCount = 3;
6374 gp_ci.pStages = shaderStages;
6375 gp_ci.pVertexInputState = NULL;
6376 gp_ci.pInputAssemblyState = &iaCI;
6377 gp_ci.pTessellationState = &tsCI;
6378 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006379 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006380 gp_ci.pMultisampleState = NULL;
6381 gp_ci.pDepthStencilState = NULL;
6382 gp_ci.pColorBlendState = NULL;
6383 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6384 gp_ci.layout = pipeline_layout;
6385 gp_ci.renderPass = renderPass();
6386
6387 VkPipelineCacheCreateInfo pc_ci = {};
6388 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6389 pc_ci.pNext = NULL;
6390 pc_ci.initialSize = 0;
6391 pc_ci.initialData = 0;
6392 pc_ci.maxSize = 0;
6393
6394 VkPipeline pipeline;
6395 VkPipelineCache pipelineCache;
6396
Karl Schultz6addd812016-02-02 17:17:23 -07006397 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6398&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006399 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6401&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006402
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006403 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006404
Chia-I Wuf7458c52015-10-26 21:10:41 +08006405 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6406 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6408 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006409}
6410*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006411// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006412TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006413 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006414
Karl Schultz6addd812016-02-02 17:17:23 -07006415 m_errorMonitor->SetDesiredFailureMsg(
6416 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006417 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6418
Tobin Ehlise68360f2015-10-01 11:15:13 -06006419 ASSERT_NO_FATAL_FAILURE(InitState());
6420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006421
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006422 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006423 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6424 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006425
6426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6428 ds_pool_ci.maxSets = 1;
6429 ds_pool_ci.poolSizeCount = 1;
6430 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006431
6432 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006433 err =
6434 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006435 ASSERT_VK_SUCCESS(err);
6436
6437 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006438 dsl_binding.binding = 0;
6439 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6440 dsl_binding.descriptorCount = 1;
6441 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006442
6443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6445 ds_layout_ci.bindingCount = 1;
6446 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006447
6448 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6450 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006451 ASSERT_VK_SUCCESS(err);
6452
6453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006457 alloc_info.descriptorPool = ds_pool;
6458 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6460 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006461 ASSERT_VK_SUCCESS(err);
6462
6463 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006464 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6465 pipeline_layout_ci.setLayoutCount = 1;
6466 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006467
6468 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006469 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6470 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006471 ASSERT_VK_SUCCESS(err);
6472
6473 VkViewport vp = {}; // Just need dummy vp to point to
6474
6475 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006476 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6477 vp_state_ci.scissorCount = 0;
6478 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6479 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006480
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006481 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6482 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6483 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6484 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6485 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6486 rs_state_ci.depthClampEnable = VK_FALSE;
6487 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6488 rs_state_ci.depthBiasEnable = VK_FALSE;
6489
Cody Northropeb3a6c12015-10-05 14:44:45 -06006490 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006491 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006492
Karl Schultz6addd812016-02-02 17:17:23 -07006493 VkShaderObj vs(m_device, bindStateVertShaderText,
6494 VK_SHADER_STAGE_VERTEX_BIT, this);
6495 VkShaderObj fs(m_device, bindStateFragShaderText,
6496 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006497 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006498 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006499 shaderStages[0] = vs.GetStageCreateInfo();
6500 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006501
6502 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006503 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6504 gp_ci.stageCount = 2;
6505 gp_ci.pStages = shaderStages;
6506 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006507 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006508 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6509 gp_ci.layout = pipeline_layout;
6510 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006511
6512 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006514
6515 VkPipeline pipeline;
6516 VkPipelineCache pipelineCache;
6517
Karl Schultz6addd812016-02-02 17:17:23 -07006518 err =
6519 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006520 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006521 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6522 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006524 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006525
Chia-I Wuf7458c52015-10-26 21:10:41 +08006526 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6527 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6528 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6529 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006530}
Karl Schultz6addd812016-02-02 17:17:23 -07006531// Don't set viewport state in PSO. This is an error b/c we always need this
6532// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006533// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006534TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006535 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006536 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006537
Karl Schultz6addd812016-02-02 17:17:23 -07006538 m_errorMonitor->SetDesiredFailureMsg(
6539 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006540 "Gfx Pipeline pViewportState is null. Even if ");
6541
Tobin Ehlise68360f2015-10-01 11:15:13 -06006542 ASSERT_NO_FATAL_FAILURE(InitState());
6543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006544
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006545 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006546 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6547 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006548
6549 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006550 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6551 ds_pool_ci.maxSets = 1;
6552 ds_pool_ci.poolSizeCount = 1;
6553 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006554
6555 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006556 err =
6557 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006558 ASSERT_VK_SUCCESS(err);
6559
6560 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006561 dsl_binding.binding = 0;
6562 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6563 dsl_binding.descriptorCount = 1;
6564 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006565
6566 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006567 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6568 ds_layout_ci.bindingCount = 1;
6569 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006570
6571 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006572 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6573 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006574 ASSERT_VK_SUCCESS(err);
6575
6576 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006577 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006579 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006580 alloc_info.descriptorPool = ds_pool;
6581 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6583 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006584 ASSERT_VK_SUCCESS(err);
6585
6586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006587 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6588 pipeline_layout_ci.setLayoutCount = 1;
6589 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006590
6591 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6593 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006594 ASSERT_VK_SUCCESS(err);
6595
6596 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6597 // Set scissor as dynamic to avoid second error
6598 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006599 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6600 dyn_state_ci.dynamicStateCount = 1;
6601 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006602
Cody Northropeb3a6c12015-10-05 14:44:45 -06006603 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006604 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006605
Karl Schultz6addd812016-02-02 17:17:23 -07006606 VkShaderObj vs(m_device, bindStateVertShaderText,
6607 VK_SHADER_STAGE_VERTEX_BIT, this);
6608 VkShaderObj fs(m_device, bindStateFragShaderText,
6609 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006610 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006611 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006612 shaderStages[0] = vs.GetStageCreateInfo();
6613 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006614
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006615
6616 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6617 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6618 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6619 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6620 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6621 rs_state_ci.depthClampEnable = VK_FALSE;
6622 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6623 rs_state_ci.depthBiasEnable = VK_FALSE;
6624
Tobin Ehlise68360f2015-10-01 11:15:13 -06006625 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006626 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6627 gp_ci.stageCount = 2;
6628 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006629 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006630 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6631 // should cause validation error
6632 gp_ci.pDynamicState = &dyn_state_ci;
6633 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6634 gp_ci.layout = pipeline_layout;
6635 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006636
6637 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006638 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006639
6640 VkPipeline pipeline;
6641 VkPipelineCache pipelineCache;
6642
Karl Schultz6addd812016-02-02 17:17:23 -07006643 err =
6644 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006645 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006646 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6647 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006648
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006650
Chia-I Wuf7458c52015-10-26 21:10:41 +08006651 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6652 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6653 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6654 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006655}
6656// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006657// Then run second test where dynamic scissor count doesn't match PSO scissor
6658// count
6659TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6660 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006661
Karl Schultz6addd812016-02-02 17:17:23 -07006662 m_errorMonitor->SetDesiredFailureMsg(
6663 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006664 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6665
Tobin Ehlise68360f2015-10-01 11:15:13 -06006666 ASSERT_NO_FATAL_FAILURE(InitState());
6667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006668
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006669 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006670 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6671 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006672
6673 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006674 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6675 ds_pool_ci.maxSets = 1;
6676 ds_pool_ci.poolSizeCount = 1;
6677 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006678
6679 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006680 err =
6681 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006682 ASSERT_VK_SUCCESS(err);
6683
6684 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 dsl_binding.binding = 0;
6686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6687 dsl_binding.descriptorCount = 1;
6688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006689
6690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6692 ds_layout_ci.bindingCount = 1;
6693 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006694
6695 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6697 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006698 ASSERT_VK_SUCCESS(err);
6699
6700 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006701 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006702 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006703 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006704 alloc_info.descriptorPool = ds_pool;
6705 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006706 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6707 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006708 ASSERT_VK_SUCCESS(err);
6709
6710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6712 pipeline_layout_ci.setLayoutCount = 1;
6713 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006714
6715 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006716 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6717 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006718 ASSERT_VK_SUCCESS(err);
6719
6720 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006721 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6722 vp_state_ci.viewportCount = 1;
6723 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6724 vp_state_ci.scissorCount = 1;
6725 vp_state_ci.pScissors =
6726 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006727
6728 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6729 // Set scissor as dynamic to avoid that error
6730 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006731 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6732 dyn_state_ci.dynamicStateCount = 1;
6733 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006734
Cody Northropeb3a6c12015-10-05 14:44:45 -06006735 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006736 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006737
Karl Schultz6addd812016-02-02 17:17:23 -07006738 VkShaderObj vs(m_device, bindStateVertShaderText,
6739 VK_SHADER_STAGE_VERTEX_BIT, this);
6740 VkShaderObj fs(m_device, bindStateFragShaderText,
6741 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006742 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006743 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006744 shaderStages[0] = vs.GetStageCreateInfo();
6745 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006746
Cody Northropf6622dc2015-10-06 10:33:21 -06006747 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6748 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6749 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006750 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006751 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006752 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006753 vi_ci.pVertexAttributeDescriptions = nullptr;
6754
6755 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6756 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6757 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6758
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006759 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006760 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006761 rs_ci.pNext = nullptr;
6762
Mark Youngc89c6312016-03-31 16:03:20 -06006763 VkPipelineColorBlendAttachmentState att = {};
6764 att.blendEnable = VK_FALSE;
6765 att.colorWriteMask = 0xf;
6766
Cody Northropf6622dc2015-10-06 10:33:21 -06006767 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6768 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6769 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006770 cb_ci.attachmentCount = 1;
6771 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006772
Tobin Ehlise68360f2015-10-01 11:15:13 -06006773 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006774 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6775 gp_ci.stageCount = 2;
6776 gp_ci.pStages = shaderStages;
6777 gp_ci.pVertexInputState = &vi_ci;
6778 gp_ci.pInputAssemblyState = &ia_ci;
6779 gp_ci.pViewportState = &vp_state_ci;
6780 gp_ci.pRasterizationState = &rs_ci;
6781 gp_ci.pColorBlendState = &cb_ci;
6782 gp_ci.pDynamicState = &dyn_state_ci;
6783 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6784 gp_ci.layout = pipeline_layout;
6785 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006786
6787 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006788 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006789
6790 VkPipeline pipeline;
6791 VkPipelineCache pipelineCache;
6792
Karl Schultz6addd812016-02-02 17:17:23 -07006793 err =
6794 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006795 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006796 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6797 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006799 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006800
Tobin Ehlisd332f282015-10-02 11:00:56 -06006801 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006802 // First need to successfully create the PSO from above by setting
6803 // pViewports
6804 m_errorMonitor->SetDesiredFailureMsg(
6805 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6806 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6807 "scissorCount is 1. These counts must match.");
6808
6809 VkViewport vp = {}; // Just need dummy vp to point to
6810 vp_state_ci.pViewports = &vp;
6811 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6812 &gp_ci, NULL, &pipeline);
6813 ASSERT_VK_SUCCESS(err);
6814 BeginCommandBuffer();
6815 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6816 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6817 VkRect2D scissors[2] = {}; // don't care about data
6818 // Count of 2 doesn't match PSO count of 1
6819 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6820 Draw(1, 0, 0, 0);
6821
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006822 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006823
6824 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6825 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006828 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006829}
6830// Create PSO w/o non-zero scissorCount but no scissor data
6831// Then run second test where dynamic viewportCount doesn't match PSO
6832// viewportCount
6833TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6834 VkResult err;
6835
6836 m_errorMonitor->SetDesiredFailureMsg(
6837 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6838 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6839
6840 ASSERT_NO_FATAL_FAILURE(InitState());
6841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6842
6843 VkDescriptorPoolSize ds_type_count = {};
6844 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6845 ds_type_count.descriptorCount = 1;
6846
6847 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6848 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6849 ds_pool_ci.maxSets = 1;
6850 ds_pool_ci.poolSizeCount = 1;
6851 ds_pool_ci.pPoolSizes = &ds_type_count;
6852
6853 VkDescriptorPool ds_pool;
6854 err =
6855 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6856 ASSERT_VK_SUCCESS(err);
6857
6858 VkDescriptorSetLayoutBinding dsl_binding = {};
6859 dsl_binding.binding = 0;
6860 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6861 dsl_binding.descriptorCount = 1;
6862 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6863
6864 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6865 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6866 ds_layout_ci.bindingCount = 1;
6867 ds_layout_ci.pBindings = &dsl_binding;
6868
6869 VkDescriptorSetLayout ds_layout;
6870 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6871 &ds_layout);
6872 ASSERT_VK_SUCCESS(err);
6873
6874 VkDescriptorSet descriptorSet;
6875 VkDescriptorSetAllocateInfo alloc_info = {};
6876 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6877 alloc_info.descriptorSetCount = 1;
6878 alloc_info.descriptorPool = ds_pool;
6879 alloc_info.pSetLayouts = &ds_layout;
6880 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6881 &descriptorSet);
6882 ASSERT_VK_SUCCESS(err);
6883
6884 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6885 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6886 pipeline_layout_ci.setLayoutCount = 1;
6887 pipeline_layout_ci.pSetLayouts = &ds_layout;
6888
6889 VkPipelineLayout pipeline_layout;
6890 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6891 &pipeline_layout);
6892 ASSERT_VK_SUCCESS(err);
6893
6894 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6895 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6896 vp_state_ci.scissorCount = 1;
6897 vp_state_ci.pScissors =
6898 NULL; // Null scissor w/ count of 1 should cause error
6899 vp_state_ci.viewportCount = 1;
6900 vp_state_ci.pViewports =
6901 NULL; // vp is dynamic (below) so this won't cause error
6902
6903 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6904 // Set scissor as dynamic to avoid that error
6905 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6906 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6907 dyn_state_ci.dynamicStateCount = 1;
6908 dyn_state_ci.pDynamicStates = &vp_state;
6909
6910 VkPipelineShaderStageCreateInfo shaderStages[2];
6911 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6912
6913 VkShaderObj vs(m_device, bindStateVertShaderText,
6914 VK_SHADER_STAGE_VERTEX_BIT, this);
6915 VkShaderObj fs(m_device, bindStateFragShaderText,
6916 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006917 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006918 // but add it to be able to run on more devices
6919 shaderStages[0] = vs.GetStageCreateInfo();
6920 shaderStages[1] = fs.GetStageCreateInfo();
6921
6922 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6923 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6924 vi_ci.pNext = nullptr;
6925 vi_ci.vertexBindingDescriptionCount = 0;
6926 vi_ci.pVertexBindingDescriptions = nullptr;
6927 vi_ci.vertexAttributeDescriptionCount = 0;
6928 vi_ci.pVertexAttributeDescriptions = nullptr;
6929
6930 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6931 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6932 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6933
6934 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6935 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6936 rs_ci.pNext = nullptr;
6937
Mark Youngc89c6312016-03-31 16:03:20 -06006938 VkPipelineColorBlendAttachmentState att = {};
6939 att.blendEnable = VK_FALSE;
6940 att.colorWriteMask = 0xf;
6941
Karl Schultz6addd812016-02-02 17:17:23 -07006942 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6943 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6944 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006945 cb_ci.attachmentCount = 1;
6946 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006947
6948 VkGraphicsPipelineCreateInfo gp_ci = {};
6949 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6950 gp_ci.stageCount = 2;
6951 gp_ci.pStages = shaderStages;
6952 gp_ci.pVertexInputState = &vi_ci;
6953 gp_ci.pInputAssemblyState = &ia_ci;
6954 gp_ci.pViewportState = &vp_state_ci;
6955 gp_ci.pRasterizationState = &rs_ci;
6956 gp_ci.pColorBlendState = &cb_ci;
6957 gp_ci.pDynamicState = &dyn_state_ci;
6958 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6959 gp_ci.layout = pipeline_layout;
6960 gp_ci.renderPass = renderPass();
6961
6962 VkPipelineCacheCreateInfo pc_ci = {};
6963 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6964
6965 VkPipeline pipeline;
6966 VkPipelineCache pipelineCache;
6967
6968 err =
6969 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6970 ASSERT_VK_SUCCESS(err);
6971 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6972 &gp_ci, NULL, &pipeline);
6973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006974 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006975
6976 // Now hit second fail case where we set scissor w/ different count than PSO
6977 // First need to successfully create the PSO from above by setting
6978 // pViewports
6979 m_errorMonitor->SetDesiredFailureMsg(
6980 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6981 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6982 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006983
Tobin Ehlisd332f282015-10-02 11:00:56 -06006984 VkRect2D sc = {}; // Just need dummy vp to point to
6985 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006986 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6987 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006988 ASSERT_VK_SUCCESS(err);
6989 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006990 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6991 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006992 VkViewport viewports[2] = {}; // don't care about data
6993 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006994 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006995 Draw(1, 0, 0, 0);
6996
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006997 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006998
Chia-I Wuf7458c52015-10-26 21:10:41 +08006999 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7001 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7002 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007003 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007004}
7005
Mark Young7394fdd2016-03-31 14:56:43 -06007006TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7007 VkResult err;
7008
7009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007010 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007011
7012 ASSERT_NO_FATAL_FAILURE(InitState());
7013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7014
7015 VkDescriptorPoolSize ds_type_count = {};
7016 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7017 ds_type_count.descriptorCount = 1;
7018
7019 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7020 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7021 ds_pool_ci.maxSets = 1;
7022 ds_pool_ci.poolSizeCount = 1;
7023 ds_pool_ci.pPoolSizes = &ds_type_count;
7024
7025 VkDescriptorPool ds_pool;
7026 err =
7027 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7028 ASSERT_VK_SUCCESS(err);
7029
7030 VkDescriptorSetLayoutBinding dsl_binding = {};
7031 dsl_binding.binding = 0;
7032 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7033 dsl_binding.descriptorCount = 1;
7034 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7035
7036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7038 ds_layout_ci.bindingCount = 1;
7039 ds_layout_ci.pBindings = &dsl_binding;
7040
7041 VkDescriptorSetLayout ds_layout;
7042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7043 &ds_layout);
7044 ASSERT_VK_SUCCESS(err);
7045
7046 VkDescriptorSet descriptorSet;
7047 VkDescriptorSetAllocateInfo alloc_info = {};
7048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7049 alloc_info.descriptorSetCount = 1;
7050 alloc_info.descriptorPool = ds_pool;
7051 alloc_info.pSetLayouts = &ds_layout;
7052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7053 &descriptorSet);
7054 ASSERT_VK_SUCCESS(err);
7055
7056 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7057 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7058 pipeline_layout_ci.setLayoutCount = 1;
7059 pipeline_layout_ci.pSetLayouts = &ds_layout;
7060
7061 VkPipelineLayout pipeline_layout;
7062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7063 &pipeline_layout);
7064 ASSERT_VK_SUCCESS(err);
7065
7066 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7067 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7068 vp_state_ci.scissorCount = 1;
7069 vp_state_ci.pScissors = NULL;
7070 vp_state_ci.viewportCount = 1;
7071 vp_state_ci.pViewports = NULL;
7072
7073 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7074 VK_DYNAMIC_STATE_SCISSOR,
7075 VK_DYNAMIC_STATE_LINE_WIDTH};
7076 // Set scissor as dynamic to avoid that error
7077 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7078 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7079 dyn_state_ci.dynamicStateCount = 2;
7080 dyn_state_ci.pDynamicStates = dynamic_states;
7081
7082 VkPipelineShaderStageCreateInfo shaderStages[2];
7083 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7084
7085 VkShaderObj vs(m_device, bindStateVertShaderText,
7086 VK_SHADER_STAGE_VERTEX_BIT, this);
7087 VkShaderObj fs(m_device, bindStateFragShaderText,
7088 VK_SHADER_STAGE_FRAGMENT_BIT,
7089 this); // TODO - We shouldn't need a fragment shader
7090 // but add it to be able to run on more devices
7091 shaderStages[0] = vs.GetStageCreateInfo();
7092 shaderStages[1] = fs.GetStageCreateInfo();
7093
7094 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7095 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7096 vi_ci.pNext = nullptr;
7097 vi_ci.vertexBindingDescriptionCount = 0;
7098 vi_ci.pVertexBindingDescriptions = nullptr;
7099 vi_ci.vertexAttributeDescriptionCount = 0;
7100 vi_ci.pVertexAttributeDescriptions = nullptr;
7101
7102 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7103 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7104 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7105
7106 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7107 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7108 rs_ci.pNext = nullptr;
7109
Mark Young47107952016-05-02 15:59:55 -06007110 // Check too low (line width of -1.0f).
7111 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007112
7113 VkPipelineColorBlendAttachmentState att = {};
7114 att.blendEnable = VK_FALSE;
7115 att.colorWriteMask = 0xf;
7116
7117 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7118 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7119 cb_ci.pNext = nullptr;
7120 cb_ci.attachmentCount = 1;
7121 cb_ci.pAttachments = &att;
7122
7123 VkGraphicsPipelineCreateInfo gp_ci = {};
7124 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7125 gp_ci.stageCount = 2;
7126 gp_ci.pStages = shaderStages;
7127 gp_ci.pVertexInputState = &vi_ci;
7128 gp_ci.pInputAssemblyState = &ia_ci;
7129 gp_ci.pViewportState = &vp_state_ci;
7130 gp_ci.pRasterizationState = &rs_ci;
7131 gp_ci.pColorBlendState = &cb_ci;
7132 gp_ci.pDynamicState = &dyn_state_ci;
7133 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7134 gp_ci.layout = pipeline_layout;
7135 gp_ci.renderPass = renderPass();
7136
7137 VkPipelineCacheCreateInfo pc_ci = {};
7138 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7139
7140 VkPipeline pipeline;
7141 VkPipelineCache pipelineCache;
7142
7143 err =
7144 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7145 ASSERT_VK_SUCCESS(err);
7146 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7147 &gp_ci, NULL, &pipeline);
7148
7149 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007151
7152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7153 "Attempt to set lineWidth to 65536");
7154
7155 // Check too high (line width of 65536.0f).
7156 rs_ci.lineWidth = 65536.0f;
7157
7158 err =
7159 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7160 ASSERT_VK_SUCCESS(err);
7161 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7162 &gp_ci, NULL, &pipeline);
7163
7164 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007165 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007166
7167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007168 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007169
7170 dyn_state_ci.dynamicStateCount = 3;
7171
7172 rs_ci.lineWidth = 1.0f;
7173
7174 err =
7175 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7176 ASSERT_VK_SUCCESS(err);
7177 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7178 &gp_ci, NULL, &pipeline);
7179 BeginCommandBuffer();
7180 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7181 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7182
7183 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007184 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007185 m_errorMonitor->VerifyFound();
7186
7187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7188 "Attempt to set lineWidth to 65536");
7189
7190 // Check too high with dynamic setting.
7191 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7192 m_errorMonitor->VerifyFound();
7193 EndCommandBuffer();
7194
7195 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7196 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7198 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007199 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007200}
7201
Karl Schultz6addd812016-02-02 17:17:23 -07007202TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007203 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007204 m_errorMonitor->SetDesiredFailureMsg(
7205 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007206 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007207
7208 ASSERT_NO_FATAL_FAILURE(InitState());
7209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007210
Tony Barbourfe3351b2015-07-28 10:17:20 -06007211 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007212 // Don't care about RenderPass handle b/c error should be flagged before
7213 // that
7214 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7215 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007216
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007217 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007218}
7219
Karl Schultz6addd812016-02-02 17:17:23 -07007220TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007221 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007222 m_errorMonitor->SetDesiredFailureMsg(
7223 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007224 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007225
7226 ASSERT_NO_FATAL_FAILURE(InitState());
7227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007228
Tony Barbourfe3351b2015-07-28 10:17:20 -06007229 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007230 // Just create a dummy Renderpass that's non-NULL so we can get to the
7231 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007232 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007233 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7234 rp_begin.pNext = NULL;
7235 rp_begin.renderPass = renderPass();
7236 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007237
Karl Schultz6addd812016-02-02 17:17:23 -07007238 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7239 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007240
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007241 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007242}
7243
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007244TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7245 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7246 "the number of renderPass attachments that use loadOp"
7247 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7248
7249 ASSERT_NO_FATAL_FAILURE(InitState());
7250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7251
7252 // Create a renderPass with a single attachment that uses loadOp CLEAR
7253 VkAttachmentReference attach = {};
7254 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7255 VkSubpassDescription subpass = {};
7256 subpass.inputAttachmentCount = 1;
7257 subpass.pInputAttachments = &attach;
7258 VkRenderPassCreateInfo rpci = {};
7259 rpci.subpassCount = 1;
7260 rpci.pSubpasses = &subpass;
7261 rpci.attachmentCount = 1;
7262 VkAttachmentDescription attach_desc = {};
7263 attach_desc.format = VK_FORMAT_UNDEFINED;
7264 // Set loadOp to CLEAR
7265 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7266 rpci.pAttachments = &attach_desc;
7267 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7268 VkRenderPass rp;
7269 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7270
7271 VkCommandBufferInheritanceInfo hinfo = {};
7272 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7273 hinfo.renderPass = VK_NULL_HANDLE;
7274 hinfo.subpass = 0;
7275 hinfo.framebuffer = VK_NULL_HANDLE;
7276 hinfo.occlusionQueryEnable = VK_FALSE;
7277 hinfo.queryFlags = 0;
7278 hinfo.pipelineStatistics = 0;
7279 VkCommandBufferBeginInfo info = {};
7280 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7281 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7282 info.pInheritanceInfo = &hinfo;
7283
7284 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7285 VkRenderPassBeginInfo rp_begin = {};
7286 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7287 rp_begin.pNext = NULL;
7288 rp_begin.renderPass = renderPass();
7289 rp_begin.framebuffer = framebuffer();
7290 rp_begin.clearValueCount = 0; // Should be 1
7291
7292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7293 " has a clearValueCount of 0 but the "
7294 "actual number of attachments in "
7295 "renderPass ");
7296
7297 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7298 VK_SUBPASS_CONTENTS_INLINE);
7299
7300 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007301
7302 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007303}
7304
Cody Northrop3bb4d962016-05-09 16:15:57 -06007305TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7306
7307 TEST_DESCRIPTION("End a command buffer with an active render pass");
7308
7309 m_errorMonitor->SetDesiredFailureMsg(
7310 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7311 "It is invalid to issue this call inside an active render pass");
7312
7313 ASSERT_NO_FATAL_FAILURE(InitState());
7314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7315
7316 // The framework's BeginCommandBuffer calls CreateRenderPass
7317 BeginCommandBuffer();
7318
7319 // Call directly into vkEndCommandBuffer instead of the
7320 // the framework's EndCommandBuffer, which inserts a
7321 // vkEndRenderPass
7322 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7323
7324 m_errorMonitor->VerifyFound();
7325
7326 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7327 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7328}
7329
Karl Schultz6addd812016-02-02 17:17:23 -07007330TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007331 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007332 m_errorMonitor->SetDesiredFailureMsg(
7333 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007334 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007335
7336 ASSERT_NO_FATAL_FAILURE(InitState());
7337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007338
7339 // Renderpass is started here
7340 BeginCommandBuffer();
7341
7342 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 vk_testing::Buffer dstBuffer;
7344 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007345
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007347
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007348 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007349}
7350
Karl Schultz6addd812016-02-02 17:17:23 -07007351TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007352 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007353 m_errorMonitor->SetDesiredFailureMsg(
7354 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007355 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007356
7357 ASSERT_NO_FATAL_FAILURE(InitState());
7358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007359
7360 // Renderpass is started here
7361 BeginCommandBuffer();
7362
7363 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007364 vk_testing::Buffer dstBuffer;
7365 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007366
Karl Schultz6addd812016-02-02 17:17:23 -07007367 VkDeviceSize dstOffset = 0;
7368 VkDeviceSize dataSize = 1024;
7369 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007370
Karl Schultz6addd812016-02-02 17:17:23 -07007371 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7372 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007373
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007374 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007375}
7376
Karl Schultz6addd812016-02-02 17:17:23 -07007377TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007378 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007379 m_errorMonitor->SetDesiredFailureMsg(
7380 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007381 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007382
7383 ASSERT_NO_FATAL_FAILURE(InitState());
7384 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007385
7386 // Renderpass is started here
7387 BeginCommandBuffer();
7388
Michael Lentine0a369f62016-02-03 16:51:46 -06007389 VkClearColorValue clear_color;
7390 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007391 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7392 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7393 const int32_t tex_width = 32;
7394 const int32_t tex_height = 32;
7395 VkImageCreateInfo image_create_info = {};
7396 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7397 image_create_info.pNext = NULL;
7398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7399 image_create_info.format = tex_format;
7400 image_create_info.extent.width = tex_width;
7401 image_create_info.extent.height = tex_height;
7402 image_create_info.extent.depth = 1;
7403 image_create_info.mipLevels = 1;
7404 image_create_info.arrayLayers = 1;
7405 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7406 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7407 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007408
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007409 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007410 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7411 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007412
Karl Schultz6addd812016-02-02 17:17:23 -07007413 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7414 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007415
Karl Schultz6addd812016-02-02 17:17:23 -07007416 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7417 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007418
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007419 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007420}
7421
Karl Schultz6addd812016-02-02 17:17:23 -07007422TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007423 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007424 m_errorMonitor->SetDesiredFailureMsg(
7425 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007426 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007427
7428 ASSERT_NO_FATAL_FAILURE(InitState());
7429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007430
7431 // Renderpass is started here
7432 BeginCommandBuffer();
7433
7434 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007435 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007436 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7437 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7438 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7439 image_create_info.extent.width = 64;
7440 image_create_info.extent.height = 64;
7441 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7442 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007443
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007444 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007445 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7446 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007447
Karl Schultz6addd812016-02-02 17:17:23 -07007448 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7449 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007450
Karl Schultz6addd812016-02-02 17:17:23 -07007451 vkCmdClearDepthStencilImage(
7452 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7453 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7454 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007456 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007457}
7458
Karl Schultz6addd812016-02-02 17:17:23 -07007459TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007460 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007461 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007462
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007464 "vkCmdClearAttachments: This call "
7465 "must be issued inside an active "
7466 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007467
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007468 ASSERT_NO_FATAL_FAILURE(InitState());
7469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007470
7471 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007472 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007473 ASSERT_VK_SUCCESS(err);
7474
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007475 VkClearAttachment color_attachment;
7476 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7477 color_attachment.clearValue.color.float32[0] = 0;
7478 color_attachment.clearValue.color.float32[1] = 0;
7479 color_attachment.clearValue.color.float32[2] = 0;
7480 color_attachment.clearValue.color.float32[3] = 0;
7481 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007482 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7483 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7484 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007485
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007486 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007487}
7488
Karl Schultz9e66a292016-04-21 15:57:51 -06007489TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7490 // Try to add a buffer memory barrier with no buffer.
7491 m_errorMonitor->SetDesiredFailureMsg(
7492 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7493 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7494
7495 ASSERT_NO_FATAL_FAILURE(InitState());
7496 BeginCommandBuffer();
7497
7498 VkBufferMemoryBarrier buf_barrier = {};
7499 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7500 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7501 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7502 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7503 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7504 buf_barrier.buffer = VK_NULL_HANDLE;
7505 buf_barrier.offset = 0;
7506 buf_barrier.size = VK_WHOLE_SIZE;
7507 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7508 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7509 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7510
7511 m_errorMonitor->VerifyFound();
7512}
7513
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007514TEST_F(VkLayerTest, InvalidBarriers) {
7515 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7516
7517 m_errorMonitor->SetDesiredFailureMsg(
7518 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7519
7520 ASSERT_NO_FATAL_FAILURE(InitState());
7521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7522
7523 VkMemoryBarrier mem_barrier = {};
7524 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7525 mem_barrier.pNext = NULL;
7526 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7527 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7528 BeginCommandBuffer();
7529 // BeginCommandBuffer() starts a render pass
7530 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7531 VK_PIPELINE_STAGE_HOST_BIT,
7532 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7533 &mem_barrier, 0, nullptr, 0, nullptr);
7534 m_errorMonitor->VerifyFound();
7535
7536 m_errorMonitor->SetDesiredFailureMsg(
7537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7538 "Image Layout cannot be transitioned to UNDEFINED");
7539 VkImageObj image(m_device);
7540 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7541 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7542 ASSERT_TRUE(image.initialized());
7543 VkImageMemoryBarrier img_barrier = {};
7544 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7545 img_barrier.pNext = NULL;
7546 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7547 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7548 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7549 // New layout can't be UNDEFINED
7550 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7551 img_barrier.image = image.handle();
7552 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7553 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7554 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7555 img_barrier.subresourceRange.baseArrayLayer = 0;
7556 img_barrier.subresourceRange.baseMipLevel = 0;
7557 img_barrier.subresourceRange.layerCount = 1;
7558 img_barrier.subresourceRange.levelCount = 1;
7559 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7560 VK_PIPELINE_STAGE_HOST_BIT,
7561 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7562 nullptr, 1, &img_barrier);
7563 m_errorMonitor->VerifyFound();
7564 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7565
7566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7567 "Subresource must have the sum of the "
7568 "baseArrayLayer");
7569 // baseArrayLayer + layerCount must be <= image's arrayLayers
7570 img_barrier.subresourceRange.baseArrayLayer = 1;
7571 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7572 VK_PIPELINE_STAGE_HOST_BIT,
7573 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7574 nullptr, 1, &img_barrier);
7575 m_errorMonitor->VerifyFound();
7576 img_barrier.subresourceRange.baseArrayLayer = 0;
7577
7578 m_errorMonitor->SetDesiredFailureMsg(
7579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7580 "Subresource must have the sum of the baseMipLevel");
7581 // baseMipLevel + levelCount must be <= image's mipLevels
7582 img_barrier.subresourceRange.baseMipLevel = 1;
7583 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7584 VK_PIPELINE_STAGE_HOST_BIT,
7585 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7586 nullptr, 1, &img_barrier);
7587 m_errorMonitor->VerifyFound();
7588 img_barrier.subresourceRange.baseMipLevel = 0;
7589
7590 m_errorMonitor->SetDesiredFailureMsg(
7591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7592 "Buffer Barriers cannot be used during a render pass");
7593 vk_testing::Buffer buffer;
7594 buffer.init(*m_device, 256);
7595 VkBufferMemoryBarrier buf_barrier = {};
7596 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7597 buf_barrier.pNext = NULL;
7598 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7599 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7600 buf_barrier.buffer = buffer.handle();
7601 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7602 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7603 buf_barrier.offset = 0;
7604 buf_barrier.size = VK_WHOLE_SIZE;
7605 // Can't send buffer barrier during a render pass
7606 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7607 VK_PIPELINE_STAGE_HOST_BIT,
7608 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7609 &buf_barrier, 0, nullptr);
7610 m_errorMonitor->VerifyFound();
7611 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7612
7613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7614 "which is not less than total size");
7615 buf_barrier.offset = 257;
7616 // Offset greater than total size
7617 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7618 VK_PIPELINE_STAGE_HOST_BIT,
7619 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7620 &buf_barrier, 0, nullptr);
7621 m_errorMonitor->VerifyFound();
7622 buf_barrier.offset = 0;
7623
7624 m_errorMonitor->SetDesiredFailureMsg(
7625 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7626 buf_barrier.size = 257;
7627 // Size greater than total size
7628 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7629 VK_PIPELINE_STAGE_HOST_BIT,
7630 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7631 &buf_barrier, 0, nullptr);
7632 m_errorMonitor->VerifyFound();
7633 buf_barrier.size = VK_WHOLE_SIZE;
7634
7635 m_errorMonitor->SetDesiredFailureMsg(
7636 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7637 "Image is a depth and stencil format and thus must "
7638 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7639 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7640 VkDepthStencilObj ds_image(m_device);
7641 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7642 ASSERT_TRUE(ds_image.initialized());
7643 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7644 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7645 img_barrier.image = ds_image.handle();
7646 // Leave aspectMask at COLOR on purpose
7647 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7648 VK_PIPELINE_STAGE_HOST_BIT,
7649 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7650 nullptr, 1, &img_barrier);
7651 m_errorMonitor->VerifyFound();
7652}
7653
Karl Schultz6addd812016-02-02 17:17:23 -07007654TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007655 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007656 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007657
Karl Schultz6addd812016-02-02 17:17:23 -07007658 m_errorMonitor->SetDesiredFailureMsg(
7659 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007660 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7661
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007662 ASSERT_NO_FATAL_FAILURE(InitState());
7663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007664 uint32_t qfi = 0;
7665 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007666 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7667 buffCI.size = 1024;
7668 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7669 buffCI.queueFamilyIndexCount = 1;
7670 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007671
7672 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007673 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007674 ASSERT_VK_SUCCESS(err);
7675
7676 BeginCommandBuffer();
7677 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007678 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7679 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007680 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007681 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7682 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007683
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007684 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007685
Chia-I Wuf7458c52015-10-26 21:10:41 +08007686 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007687}
7688
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007689TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7690 // Create an out-of-range queueFamilyIndex
7691 m_errorMonitor->SetDesiredFailureMsg(
7692 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007693 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7694 "of the indices specified when the device was created, via the "
7695 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007696
7697 ASSERT_NO_FATAL_FAILURE(InitState());
7698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7699 VkBufferCreateInfo buffCI = {};
7700 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7701 buffCI.size = 1024;
7702 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7703 buffCI.queueFamilyIndexCount = 1;
7704 // Introduce failure by specifying invalid queue_family_index
7705 uint32_t qfi = 777;
7706 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007707 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007708
7709 VkBuffer ib;
7710 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007712 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007713 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007714}
7715
Karl Schultz6addd812016-02-02 17:17:23 -07007716TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7717 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7718 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007719
Karl Schultz6addd812016-02-02 17:17:23 -07007720 m_errorMonitor->SetDesiredFailureMsg(
7721 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007722 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007723
7724 ASSERT_NO_FATAL_FAILURE(InitState());
7725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007726
7727 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007728 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007729 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7730 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007731
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007732 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007733}
7734
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007735TEST_F(VkLayerTest, DSUsageBitsErrors) {
7736 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7737 "that do not have correct usage bits sets.");
7738 VkResult err;
7739
7740 ASSERT_NO_FATAL_FAILURE(InitState());
7741 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7742 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7743 ds_type_count[i].type = VkDescriptorType(i);
7744 ds_type_count[i].descriptorCount = 1;
7745 }
7746 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7747 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7748 ds_pool_ci.pNext = NULL;
7749 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7750 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7751 ds_pool_ci.pPoolSizes = ds_type_count;
7752
7753 VkDescriptorPool ds_pool;
7754 err =
7755 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7756 ASSERT_VK_SUCCESS(err);
7757
7758 // Create 10 layouts where each has a single descriptor of different type
7759 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7760 {};
7761 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7762 dsl_binding[i].binding = 0;
7763 dsl_binding[i].descriptorType = VkDescriptorType(i);
7764 dsl_binding[i].descriptorCount = 1;
7765 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7766 dsl_binding[i].pImmutableSamplers = NULL;
7767 }
7768
7769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7771 ds_layout_ci.pNext = NULL;
7772 ds_layout_ci.bindingCount = 1;
7773 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7774 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7775 ds_layout_ci.pBindings = dsl_binding + i;
7776 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7777 NULL, ds_layouts + i);
7778 ASSERT_VK_SUCCESS(err);
7779 }
7780 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7781 VkDescriptorSetAllocateInfo alloc_info = {};
7782 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7783 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7784 alloc_info.descriptorPool = ds_pool;
7785 alloc_info.pSetLayouts = ds_layouts;
7786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7787 descriptor_sets);
7788 ASSERT_VK_SUCCESS(err);
7789
7790 // Create a buffer & bufferView to be used for invalid updates
7791 VkBufferCreateInfo buff_ci = {};
7792 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7793 // This usage is not valid for any descriptor type
7794 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7795 buff_ci.size = 256;
7796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7797 VkBuffer buffer;
7798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7799 ASSERT_VK_SUCCESS(err);
7800
7801 VkBufferViewCreateInfo buff_view_ci = {};
7802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7803 buff_view_ci.buffer = buffer;
7804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7805 buff_view_ci.range = VK_WHOLE_SIZE;
7806 VkBufferView buff_view;
7807 err =
7808 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7809 ASSERT_VK_SUCCESS(err);
7810
7811 // Create an image to be used for invalid updates
7812 VkImageCreateInfo image_ci = {};
7813 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7814 image_ci.imageType = VK_IMAGE_TYPE_2D;
7815 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7816 image_ci.extent.width = 64;
7817 image_ci.extent.height = 64;
7818 image_ci.extent.depth = 1;
7819 image_ci.mipLevels = 1;
7820 image_ci.arrayLayers = 1;
7821 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7822 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7823 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7824 // This usage is not valid for any descriptor type
7825 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7826 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7827 VkImage image;
7828 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7829 ASSERT_VK_SUCCESS(err);
7830 // Bind memory to image
7831 VkMemoryRequirements mem_reqs;
7832 VkDeviceMemory image_mem;
7833 bool pass;
7834 VkMemoryAllocateInfo mem_alloc = {};
7835 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7836 mem_alloc.pNext = NULL;
7837 mem_alloc.allocationSize = 0;
7838 mem_alloc.memoryTypeIndex = 0;
7839 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7840 mem_alloc.allocationSize = mem_reqs.size;
7841 pass =
7842 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7843 ASSERT_TRUE(pass);
7844 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7845 ASSERT_VK_SUCCESS(err);
7846 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7847 ASSERT_VK_SUCCESS(err);
7848 // Now create view for image
7849 VkImageViewCreateInfo image_view_ci = {};
7850 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7851 image_view_ci.image = image;
7852 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7853 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7854 image_view_ci.subresourceRange.layerCount = 1;
7855 image_view_ci.subresourceRange.baseArrayLayer = 0;
7856 image_view_ci.subresourceRange.levelCount = 1;
7857 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7858 VkImageView image_view;
7859 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7860 &image_view);
7861 ASSERT_VK_SUCCESS(err);
7862
7863 VkDescriptorBufferInfo buff_info = {};
7864 buff_info.buffer = buffer;
7865 VkDescriptorImageInfo img_info = {};
7866 img_info.imageView = image_view;
7867 VkWriteDescriptorSet descriptor_write = {};
7868 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7869 descriptor_write.dstBinding = 0;
7870 descriptor_write.descriptorCount = 1;
7871 descriptor_write.pTexelBufferView = &buff_view;
7872 descriptor_write.pBufferInfo = &buff_info;
7873 descriptor_write.pImageInfo = &img_info;
7874
7875 // These error messages align with VkDescriptorType struct
7876 const char *error_msgs[] = {
7877 "", // placeholder, no error for SAMPLER descriptor
7878 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7879 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7880 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7881 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7882 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7883 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7884 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7885 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7886 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7887 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7888 // Start loop at 1 as SAMPLER desc type has no usage bit error
7889 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7890 descriptor_write.descriptorType = VkDescriptorType(i);
7891 descriptor_write.dstSet = descriptor_sets[i];
7892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7893 error_msgs[i]);
7894
7895 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7896 NULL);
7897
7898 m_errorMonitor->VerifyFound();
7899 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7900 }
7901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7902 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007903 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007904 vkDestroyImageView(m_device->device(), image_view, NULL);
7905 vkDestroyBuffer(m_device->device(), buffer, NULL);
7906 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7907 vkFreeDescriptorSets(m_device->device(), ds_pool,
7908 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7909 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7910}
7911
Karl Schultz6addd812016-02-02 17:17:23 -07007912TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007913 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07007914 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007915
Karl Schultz6addd812016-02-02 17:17:23 -07007916 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007917 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7918 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
7919 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007920
Tobin Ehlis3b780662015-05-28 12:11:26 -06007921 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007922 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007923 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007924 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7925 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007926
7927 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007928 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7929 ds_pool_ci.pNext = NULL;
7930 ds_pool_ci.maxSets = 1;
7931 ds_pool_ci.poolSizeCount = 1;
7932 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007933
Tobin Ehlis3b780662015-05-28 12:11:26 -06007934 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007935 err =
7936 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007937 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007938 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007939 dsl_binding.binding = 0;
7940 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7941 dsl_binding.descriptorCount = 1;
7942 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7943 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007944
Tony Barboureb254902015-07-15 12:50:33 -06007945 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007946 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7947 ds_layout_ci.pNext = NULL;
7948 ds_layout_ci.bindingCount = 1;
7949 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007950
Tobin Ehlis3b780662015-05-28 12:11:26 -06007951 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007952 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7953 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007954 ASSERT_VK_SUCCESS(err);
7955
7956 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007957 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007958 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007959 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007960 alloc_info.descriptorPool = ds_pool;
7961 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007962 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7963 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007964 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007965
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007966 VkSamplerCreateInfo sampler_ci = {};
7967 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7968 sampler_ci.pNext = NULL;
7969 sampler_ci.magFilter = VK_FILTER_NEAREST;
7970 sampler_ci.minFilter = VK_FILTER_NEAREST;
7971 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7972 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7973 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7974 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7975 sampler_ci.mipLodBias = 1.0;
7976 sampler_ci.anisotropyEnable = VK_FALSE;
7977 sampler_ci.maxAnisotropy = 1;
7978 sampler_ci.compareEnable = VK_FALSE;
7979 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7980 sampler_ci.minLod = 1.0;
7981 sampler_ci.maxLod = 1.0;
7982 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7983 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7984 VkSampler sampler;
7985 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7986 ASSERT_VK_SUCCESS(err);
7987
7988 VkDescriptorImageInfo info = {};
7989 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007990
7991 VkWriteDescriptorSet descriptor_write;
7992 memset(&descriptor_write, 0, sizeof(descriptor_write));
7993 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007994 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007995 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007996 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007997 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007998 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007999
8000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8001
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008002 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008003
Chia-I Wuf7458c52015-10-26 21:10:41 +08008004 vkDestroySampler(m_device->device(), sampler, NULL);
8005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008007}
8008
Karl Schultz6addd812016-02-02 17:17:23 -07008009TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008010 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008011 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008012
Karl Schultz6addd812016-02-02 17:17:23 -07008013 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008014 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8015 " binding #0 with 1 total descriptors but update of 1 descriptors "
8016 "starting at binding offset of 0 combined with update array element "
8017 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008018
Tobin Ehlis3b780662015-05-28 12:11:26 -06008019 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008020 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008021 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8023 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008024
8025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8027 ds_pool_ci.pNext = NULL;
8028 ds_pool_ci.maxSets = 1;
8029 ds_pool_ci.poolSizeCount = 1;
8030 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008031
Tobin Ehlis3b780662015-05-28 12:11:26 -06008032 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008033 err =
8034 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008035 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008036
Tony Barboureb254902015-07-15 12:50:33 -06008037 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008038 dsl_binding.binding = 0;
8039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8040 dsl_binding.descriptorCount = 1;
8041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8042 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008043
8044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8046 ds_layout_ci.pNext = NULL;
8047 ds_layout_ci.bindingCount = 1;
8048 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008049
Tobin Ehlis3b780662015-05-28 12:11:26 -06008050 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008051 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8052 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008053 ASSERT_VK_SUCCESS(err);
8054
8055 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008056 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008057 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008058 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008059 alloc_info.descriptorPool = ds_pool;
8060 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008061 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8062 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008063 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008064
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008065 // Correctly update descriptor to avoid "NOT_UPDATED" error
8066 VkDescriptorBufferInfo buff_info = {};
8067 buff_info.buffer =
8068 VkBuffer(0); // Don't care about buffer handle for this test
8069 buff_info.offset = 0;
8070 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008071
8072 VkWriteDescriptorSet descriptor_write;
8073 memset(&descriptor_write, 0, sizeof(descriptor_write));
8074 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008075 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008076 descriptor_write.dstArrayElement =
8077 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008078 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008079 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8080 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008081
8082 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8083
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008084 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008085
Chia-I Wuf7458c52015-10-26 21:10:41 +08008086 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8087 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008088}
8089
Karl Schultz6addd812016-02-02 17:17:23 -07008090TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8091 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8092 // index 2
8093 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008094
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8096 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008097
Tobin Ehlis3b780662015-05-28 12:11:26 -06008098 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008099 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008100 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008101 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8102 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008103
8104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8106 ds_pool_ci.pNext = NULL;
8107 ds_pool_ci.maxSets = 1;
8108 ds_pool_ci.poolSizeCount = 1;
8109 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008110
Tobin Ehlis3b780662015-05-28 12:11:26 -06008111 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008112 err =
8113 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008114 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008115
Tony Barboureb254902015-07-15 12:50:33 -06008116 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008117 dsl_binding.binding = 0;
8118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8119 dsl_binding.descriptorCount = 1;
8120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8121 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008122
8123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8125 ds_layout_ci.pNext = NULL;
8126 ds_layout_ci.bindingCount = 1;
8127 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008128 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8130 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008131 ASSERT_VK_SUCCESS(err);
8132
8133 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008134 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008135 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008136 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008137 alloc_info.descriptorPool = ds_pool;
8138 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008139 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8140 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008141 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008142
Tony Barboureb254902015-07-15 12:50:33 -06008143 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008144 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8145 sampler_ci.pNext = NULL;
8146 sampler_ci.magFilter = VK_FILTER_NEAREST;
8147 sampler_ci.minFilter = VK_FILTER_NEAREST;
8148 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8149 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8150 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8151 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8152 sampler_ci.mipLodBias = 1.0;
8153 sampler_ci.anisotropyEnable = VK_FALSE;
8154 sampler_ci.maxAnisotropy = 1;
8155 sampler_ci.compareEnable = VK_FALSE;
8156 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8157 sampler_ci.minLod = 1.0;
8158 sampler_ci.maxLod = 1.0;
8159 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8160 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008161
Tobin Ehlis3b780662015-05-28 12:11:26 -06008162 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008163 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008164 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008165
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008166 VkDescriptorImageInfo info = {};
8167 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008168
8169 VkWriteDescriptorSet descriptor_write;
8170 memset(&descriptor_write, 0, sizeof(descriptor_write));
8171 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008172 descriptor_write.dstSet = descriptorSet;
8173 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008174 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008175 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008176 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008177 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008178
8179 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008181 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008182
Chia-I Wuf7458c52015-10-26 21:10:41 +08008183 vkDestroySampler(m_device->device(), sampler, NULL);
8184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008186}
8187
Karl Schultz6addd812016-02-02 17:17:23 -07008188TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8189 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8190 // types
8191 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008192
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008194 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008195
Tobin Ehlis3b780662015-05-28 12:11:26 -06008196 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008197
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8200 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008201
8202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8204 ds_pool_ci.pNext = NULL;
8205 ds_pool_ci.maxSets = 1;
8206 ds_pool_ci.poolSizeCount = 1;
8207 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008208
Tobin Ehlis3b780662015-05-28 12:11:26 -06008209 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008210 err =
8211 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008212 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008213 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008214 dsl_binding.binding = 0;
8215 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8216 dsl_binding.descriptorCount = 1;
8217 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8218 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008219
Tony Barboureb254902015-07-15 12:50:33 -06008220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8222 ds_layout_ci.pNext = NULL;
8223 ds_layout_ci.bindingCount = 1;
8224 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008225
Tobin Ehlis3b780662015-05-28 12:11:26 -06008226 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008227 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8228 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008229 ASSERT_VK_SUCCESS(err);
8230
8231 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008232 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008234 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008235 alloc_info.descriptorPool = ds_pool;
8236 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8238 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008239 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008240
Tony Barboureb254902015-07-15 12:50:33 -06008241 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008242 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8243 sampler_ci.pNext = NULL;
8244 sampler_ci.magFilter = VK_FILTER_NEAREST;
8245 sampler_ci.minFilter = VK_FILTER_NEAREST;
8246 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8247 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8248 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8249 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8250 sampler_ci.mipLodBias = 1.0;
8251 sampler_ci.anisotropyEnable = VK_FALSE;
8252 sampler_ci.maxAnisotropy = 1;
8253 sampler_ci.compareEnable = VK_FALSE;
8254 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8255 sampler_ci.minLod = 1.0;
8256 sampler_ci.maxLod = 1.0;
8257 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8258 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008259 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008260 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008261 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008262
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008263 VkDescriptorImageInfo info = {};
8264 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008265
8266 VkWriteDescriptorSet descriptor_write;
8267 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008268 descriptor_write.sType =
8269 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008270 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008271 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008272 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008273 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008274 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008275
8276 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008278 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008279
Chia-I Wuf7458c52015-10-26 21:10:41 +08008280 vkDestroySampler(m_device->device(), sampler, NULL);
8281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008283}
8284
Karl Schultz6addd812016-02-02 17:17:23 -07008285TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008286 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008287 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008288
Karl Schultz6addd812016-02-02 17:17:23 -07008289 m_errorMonitor->SetDesiredFailureMsg(
8290 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008291 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008292
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008293 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008294 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8295 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008296 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008297 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8298 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008299
8300 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008301 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8302 ds_pool_ci.pNext = NULL;
8303 ds_pool_ci.maxSets = 1;
8304 ds_pool_ci.poolSizeCount = 1;
8305 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008306
8307 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008308 err =
8309 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008310 ASSERT_VK_SUCCESS(err);
8311
8312 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008313 dsl_binding.binding = 0;
8314 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8315 dsl_binding.descriptorCount = 1;
8316 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8317 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008318
8319 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008320 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8321 ds_layout_ci.pNext = NULL;
8322 ds_layout_ci.bindingCount = 1;
8323 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008324 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008325 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8326 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008327 ASSERT_VK_SUCCESS(err);
8328
8329 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008330 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008332 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008333 alloc_info.descriptorPool = ds_pool;
8334 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008335 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8336 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008337 ASSERT_VK_SUCCESS(err);
8338
Karl Schultz6addd812016-02-02 17:17:23 -07008339 VkSampler sampler =
8340 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008341
8342 VkDescriptorImageInfo descriptor_info;
8343 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8344 descriptor_info.sampler = sampler;
8345
8346 VkWriteDescriptorSet descriptor_write;
8347 memset(&descriptor_write, 0, sizeof(descriptor_write));
8348 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008349 descriptor_write.dstSet = descriptorSet;
8350 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008351 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008352 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8353 descriptor_write.pImageInfo = &descriptor_info;
8354
8355 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8356
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008357 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008358
Chia-I Wuf7458c52015-10-26 21:10:41 +08008359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8360 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008361}
8362
Karl Schultz6addd812016-02-02 17:17:23 -07008363TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8364 // Create a single combined Image/Sampler descriptor and send it an invalid
8365 // imageView
8366 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008367
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8369 "Attempted write update to combined "
8370 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008371 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008372
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008373 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008374 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008375 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8376 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008377
8378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8380 ds_pool_ci.pNext = NULL;
8381 ds_pool_ci.maxSets = 1;
8382 ds_pool_ci.poolSizeCount = 1;
8383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008384
8385 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008386 err =
8387 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008388 ASSERT_VK_SUCCESS(err);
8389
8390 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008391 dsl_binding.binding = 0;
8392 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8393 dsl_binding.descriptorCount = 1;
8394 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8395 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008396
8397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8399 ds_layout_ci.pNext = NULL;
8400 ds_layout_ci.bindingCount = 1;
8401 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008402 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8404 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008405 ASSERT_VK_SUCCESS(err);
8406
8407 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008408 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008410 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008411 alloc_info.descriptorPool = ds_pool;
8412 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8414 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008415 ASSERT_VK_SUCCESS(err);
8416
8417 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008418 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8419 sampler_ci.pNext = NULL;
8420 sampler_ci.magFilter = VK_FILTER_NEAREST;
8421 sampler_ci.minFilter = VK_FILTER_NEAREST;
8422 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8423 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8424 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8425 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8426 sampler_ci.mipLodBias = 1.0;
8427 sampler_ci.anisotropyEnable = VK_FALSE;
8428 sampler_ci.maxAnisotropy = 1;
8429 sampler_ci.compareEnable = VK_FALSE;
8430 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8431 sampler_ci.minLod = 1.0;
8432 sampler_ci.maxLod = 1.0;
8433 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8434 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008435
8436 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008437 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008438 ASSERT_VK_SUCCESS(err);
8439
Karl Schultz6addd812016-02-02 17:17:23 -07008440 VkImageView view =
8441 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008442
8443 VkDescriptorImageInfo descriptor_info;
8444 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8445 descriptor_info.sampler = sampler;
8446 descriptor_info.imageView = view;
8447
8448 VkWriteDescriptorSet descriptor_write;
8449 memset(&descriptor_write, 0, sizeof(descriptor_write));
8450 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008451 descriptor_write.dstSet = descriptorSet;
8452 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008453 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008454 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8455 descriptor_write.pImageInfo = &descriptor_info;
8456
8457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8458
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008459 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008460
Chia-I Wuf7458c52015-10-26 21:10:41 +08008461 vkDestroySampler(m_device->device(), sampler, NULL);
8462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008464}
8465
Karl Schultz6addd812016-02-02 17:17:23 -07008466TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8467 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8468 // into the other
8469 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008470
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8472 " binding #1 with type "
8473 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8474 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008475
Tobin Ehlis04356f92015-10-27 16:35:27 -06008476 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008477 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008478 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008479 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8480 ds_type_count[0].descriptorCount = 1;
8481 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8482 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008483
8484 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008485 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8486 ds_pool_ci.pNext = NULL;
8487 ds_pool_ci.maxSets = 1;
8488 ds_pool_ci.poolSizeCount = 2;
8489 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008490
8491 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008492 err =
8493 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008494 ASSERT_VK_SUCCESS(err);
8495 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008496 dsl_binding[0].binding = 0;
8497 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8498 dsl_binding[0].descriptorCount = 1;
8499 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8500 dsl_binding[0].pImmutableSamplers = NULL;
8501 dsl_binding[1].binding = 1;
8502 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8503 dsl_binding[1].descriptorCount = 1;
8504 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8505 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008506
8507 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008508 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8509 ds_layout_ci.pNext = NULL;
8510 ds_layout_ci.bindingCount = 2;
8511 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008512
8513 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008514 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8515 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008516 ASSERT_VK_SUCCESS(err);
8517
8518 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008519 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008520 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008521 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008522 alloc_info.descriptorPool = ds_pool;
8523 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008524 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8525 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008526 ASSERT_VK_SUCCESS(err);
8527
8528 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008529 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8530 sampler_ci.pNext = NULL;
8531 sampler_ci.magFilter = VK_FILTER_NEAREST;
8532 sampler_ci.minFilter = VK_FILTER_NEAREST;
8533 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8534 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8535 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8536 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8537 sampler_ci.mipLodBias = 1.0;
8538 sampler_ci.anisotropyEnable = VK_FALSE;
8539 sampler_ci.maxAnisotropy = 1;
8540 sampler_ci.compareEnable = VK_FALSE;
8541 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8542 sampler_ci.minLod = 1.0;
8543 sampler_ci.maxLod = 1.0;
8544 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8545 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008546
8547 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008548 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008549 ASSERT_VK_SUCCESS(err);
8550
8551 VkDescriptorImageInfo info = {};
8552 info.sampler = sampler;
8553
8554 VkWriteDescriptorSet descriptor_write;
8555 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8556 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008557 descriptor_write.dstSet = descriptorSet;
8558 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008559 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008560 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8561 descriptor_write.pImageInfo = &info;
8562 // This write update should succeed
8563 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8564 // Now perform a copy update that fails due to type mismatch
8565 VkCopyDescriptorSet copy_ds_update;
8566 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8567 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8568 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008569 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008570 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008571 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008572 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008573 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8574
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008575 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008576 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008577 m_errorMonitor->SetDesiredFailureMsg(
8578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008579 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008580 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8581 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8582 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008583 copy_ds_update.srcBinding =
8584 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008585 copy_ds_update.dstSet = descriptorSet;
8586 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008587 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008588 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8589
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008590 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008591
Tobin Ehlis04356f92015-10-27 16:35:27 -06008592 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008593 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008594 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8595 "update array offset of 0 and update of "
8596 "5 descriptors oversteps total number "
8597 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008598
Tobin Ehlis04356f92015-10-27 16:35:27 -06008599 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8600 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8601 copy_ds_update.srcSet = descriptorSet;
8602 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008603 copy_ds_update.dstSet = descriptorSet;
8604 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008605 copy_ds_update.descriptorCount =
8606 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008607 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8608
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008609 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008610
Chia-I Wuf7458c52015-10-26 21:10:41 +08008611 vkDestroySampler(m_device->device(), sampler, NULL);
8612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8613 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008614}
8615
Karl Schultz6addd812016-02-02 17:17:23 -07008616TEST_F(VkLayerTest, NumSamplesMismatch) {
8617 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8618 // sampleCount
8619 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008620
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008622 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008623
Tobin Ehlis3b780662015-05-28 12:11:26 -06008624 ASSERT_NO_FATAL_FAILURE(InitState());
8625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008626 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008627 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008628 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008629
8630 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008631 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8632 ds_pool_ci.pNext = NULL;
8633 ds_pool_ci.maxSets = 1;
8634 ds_pool_ci.poolSizeCount = 1;
8635 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008636
Tobin Ehlis3b780662015-05-28 12:11:26 -06008637 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008638 err =
8639 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008640 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008641
Tony Barboureb254902015-07-15 12:50:33 -06008642 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008643 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008644 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008645 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008646 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8647 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008648
Tony Barboureb254902015-07-15 12:50:33 -06008649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8651 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008652 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008653 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008654
Tobin Ehlis3b780662015-05-28 12:11:26 -06008655 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8657 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008658 ASSERT_VK_SUCCESS(err);
8659
8660 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008661 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008663 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008664 alloc_info.descriptorPool = ds_pool;
8665 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8667 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008668 ASSERT_VK_SUCCESS(err);
8669
Tony Barboureb254902015-07-15 12:50:33 -06008670 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008671 pipe_ms_state_ci.sType =
8672 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8673 pipe_ms_state_ci.pNext = NULL;
8674 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8675 pipe_ms_state_ci.sampleShadingEnable = 0;
8676 pipe_ms_state_ci.minSampleShading = 1.0;
8677 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008678
Tony Barboureb254902015-07-15 12:50:33 -06008679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8681 pipeline_layout_ci.pNext = NULL;
8682 pipeline_layout_ci.setLayoutCount = 1;
8683 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008684
8685 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8687 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008688 ASSERT_VK_SUCCESS(err);
8689
Karl Schultz6addd812016-02-02 17:17:23 -07008690 VkShaderObj vs(m_device, bindStateVertShaderText,
8691 VK_SHADER_STAGE_VERTEX_BIT, this);
8692 VkShaderObj fs(m_device, bindStateFragShaderText,
8693 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008694 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008695 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008696 VkPipelineObj pipe(m_device);
8697 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008698 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008699 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008700 pipe.SetMSAA(&pipe_ms_state_ci);
8701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008702
Tony Barbourfe3351b2015-07-28 10:17:20 -06008703 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8705 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008706
Mark Young29927482016-05-04 14:38:51 -06008707 // Render triangle (the error should trigger on the attempt to draw).
8708 Draw(3, 1, 0, 0);
8709
8710 // Finalize recording of the command buffer
8711 EndCommandBuffer();
8712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008713 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008714
Chia-I Wuf7458c52015-10-26 21:10:41 +08008715 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8716 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8717 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008718}
Mark Young29927482016-05-04 14:38:51 -06008719
Mark Youngc89c6312016-03-31 16:03:20 -06008720TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8721 // Create Pipeline where the number of blend attachments doesn't match the
8722 // number of color attachments. In this case, we don't add any color
8723 // blend attachments even though we have a color attachment.
8724 VkResult err;
8725
8726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008727 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008728
8729 ASSERT_NO_FATAL_FAILURE(InitState());
8730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8731 VkDescriptorPoolSize ds_type_count = {};
8732 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8733 ds_type_count.descriptorCount = 1;
8734
8735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8737 ds_pool_ci.pNext = NULL;
8738 ds_pool_ci.maxSets = 1;
8739 ds_pool_ci.poolSizeCount = 1;
8740 ds_pool_ci.pPoolSizes = &ds_type_count;
8741
8742 VkDescriptorPool ds_pool;
8743 err =
8744 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8745 ASSERT_VK_SUCCESS(err);
8746
8747 VkDescriptorSetLayoutBinding dsl_binding = {};
8748 dsl_binding.binding = 0;
8749 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8750 dsl_binding.descriptorCount = 1;
8751 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8752 dsl_binding.pImmutableSamplers = NULL;
8753
8754 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8755 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8756 ds_layout_ci.pNext = NULL;
8757 ds_layout_ci.bindingCount = 1;
8758 ds_layout_ci.pBindings = &dsl_binding;
8759
8760 VkDescriptorSetLayout ds_layout;
8761 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8762 &ds_layout);
8763 ASSERT_VK_SUCCESS(err);
8764
8765 VkDescriptorSet descriptorSet;
8766 VkDescriptorSetAllocateInfo alloc_info = {};
8767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8768 alloc_info.descriptorSetCount = 1;
8769 alloc_info.descriptorPool = ds_pool;
8770 alloc_info.pSetLayouts = &ds_layout;
8771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8772 &descriptorSet);
8773 ASSERT_VK_SUCCESS(err);
8774
8775 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8776 pipe_ms_state_ci.sType =
8777 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8778 pipe_ms_state_ci.pNext = NULL;
8779 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8780 pipe_ms_state_ci.sampleShadingEnable = 0;
8781 pipe_ms_state_ci.minSampleShading = 1.0;
8782 pipe_ms_state_ci.pSampleMask = NULL;
8783
8784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8786 pipeline_layout_ci.pNext = NULL;
8787 pipeline_layout_ci.setLayoutCount = 1;
8788 pipeline_layout_ci.pSetLayouts = &ds_layout;
8789
8790 VkPipelineLayout pipeline_layout;
8791 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8792 &pipeline_layout);
8793 ASSERT_VK_SUCCESS(err);
8794
8795 VkShaderObj vs(m_device, bindStateVertShaderText,
8796 VK_SHADER_STAGE_VERTEX_BIT, this);
8797 VkShaderObj fs(m_device, bindStateFragShaderText,
8798 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008799 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06008800 // but add it to be able to run on more devices
8801 VkPipelineObj pipe(m_device);
8802 pipe.AddShader(&vs);
8803 pipe.AddShader(&fs);
8804 pipe.SetMSAA(&pipe_ms_state_ci);
8805 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8806
8807 BeginCommandBuffer();
8808 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8809 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8810
Mark Young29927482016-05-04 14:38:51 -06008811 // Render triangle (the error should trigger on the attempt to draw).
8812 Draw(3, 1, 0, 0);
8813
8814 // Finalize recording of the command buffer
8815 EndCommandBuffer();
8816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008817 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06008818
8819 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8822}
Mark Young29927482016-05-04 14:38:51 -06008823
Mark Muellerd4914412016-06-13 17:52:06 -06008824TEST_F(VkLayerTest, MissingClearAttachment) {
8825 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
8826 "structure passed to vkCmdClearAttachments");
8827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8828 "vkCmdClearAttachments() attachment index 1 not found in attachment "
8829 "reference array of active subpass 0");
8830
8831 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
8832 m_errorMonitor->VerifyFound();
8833}
8834
Karl Schultz6addd812016-02-02 17:17:23 -07008835TEST_F(VkLayerTest, ClearCmdNoDraw) {
8836 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
8837 // to issuing a Draw
8838 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008839
Karl Schultz6addd812016-02-02 17:17:23 -07008840 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07008841 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008842 "vkCmdClearAttachments() issued on CB object ");
8843
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008844 ASSERT_NO_FATAL_FAILURE(InitState());
8845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008846
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008847 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008848 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8849 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008850
8851 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008852 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8853 ds_pool_ci.pNext = NULL;
8854 ds_pool_ci.maxSets = 1;
8855 ds_pool_ci.poolSizeCount = 1;
8856 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008857
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008858 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008859 err =
8860 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008861 ASSERT_VK_SUCCESS(err);
8862
Tony Barboureb254902015-07-15 12:50:33 -06008863 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008864 dsl_binding.binding = 0;
8865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8866 dsl_binding.descriptorCount = 1;
8867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8868 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008869
Tony Barboureb254902015-07-15 12:50:33 -06008870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8872 ds_layout_ci.pNext = NULL;
8873 ds_layout_ci.bindingCount = 1;
8874 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008875
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008876 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8878 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008879 ASSERT_VK_SUCCESS(err);
8880
8881 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008882 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008883 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008884 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008885 alloc_info.descriptorPool = ds_pool;
8886 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8888 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008889 ASSERT_VK_SUCCESS(err);
8890
Tony Barboureb254902015-07-15 12:50:33 -06008891 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008892 pipe_ms_state_ci.sType =
8893 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8894 pipe_ms_state_ci.pNext = NULL;
8895 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8896 pipe_ms_state_ci.sampleShadingEnable = 0;
8897 pipe_ms_state_ci.minSampleShading = 1.0;
8898 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008899
Tony Barboureb254902015-07-15 12:50:33 -06008900 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008901 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8902 pipeline_layout_ci.pNext = NULL;
8903 pipeline_layout_ci.setLayoutCount = 1;
8904 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008905
8906 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8908 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008909 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008910
Karl Schultz6addd812016-02-02 17:17:23 -07008911 VkShaderObj vs(m_device, bindStateVertShaderText,
8912 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06008913 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07008914 // on more devices
8915 VkShaderObj fs(m_device, bindStateFragShaderText,
8916 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008917
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008918 VkPipelineObj pipe(m_device);
8919 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008920 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008921 pipe.SetMSAA(&pipe_ms_state_ci);
8922 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008923
8924 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008925
Karl Schultz6addd812016-02-02 17:17:23 -07008926 // Main thing we care about for this test is that the VkImage obj we're
8927 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008928 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008929 VkClearAttachment color_attachment;
8930 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8931 color_attachment.clearValue.color.float32[0] = 1.0;
8932 color_attachment.clearValue.color.float32[1] = 1.0;
8933 color_attachment.clearValue.color.float32[2] = 1.0;
8934 color_attachment.clearValue.color.float32[3] = 1.0;
8935 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008936 VkClearRect clear_rect = {
8937 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008938
Karl Schultz6addd812016-02-02 17:17:23 -07008939 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8940 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008943
Chia-I Wuf7458c52015-10-26 21:10:41 +08008944 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8946 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008947}
8948
Karl Schultz6addd812016-02-02 17:17:23 -07008949TEST_F(VkLayerTest, VtxBufferBadIndex) {
8950 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008951
Karl Schultz6addd812016-02-02 17:17:23 -07008952 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008953 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008954 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008955
Tobin Ehlis502480b2015-06-24 15:53:07 -06008956 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008957 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008959
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008960 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008961 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8962 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008963
8964 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008965 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8966 ds_pool_ci.pNext = NULL;
8967 ds_pool_ci.maxSets = 1;
8968 ds_pool_ci.poolSizeCount = 1;
8969 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008970
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008971 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008972 err =
8973 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008974 ASSERT_VK_SUCCESS(err);
8975
Tony Barboureb254902015-07-15 12:50:33 -06008976 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008977 dsl_binding.binding = 0;
8978 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8979 dsl_binding.descriptorCount = 1;
8980 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8981 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008982
Tony Barboureb254902015-07-15 12:50:33 -06008983 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008984 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8985 ds_layout_ci.pNext = NULL;
8986 ds_layout_ci.bindingCount = 1;
8987 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008988
Tobin Ehlis502480b2015-06-24 15:53:07 -06008989 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008990 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8991 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008992 ASSERT_VK_SUCCESS(err);
8993
8994 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008995 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008996 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008997 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008998 alloc_info.descriptorPool = ds_pool;
8999 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009000 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9001 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009002 ASSERT_VK_SUCCESS(err);
9003
Tony Barboureb254902015-07-15 12:50:33 -06009004 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009005 pipe_ms_state_ci.sType =
9006 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9007 pipe_ms_state_ci.pNext = NULL;
9008 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9009 pipe_ms_state_ci.sampleShadingEnable = 0;
9010 pipe_ms_state_ci.minSampleShading = 1.0;
9011 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009012
Tony Barboureb254902015-07-15 12:50:33 -06009013 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009014 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9015 pipeline_layout_ci.pNext = NULL;
9016 pipeline_layout_ci.setLayoutCount = 1;
9017 pipeline_layout_ci.pSetLayouts = &ds_layout;
9018 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009019
Karl Schultz6addd812016-02-02 17:17:23 -07009020 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9021 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009022 ASSERT_VK_SUCCESS(err);
9023
Karl Schultz6addd812016-02-02 17:17:23 -07009024 VkShaderObj vs(m_device, bindStateVertShaderText,
9025 VK_SHADER_STAGE_VERTEX_BIT, this);
9026 VkShaderObj fs(m_device, bindStateFragShaderText,
9027 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009028 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009029 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009030 VkPipelineObj pipe(m_device);
9031 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009032 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009033 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009034 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009035 pipe.SetViewport(m_viewports);
9036 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009037 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009038
9039 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009040 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9041 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009042 // Don't care about actual data, just need to get to draw to flag error
9043 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009044 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9045 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009046 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009047 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009049 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009050
Chia-I Wuf7458c52015-10-26 21:10:41 +08009051 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9053 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009054}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009055// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9056TEST_F(VkLayerTest, InvalidImageLayout) {
9057 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9058 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9059 "images in the wrong layout when they're copied or transitioned.");
9060 // 3 in ValidateCmdBufImageLayouts
9061 // * -1 Attempt to submit cmd buf w/ deleted image
9062 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9063 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9064 m_errorMonitor->SetDesiredFailureMsg(
9065 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9066 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9067
9068 ASSERT_NO_FATAL_FAILURE(InitState());
9069 // Create src & dst images to use for copy operations
9070 VkImage src_image;
9071 VkImage dst_image;
9072
9073 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9074 const int32_t tex_width = 32;
9075 const int32_t tex_height = 32;
9076
9077 VkImageCreateInfo image_create_info = {};
9078 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9079 image_create_info.pNext = NULL;
9080 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9081 image_create_info.format = tex_format;
9082 image_create_info.extent.width = tex_width;
9083 image_create_info.extent.height = tex_height;
9084 image_create_info.extent.depth = 1;
9085 image_create_info.mipLevels = 1;
9086 image_create_info.arrayLayers = 4;
9087 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9088 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9089 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9090 image_create_info.flags = 0;
9091
9092 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9093 ASSERT_VK_SUCCESS(err);
9094 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9095 ASSERT_VK_SUCCESS(err);
9096
9097 BeginCommandBuffer();
9098 VkImageCopy copyRegion;
9099 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9100 copyRegion.srcSubresource.mipLevel = 0;
9101 copyRegion.srcSubresource.baseArrayLayer = 0;
9102 copyRegion.srcSubresource.layerCount = 1;
9103 copyRegion.srcOffset.x = 0;
9104 copyRegion.srcOffset.y = 0;
9105 copyRegion.srcOffset.z = 0;
9106 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9107 copyRegion.dstSubresource.mipLevel = 0;
9108 copyRegion.dstSubresource.baseArrayLayer = 0;
9109 copyRegion.dstSubresource.layerCount = 1;
9110 copyRegion.dstOffset.x = 0;
9111 copyRegion.dstOffset.y = 0;
9112 copyRegion.dstOffset.z = 0;
9113 copyRegion.extent.width = 1;
9114 copyRegion.extent.height = 1;
9115 copyRegion.extent.depth = 1;
9116 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9117 m_errorMonitor->VerifyFound();
9118 // Now cause error due to src image layout changing
9119 m_errorMonitor->SetDesiredFailureMsg(
9120 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9121 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9122 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9123 m_errorMonitor->VerifyFound();
9124 // Final src error is due to bad layout type
9125 m_errorMonitor->SetDesiredFailureMsg(
9126 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9127 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9128 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9129 m_errorMonitor->VerifyFound();
9130 // Now verify same checks for dst
9131 m_errorMonitor->SetDesiredFailureMsg(
9132 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9133 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9134 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9135 m_errorMonitor->VerifyFound();
9136 // Now cause error due to src image layout changing
9137 m_errorMonitor->SetDesiredFailureMsg(
9138 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9139 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9140 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9141 m_errorMonitor->VerifyFound();
9142 m_errorMonitor->SetDesiredFailureMsg(
9143 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9144 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9145 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9146 m_errorMonitor->VerifyFound();
9147 // Now cause error due to bad image layout transition in PipelineBarrier
9148 VkImageMemoryBarrier image_barrier[1] = {};
9149 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9150 image_barrier[0].image = src_image;
9151 image_barrier[0].subresourceRange.layerCount = 2;
9152 image_barrier[0].subresourceRange.levelCount = 2;
9153 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9154 m_errorMonitor->SetDesiredFailureMsg(
9155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9156 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9157 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9158 m_errorMonitor->VerifyFound();
9159
9160 // Finally some layout errors at RenderPass create time
9161 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9162 VkAttachmentReference attach = {};
9163 // perf warning for GENERAL layout w/ non-DS input attachment
9164 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9165 VkSubpassDescription subpass = {};
9166 subpass.inputAttachmentCount = 1;
9167 subpass.pInputAttachments = &attach;
9168 VkRenderPassCreateInfo rpci = {};
9169 rpci.subpassCount = 1;
9170 rpci.pSubpasses = &subpass;
9171 rpci.attachmentCount = 1;
9172 VkAttachmentDescription attach_desc = {};
9173 attach_desc.format = VK_FORMAT_UNDEFINED;
9174 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009175 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009176 VkRenderPass rp;
9177 m_errorMonitor->SetDesiredFailureMsg(
9178 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9179 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9180 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9181 m_errorMonitor->VerifyFound();
9182 // error w/ non-general layout
9183 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9184
9185 m_errorMonitor->SetDesiredFailureMsg(
9186 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9187 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9188 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9189 m_errorMonitor->VerifyFound();
9190 subpass.inputAttachmentCount = 0;
9191 subpass.colorAttachmentCount = 1;
9192 subpass.pColorAttachments = &attach;
9193 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9194 // perf warning for GENERAL layout on color attachment
9195 m_errorMonitor->SetDesiredFailureMsg(
9196 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9197 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9198 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9199 m_errorMonitor->VerifyFound();
9200 // error w/ non-color opt or GENERAL layout for color attachment
9201 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9202 m_errorMonitor->SetDesiredFailureMsg(
9203 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9204 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9205 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9206 m_errorMonitor->VerifyFound();
9207 subpass.colorAttachmentCount = 0;
9208 subpass.pDepthStencilAttachment = &attach;
9209 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9210 // perf warning for GENERAL layout on DS attachment
9211 m_errorMonitor->SetDesiredFailureMsg(
9212 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9213 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9214 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9215 m_errorMonitor->VerifyFound();
9216 // error w/ non-ds opt or GENERAL layout for color attachment
9217 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9218 m_errorMonitor->SetDesiredFailureMsg(
9219 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9220 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9221 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9222 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009223 // For this error we need a valid renderpass so create default one
9224 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9225 attach.attachment = 0;
9226 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9227 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9228 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9229 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9230 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9231 // Can't do a CLEAR load on READ_ONLY initialLayout
9232 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9233 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9234 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9236 " with invalid first layout "
9237 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9238 "ONLY_OPTIMAL");
9239 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9240 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009241
9242 vkDestroyImage(m_device->device(), src_image, NULL);
9243 vkDestroyImage(m_device->device(), dst_image, NULL);
9244}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009245#endif // DRAW_STATE_TESTS
9246
Tobin Ehlis0788f522015-05-26 16:11:58 -06009247#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009248#if GTEST_IS_THREADSAFE
9249struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009250 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009251 VkEvent event;
9252 bool bailout;
9253};
9254
Karl Schultz6addd812016-02-02 17:17:23 -07009255extern "C" void *AddToCommandBuffer(void *arg) {
9256 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009257
Karl Schultz6addd812016-02-02 17:17:23 -07009258 for (int i = 0; i < 10000; i++) {
9259 vkCmdSetEvent(data->commandBuffer, data->event,
9260 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009261 if (data->bailout) {
9262 break;
9263 }
9264 }
9265 return NULL;
9266}
9267
Karl Schultz6addd812016-02-02 17:17:23 -07009268TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009269 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009270
Karl Schultz6addd812016-02-02 17:17:23 -07009271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9272 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009273
Mike Stroyanaccf7692015-05-12 16:00:45 -06009274 ASSERT_NO_FATAL_FAILURE(InitState());
9275 ASSERT_NO_FATAL_FAILURE(InitViewport());
9276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9277
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009278 // Calls AllocateCommandBuffers
9279 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009280
9281 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009282 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009283
9284 VkEventCreateInfo event_info;
9285 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009286 VkResult err;
9287
9288 memset(&event_info, 0, sizeof(event_info));
9289 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9290
Chia-I Wuf7458c52015-10-26 21:10:41 +08009291 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009292 ASSERT_VK_SUCCESS(err);
9293
Mike Stroyanaccf7692015-05-12 16:00:45 -06009294 err = vkResetEvent(device(), event);
9295 ASSERT_VK_SUCCESS(err);
9296
9297 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009298 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009299 data.event = event;
9300 data.bailout = false;
9301 m_errorMonitor->SetBailout(&data.bailout);
9302 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009303 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009304 // Add many entries to command buffer from this thread at the same time.
9305 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009306
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009307 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009308 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009309
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009310 m_errorMonitor->SetBailout(NULL);
9311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009312 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009313
Chia-I Wuf7458c52015-10-26 21:10:41 +08009314 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009315}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009316#endif // GTEST_IS_THREADSAFE
9317#endif // THREADING_TESTS
9318
Chris Forbes9f7ff632015-05-25 11:13:08 +12009319#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009320TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009322 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009323
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009324 ASSERT_NO_FATAL_FAILURE(InitState());
9325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9326
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009327 VkShaderModule module;
9328 VkShaderModuleCreateInfo moduleCreateInfo;
9329 struct icd_spv_header spv;
9330
9331 spv.magic = ICD_SPV_MAGIC;
9332 spv.version = ICD_SPV_VERSION;
9333 spv.gen_magic = 0;
9334
9335 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9336 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009337 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009338 moduleCreateInfo.codeSize = 4;
9339 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009340 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009342 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009343}
9344
Karl Schultz6addd812016-02-02 17:17:23 -07009345TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009347 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009348
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009349 ASSERT_NO_FATAL_FAILURE(InitState());
9350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9351
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009352 VkShaderModule module;
9353 VkShaderModuleCreateInfo moduleCreateInfo;
9354 struct icd_spv_header spv;
9355
9356 spv.magic = ~ICD_SPV_MAGIC;
9357 spv.version = ICD_SPV_VERSION;
9358 spv.gen_magic = 0;
9359
9360 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9361 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009362 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009363 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9364 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009365 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009366
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009367 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009368}
9369
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009370#if 0
9371// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009372TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009374 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009375
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009376 ASSERT_NO_FATAL_FAILURE(InitState());
9377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9378
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009379 VkShaderModule module;
9380 VkShaderModuleCreateInfo moduleCreateInfo;
9381 struct icd_spv_header spv;
9382
9383 spv.magic = ICD_SPV_MAGIC;
9384 spv.version = ~ICD_SPV_VERSION;
9385 spv.gen_magic = 0;
9386
9387 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9388 moduleCreateInfo.pNext = NULL;
9389
Karl Schultz6addd812016-02-02 17:17:23 -07009390 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009391 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9392 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009393 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009394
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009395 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009396}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009397#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009398
Karl Schultz6addd812016-02-02 17:17:23 -07009399TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009401 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009402
Chris Forbes9f7ff632015-05-25 11:13:08 +12009403 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009405
9406 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009407 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009408 "\n"
9409 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009410 "out gl_PerVertex {\n"
9411 " vec4 gl_Position;\n"
9412 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009413 "void main(){\n"
9414 " gl_Position = vec4(1);\n"
9415 " x = 0;\n"
9416 "}\n";
9417 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009418 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009419 "\n"
9420 "layout(location=0) out vec4 color;\n"
9421 "void main(){\n"
9422 " color = vec4(1);\n"
9423 "}\n";
9424
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009427
9428 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009429 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009430 pipe.AddShader(&vs);
9431 pipe.AddShader(&fs);
9432
Chris Forbes9f7ff632015-05-25 11:13:08 +12009433 VkDescriptorSetObj descriptorSet(m_device);
9434 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009436
Tony Barbour5781e8f2015-08-04 16:23:11 -06009437 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009439 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009440}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009441
Karl Schultz6addd812016-02-02 17:17:23 -07009442TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009444 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009445
Chris Forbes59cb88d2015-05-25 11:13:13 +12009446 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009448
9449 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009450 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009451 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009452 "out gl_PerVertex {\n"
9453 " vec4 gl_Position;\n"
9454 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009455 "void main(){\n"
9456 " gl_Position = vec4(1);\n"
9457 "}\n";
9458 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009459 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009460 "\n"
9461 "layout(location=0) in float x;\n"
9462 "layout(location=0) out vec4 color;\n"
9463 "void main(){\n"
9464 " color = vec4(x);\n"
9465 "}\n";
9466
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009467 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9468 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009469
9470 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009471 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009472 pipe.AddShader(&vs);
9473 pipe.AddShader(&fs);
9474
Chris Forbes59cb88d2015-05-25 11:13:13 +12009475 VkDescriptorSetObj descriptorSet(m_device);
9476 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009477 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009478
Tony Barbour5781e8f2015-08-04 16:23:11 -06009479 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009480
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009481 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009482}
9483
Karl Schultz6addd812016-02-02 17:17:23 -07009484TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009486 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009487
9488 ASSERT_NO_FATAL_FAILURE(InitState());
9489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9490
9491 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009492 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009493 "\n"
9494 "out gl_PerVertex {\n"
9495 " vec4 gl_Position;\n"
9496 "};\n"
9497 "void main(){\n"
9498 " gl_Position = vec4(1);\n"
9499 "}\n";
9500 char const *fsSource =
9501 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009502 "\n"
9503 "in block { layout(location=0) float x; } ins;\n"
9504 "layout(location=0) out vec4 color;\n"
9505 "void main(){\n"
9506 " color = vec4(ins.x);\n"
9507 "}\n";
9508
9509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9511
9512 VkPipelineObj pipe(m_device);
9513 pipe.AddColorAttachment();
9514 pipe.AddShader(&vs);
9515 pipe.AddShader(&fs);
9516
9517 VkDescriptorSetObj descriptorSet(m_device);
9518 descriptorSet.AppendDummy();
9519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9520
9521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9522
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009523 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009524}
9525
Karl Schultz6addd812016-02-02 17:17:23 -07009526TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009528 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009529 "output arr[2] of float32' vs 'ptr to "
9530 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009531
9532 ASSERT_NO_FATAL_FAILURE(InitState());
9533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9534
9535 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009536 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009537 "\n"
9538 "layout(location=0) out float x[2];\n"
9539 "out gl_PerVertex {\n"
9540 " vec4 gl_Position;\n"
9541 "};\n"
9542 "void main(){\n"
9543 " x[0] = 0; x[1] = 0;\n"
9544 " gl_Position = vec4(1);\n"
9545 "}\n";
9546 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009547 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009548 "\n"
9549 "layout(location=0) in float x[3];\n"
9550 "layout(location=0) out vec4 color;\n"
9551 "void main(){\n"
9552 " color = vec4(x[0] + x[1] + x[2]);\n"
9553 "}\n";
9554
9555 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9556 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9557
9558 VkPipelineObj pipe(m_device);
9559 pipe.AddColorAttachment();
9560 pipe.AddShader(&vs);
9561 pipe.AddShader(&fs);
9562
9563 VkDescriptorSetObj descriptorSet(m_device);
9564 descriptorSet.AppendDummy();
9565 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9566
9567 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9568
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009569 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009570}
9571
Karl Schultz6addd812016-02-02 17:17:23 -07009572TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009574 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009575
Chris Forbesb56af562015-05-25 11:13:17 +12009576 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009578
9579 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009580 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009581 "\n"
9582 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009583 "out gl_PerVertex {\n"
9584 " vec4 gl_Position;\n"
9585 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009586 "void main(){\n"
9587 " x = 0;\n"
9588 " gl_Position = vec4(1);\n"
9589 "}\n";
9590 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009591 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009592 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009593 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009594 "layout(location=0) out vec4 color;\n"
9595 "void main(){\n"
9596 " color = vec4(x);\n"
9597 "}\n";
9598
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009599 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009601
9602 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009603 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009604 pipe.AddShader(&vs);
9605 pipe.AddShader(&fs);
9606
Chris Forbesb56af562015-05-25 11:13:17 +12009607 VkDescriptorSetObj descriptorSet(m_device);
9608 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009609 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009610
Tony Barbour5781e8f2015-08-04 16:23:11 -06009611 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009612
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009613 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009614}
9615
Karl Schultz6addd812016-02-02 17:17:23 -07009616TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009618 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009619
9620 ASSERT_NO_FATAL_FAILURE(InitState());
9621 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9622
9623 char const *vsSource =
9624 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009625 "\n"
9626 "out block { layout(location=0) int x; } outs;\n"
9627 "out gl_PerVertex {\n"
9628 " vec4 gl_Position;\n"
9629 "};\n"
9630 "void main(){\n"
9631 " outs.x = 0;\n"
9632 " gl_Position = vec4(1);\n"
9633 "}\n";
9634 char const *fsSource =
9635 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009636 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009637 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009638 "layout(location=0) out vec4 color;\n"
9639 "void main(){\n"
9640 " color = vec4(ins.x);\n"
9641 "}\n";
9642
9643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9645
9646 VkPipelineObj pipe(m_device);
9647 pipe.AddColorAttachment();
9648 pipe.AddShader(&vs);
9649 pipe.AddShader(&fs);
9650
9651 VkDescriptorSetObj descriptorSet(m_device);
9652 descriptorSet.AppendDummy();
9653 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9654
9655 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9656
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009657 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009658}
9659
9660TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9662 "location 0.0 which is not written by vertex shader");
9663
9664 ASSERT_NO_FATAL_FAILURE(InitState());
9665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9666
9667 char const *vsSource =
9668 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009669 "\n"
9670 "out block { layout(location=1) float x; } outs;\n"
9671 "out gl_PerVertex {\n"
9672 " vec4 gl_Position;\n"
9673 "};\n"
9674 "void main(){\n"
9675 " outs.x = 0;\n"
9676 " gl_Position = vec4(1);\n"
9677 "}\n";
9678 char const *fsSource =
9679 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009680 "\n"
9681 "in block { layout(location=0) float x; } ins;\n"
9682 "layout(location=0) out vec4 color;\n"
9683 "void main(){\n"
9684 " color = vec4(ins.x);\n"
9685 "}\n";
9686
9687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9689
9690 VkPipelineObj pipe(m_device);
9691 pipe.AddColorAttachment();
9692 pipe.AddShader(&vs);
9693 pipe.AddShader(&fs);
9694
9695 VkDescriptorSetObj descriptorSet(m_device);
9696 descriptorSet.AppendDummy();
9697 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9698
9699 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9700
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009701 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009702}
9703
9704TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9706 "location 0.1 which is not written by vertex shader");
9707
9708 ASSERT_NO_FATAL_FAILURE(InitState());
9709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9710
9711 char const *vsSource =
9712 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009713 "\n"
9714 "out block { layout(location=0, component=0) float x; } outs;\n"
9715 "out gl_PerVertex {\n"
9716 " vec4 gl_Position;\n"
9717 "};\n"
9718 "void main(){\n"
9719 " outs.x = 0;\n"
9720 " gl_Position = vec4(1);\n"
9721 "}\n";
9722 char const *fsSource =
9723 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009724 "\n"
9725 "in block { layout(location=0, component=1) float x; } ins;\n"
9726 "layout(location=0) out vec4 color;\n"
9727 "void main(){\n"
9728 " color = vec4(ins.x);\n"
9729 "}\n";
9730
9731 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9732 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9733
9734 VkPipelineObj pipe(m_device);
9735 pipe.AddColorAttachment();
9736 pipe.AddShader(&vs);
9737 pipe.AddShader(&fs);
9738
9739 VkDescriptorSetObj descriptorSet(m_device);
9740 descriptorSet.AppendDummy();
9741 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9742
9743 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9744
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009745 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009746}
9747
Karl Schultz6addd812016-02-02 17:17:23 -07009748TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009750 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009751
Chris Forbesde136e02015-05-25 11:13:28 +12009752 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12009754
9755 VkVertexInputBindingDescription input_binding;
9756 memset(&input_binding, 0, sizeof(input_binding));
9757
9758 VkVertexInputAttributeDescription input_attrib;
9759 memset(&input_attrib, 0, sizeof(input_attrib));
9760 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9761
9762 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009763 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009764 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009765 "out gl_PerVertex {\n"
9766 " vec4 gl_Position;\n"
9767 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009768 "void main(){\n"
9769 " gl_Position = vec4(1);\n"
9770 "}\n";
9771 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009772 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009773 "\n"
9774 "layout(location=0) out vec4 color;\n"
9775 "void main(){\n"
9776 " color = vec4(1);\n"
9777 "}\n";
9778
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009779 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9780 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12009781
9782 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009783 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12009784 pipe.AddShader(&vs);
9785 pipe.AddShader(&fs);
9786
9787 pipe.AddVertexInputBindings(&input_binding, 1);
9788 pipe.AddVertexInputAttribs(&input_attrib, 1);
9789
Chris Forbesde136e02015-05-25 11:13:28 +12009790 VkDescriptorSetObj descriptorSet(m_device);
9791 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009792 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12009793
Tony Barbour5781e8f2015-08-04 16:23:11 -06009794 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12009795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009796 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12009797}
9798
Karl Schultz6addd812016-02-02 17:17:23 -07009799TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009801 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13009802
9803 ASSERT_NO_FATAL_FAILURE(InitState());
9804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9805
9806 VkVertexInputBindingDescription input_binding;
9807 memset(&input_binding, 0, sizeof(input_binding));
9808
9809 VkVertexInputAttributeDescription input_attrib;
9810 memset(&input_attrib, 0, sizeof(input_attrib));
9811 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9812
9813 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009814 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009815 "\n"
9816 "layout(location=1) in float x;\n"
9817 "out gl_PerVertex {\n"
9818 " vec4 gl_Position;\n"
9819 "};\n"
9820 "void main(){\n"
9821 " gl_Position = vec4(x);\n"
9822 "}\n";
9823 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009824 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009825 "\n"
9826 "layout(location=0) out vec4 color;\n"
9827 "void main(){\n"
9828 " color = vec4(1);\n"
9829 "}\n";
9830
9831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9833
9834 VkPipelineObj pipe(m_device);
9835 pipe.AddColorAttachment();
9836 pipe.AddShader(&vs);
9837 pipe.AddShader(&fs);
9838
9839 pipe.AddVertexInputBindings(&input_binding, 1);
9840 pipe.AddVertexInputAttribs(&input_attrib, 1);
9841
9842 VkDescriptorSetObj descriptorSet(m_device);
9843 descriptorSet.AppendDummy();
9844 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9845
9846 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9847
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009848 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13009849}
9850
Karl Schultz6addd812016-02-02 17:17:23 -07009851TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
9852 m_errorMonitor->SetDesiredFailureMsg(
9853 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009854 "VS consumes input at location 0 but not provided");
9855
Chris Forbes62e8e502015-05-25 11:13:29 +12009856 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12009858
9859 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009860 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009861 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009862 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07009863 "out gl_PerVertex {\n"
9864 " vec4 gl_Position;\n"
9865 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009866 "void main(){\n"
9867 " gl_Position = x;\n"
9868 "}\n";
9869 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009870 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009871 "\n"
9872 "layout(location=0) out vec4 color;\n"
9873 "void main(){\n"
9874 " color = vec4(1);\n"
9875 "}\n";
9876
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009877 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12009879
9880 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009881 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12009882 pipe.AddShader(&vs);
9883 pipe.AddShader(&fs);
9884
Chris Forbes62e8e502015-05-25 11:13:29 +12009885 VkDescriptorSetObj descriptorSet(m_device);
9886 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12009888
Tony Barbour5781e8f2015-08-04 16:23:11 -06009889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12009890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009891 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12009892}
9893
Karl Schultz6addd812016-02-02 17:17:23 -07009894TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
9895 m_errorMonitor->SetDesiredFailureMsg(
9896 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009897 "location 0 does not match VS input type");
9898
Chris Forbesc97d98e2015-05-25 11:13:31 +12009899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009901
9902 VkVertexInputBindingDescription input_binding;
9903 memset(&input_binding, 0, sizeof(input_binding));
9904
9905 VkVertexInputAttributeDescription input_attrib;
9906 memset(&input_attrib, 0, sizeof(input_attrib));
9907 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9908
9909 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009910 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009911 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009912 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009913 "out gl_PerVertex {\n"
9914 " vec4 gl_Position;\n"
9915 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009916 "void main(){\n"
9917 " gl_Position = vec4(x);\n"
9918 "}\n";
9919 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009920 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009921 "\n"
9922 "layout(location=0) out vec4 color;\n"
9923 "void main(){\n"
9924 " color = vec4(1);\n"
9925 "}\n";
9926
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009929
9930 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009931 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009932 pipe.AddShader(&vs);
9933 pipe.AddShader(&fs);
9934
9935 pipe.AddVertexInputBindings(&input_binding, 1);
9936 pipe.AddVertexInputAttribs(&input_attrib, 1);
9937
Chris Forbesc97d98e2015-05-25 11:13:31 +12009938 VkDescriptorSetObj descriptorSet(m_device);
9939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009941
Tony Barbour5781e8f2015-08-04 16:23:11 -06009942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009943
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009944 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009945}
9946
Chris Forbesc68b43c2016-04-06 11:18:47 +12009947TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9948 m_errorMonitor->SetDesiredFailureMsg(
9949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9950 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9951
9952 ASSERT_NO_FATAL_FAILURE(InitState());
9953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9954
9955 char const *vsSource =
9956 "#version 450\n"
9957 "\n"
9958 "out gl_PerVertex {\n"
9959 " vec4 gl_Position;\n"
9960 "};\n"
9961 "void main(){\n"
9962 " gl_Position = vec4(1);\n"
9963 "}\n";
9964 char const *fsSource =
9965 "#version 450\n"
9966 "\n"
9967 "layout(location=0) out vec4 color;\n"
9968 "void main(){\n"
9969 " color = vec4(1);\n"
9970 "}\n";
9971
9972 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9973 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9974
9975 VkPipelineObj pipe(m_device);
9976 pipe.AddColorAttachment();
9977 pipe.AddShader(&vs);
9978 pipe.AddShader(&vs);
9979 pipe.AddShader(&fs);
9980
9981 VkDescriptorSetObj descriptorSet(m_device);
9982 descriptorSet.AppendDummy();
9983 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9984
9985 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009987 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009988}
9989
Karl Schultz6addd812016-02-02 17:17:23 -07009990TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009991 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009992
9993 ASSERT_NO_FATAL_FAILURE(InitState());
9994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9995
9996 VkVertexInputBindingDescription input_binding;
9997 memset(&input_binding, 0, sizeof(input_binding));
9998
9999 VkVertexInputAttributeDescription input_attribs[2];
10000 memset(input_attribs, 0, sizeof(input_attribs));
10001
10002 for (int i = 0; i < 2; i++) {
10003 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10004 input_attribs[i].location = i;
10005 }
10006
10007 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010008 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010009 "\n"
10010 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010011 "out gl_PerVertex {\n"
10012 " vec4 gl_Position;\n"
10013 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010014 "void main(){\n"
10015 " gl_Position = x[0] + x[1];\n"
10016 "}\n";
10017 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010018 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010019 "\n"
10020 "layout(location=0) out vec4 color;\n"
10021 "void main(){\n"
10022 " color = vec4(1);\n"
10023 "}\n";
10024
10025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10027
10028 VkPipelineObj pipe(m_device);
10029 pipe.AddColorAttachment();
10030 pipe.AddShader(&vs);
10031 pipe.AddShader(&fs);
10032
10033 pipe.AddVertexInputBindings(&input_binding, 1);
10034 pipe.AddVertexInputAttribs(input_attribs, 2);
10035
10036 VkDescriptorSetObj descriptorSet(m_device);
10037 descriptorSet.AppendDummy();
10038 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10039
10040 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10041
10042 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010043 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010044}
10045
Chris Forbes2682b242015-11-24 11:13:14 +130010046TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10047{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010048 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010049
10050 ASSERT_NO_FATAL_FAILURE(InitState());
10051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10052
10053 VkVertexInputBindingDescription input_binding;
10054 memset(&input_binding, 0, sizeof(input_binding));
10055
10056 VkVertexInputAttributeDescription input_attribs[2];
10057 memset(input_attribs, 0, sizeof(input_attribs));
10058
10059 for (int i = 0; i < 2; i++) {
10060 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10061 input_attribs[i].location = i;
10062 }
10063
10064 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010065 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010066 "\n"
10067 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010068 "out gl_PerVertex {\n"
10069 " vec4 gl_Position;\n"
10070 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010071 "void main(){\n"
10072 " gl_Position = x[0] + x[1];\n"
10073 "}\n";
10074 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010075 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010076 "\n"
10077 "layout(location=0) out vec4 color;\n"
10078 "void main(){\n"
10079 " color = vec4(1);\n"
10080 "}\n";
10081
10082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10084
10085 VkPipelineObj pipe(m_device);
10086 pipe.AddColorAttachment();
10087 pipe.AddShader(&vs);
10088 pipe.AddShader(&fs);
10089
10090 pipe.AddVertexInputBindings(&input_binding, 1);
10091 pipe.AddVertexInputAttribs(input_attribs, 2);
10092
10093 VkDescriptorSetObj descriptorSet(m_device);
10094 descriptorSet.AppendDummy();
10095 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10096
10097 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10098
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010099 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010100}
Chris Forbes2682b242015-11-24 11:13:14 +130010101
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010102TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10103{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010104 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010105
10106 ASSERT_NO_FATAL_FAILURE(InitState());
10107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10108
10109 char const *vsSource =
10110 "#version 450\n"
10111 "out gl_PerVertex {\n"
10112 " vec4 gl_Position;\n"
10113 "};\n"
10114 "void main(){\n"
10115 " gl_Position = vec4(0);\n"
10116 "}\n";
10117 char const *fsSource =
10118 "#version 450\n"
10119 "\n"
10120 "layout(location=0) out vec4 color;\n"
10121 "void main(){\n"
10122 " color = vec4(1);\n"
10123 "}\n";
10124
10125 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10126 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10127
10128 VkPipelineObj pipe(m_device);
10129 pipe.AddColorAttachment();
10130 pipe.AddShader(&vs);
10131 pipe.AddShader(&fs);
10132
10133 VkDescriptorSetObj descriptorSet(m_device);
10134 descriptorSet.AppendDummy();
10135 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10136
10137 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010139 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010140}
10141
Chris Forbes912c9192016-04-05 17:50:35 +120010142TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10143{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010144 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010145
10146 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10147
10148 ASSERT_NO_FATAL_FAILURE(InitState());
10149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10150
10151 char const *vsSource =
10152 "#version 450\n"
10153 "out gl_PerVertex {\n"
10154 " vec4 gl_Position;\n"
10155 "};\n"
10156 "layout(location=0) out vec3 x;\n"
10157 "layout(location=1) out ivec3 y;\n"
10158 "layout(location=2) out vec3 z;\n"
10159 "void main(){\n"
10160 " gl_Position = vec4(0);\n"
10161 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10162 "}\n";
10163 char const *fsSource =
10164 "#version 450\n"
10165 "\n"
10166 "layout(location=0) out vec4 color;\n"
10167 "layout(location=0) in float x;\n"
10168 "layout(location=1) flat in int y;\n"
10169 "layout(location=2) in vec2 z;\n"
10170 "void main(){\n"
10171 " color = vec4(1 + x + y + z.x);\n"
10172 "}\n";
10173
10174 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10175 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10176
10177 VkPipelineObj pipe(m_device);
10178 pipe.AddColorAttachment();
10179 pipe.AddShader(&vs);
10180 pipe.AddShader(&fs);
10181
10182 VkDescriptorSetObj descriptorSet(m_device);
10183 descriptorSet.AppendDummy();
10184 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10185
10186 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10187
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010188 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010189}
10190
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010191TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10192{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010193 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010194
10195 ASSERT_NO_FATAL_FAILURE(InitState());
10196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10197
Chris Forbesc1e852d2016-04-04 19:26:42 +120010198 if (!m_device->phy().features().tessellationShader) {
10199 printf("Device does not support tessellation shaders; skipped.\n");
10200 return;
10201 }
10202
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010203 char const *vsSource =
10204 "#version 450\n"
10205 "void main(){}\n";
10206 char const *tcsSource =
10207 "#version 450\n"
10208 "layout(location=0) out int x[];\n"
10209 "layout(vertices=3) out;\n"
10210 "void main(){\n"
10211 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10212 " gl_TessLevelInner[0] = 1;\n"
10213 " x[gl_InvocationID] = gl_InvocationID;\n"
10214 "}\n";
10215 char const *tesSource =
10216 "#version 450\n"
10217 "layout(triangles, equal_spacing, cw) in;\n"
10218 "layout(location=0) in int x[];\n"
10219 "out gl_PerVertex { vec4 gl_Position; };\n"
10220 "void main(){\n"
10221 " gl_Position.xyz = gl_TessCoord;\n"
10222 " gl_Position.w = x[0] + x[1] + x[2];\n"
10223 "}\n";
10224 char const *fsSource =
10225 "#version 450\n"
10226 "layout(location=0) out vec4 color;\n"
10227 "void main(){\n"
10228 " color = vec4(1);\n"
10229 "}\n";
10230
10231 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10232 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10233 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10234 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10235
10236 VkPipelineInputAssemblyStateCreateInfo iasci{
10237 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10238 nullptr,
10239 0,
10240 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10241 VK_FALSE};
10242
Chris Forbesb4cacb62016-04-04 19:15:00 +120010243 VkPipelineTessellationStateCreateInfo tsci{
10244 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10245 nullptr,
10246 0,
10247 3};
10248
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010249 VkPipelineObj pipe(m_device);
10250 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010251 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010252 pipe.AddColorAttachment();
10253 pipe.AddShader(&vs);
10254 pipe.AddShader(&tcs);
10255 pipe.AddShader(&tes);
10256 pipe.AddShader(&fs);
10257
10258 VkDescriptorSetObj descriptorSet(m_device);
10259 descriptorSet.AppendDummy();
10260 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10261
10262 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010264 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010265}
10266
Chris Forbesa0ab8152016-04-20 13:34:27 +120010267TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10268{
10269 m_errorMonitor->ExpectSuccess();
10270
10271 ASSERT_NO_FATAL_FAILURE(InitState());
10272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10273
10274 if (!m_device->phy().features().geometryShader) {
10275 printf("Device does not support geometry shaders; skipped.\n");
10276 return;
10277 }
10278
10279 char const *vsSource =
10280 "#version 450\n"
10281 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10282 "void main(){\n"
10283 " vs_out.x = vec4(1);\n"
10284 "}\n";
10285 char const *gsSource =
10286 "#version 450\n"
10287 "layout(triangles) in;\n"
10288 "layout(triangle_strip, max_vertices=3) out;\n"
10289 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10290 "out gl_PerVertex { vec4 gl_Position; };\n"
10291 "void main() {\n"
10292 " gl_Position = gs_in[0].x;\n"
10293 " EmitVertex();\n"
10294 "}\n";
10295 char const *fsSource =
10296 "#version 450\n"
10297 "layout(location=0) out vec4 color;\n"
10298 "void main(){\n"
10299 " color = vec4(1);\n"
10300 "}\n";
10301
10302 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10303 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10304 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10305
10306 VkPipelineObj pipe(m_device);
10307 pipe.AddColorAttachment();
10308 pipe.AddShader(&vs);
10309 pipe.AddShader(&gs);
10310 pipe.AddShader(&fs);
10311
10312 VkDescriptorSetObj descriptorSet(m_device);
10313 descriptorSet.AppendDummy();
10314 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10315
10316 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10317
10318 m_errorMonitor->VerifyNotFound();
10319}
10320
Chris Forbesa0193bc2016-04-04 19:19:47 +120010321TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10322{
10323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10324 "is per-vertex in tessellation control shader stage "
10325 "but per-patch in tessellation evaluation shader stage");
10326
10327 ASSERT_NO_FATAL_FAILURE(InitState());
10328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10329
Chris Forbesc1e852d2016-04-04 19:26:42 +120010330 if (!m_device->phy().features().tessellationShader) {
10331 printf("Device does not support tessellation shaders; skipped.\n");
10332 return;
10333 }
10334
Chris Forbesa0193bc2016-04-04 19:19:47 +120010335 char const *vsSource =
10336 "#version 450\n"
10337 "void main(){}\n";
10338 char const *tcsSource =
10339 "#version 450\n"
10340 "layout(location=0) out int x[];\n"
10341 "layout(vertices=3) out;\n"
10342 "void main(){\n"
10343 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10344 " gl_TessLevelInner[0] = 1;\n"
10345 " x[gl_InvocationID] = gl_InvocationID;\n"
10346 "}\n";
10347 char const *tesSource =
10348 "#version 450\n"
10349 "layout(triangles, equal_spacing, cw) in;\n"
10350 "layout(location=0) patch in int x;\n"
10351 "out gl_PerVertex { vec4 gl_Position; };\n"
10352 "void main(){\n"
10353 " gl_Position.xyz = gl_TessCoord;\n"
10354 " gl_Position.w = x;\n"
10355 "}\n";
10356 char const *fsSource =
10357 "#version 450\n"
10358 "layout(location=0) out vec4 color;\n"
10359 "void main(){\n"
10360 " color = vec4(1);\n"
10361 "}\n";
10362
10363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10364 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10365 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10366 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10367
10368 VkPipelineInputAssemblyStateCreateInfo iasci{
10369 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10370 nullptr,
10371 0,
10372 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10373 VK_FALSE};
10374
10375 VkPipelineTessellationStateCreateInfo tsci{
10376 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10377 nullptr,
10378 0,
10379 3};
10380
10381 VkPipelineObj pipe(m_device);
10382 pipe.SetInputAssembly(&iasci);
10383 pipe.SetTessellation(&tsci);
10384 pipe.AddColorAttachment();
10385 pipe.AddShader(&vs);
10386 pipe.AddShader(&tcs);
10387 pipe.AddShader(&tes);
10388 pipe.AddShader(&fs);
10389
10390 VkDescriptorSetObj descriptorSet(m_device);
10391 descriptorSet.AppendDummy();
10392 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10393
10394 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010396 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010397}
10398
Karl Schultz6addd812016-02-02 17:17:23 -070010399TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10400 m_errorMonitor->SetDesiredFailureMsg(
10401 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010402 "Duplicate vertex input binding descriptions for binding 0");
10403
Chris Forbes280ba2c2015-06-12 11:16:41 +120010404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010406
10407 /* Two binding descriptions for binding 0 */
10408 VkVertexInputBindingDescription input_bindings[2];
10409 memset(input_bindings, 0, sizeof(input_bindings));
10410
10411 VkVertexInputAttributeDescription input_attrib;
10412 memset(&input_attrib, 0, sizeof(input_attrib));
10413 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10414
10415 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010416 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010417 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010418 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010419 "out gl_PerVertex {\n"
10420 " vec4 gl_Position;\n"
10421 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010422 "void main(){\n"
10423 " gl_Position = vec4(x);\n"
10424 "}\n";
10425 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010426 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010427 "\n"
10428 "layout(location=0) out vec4 color;\n"
10429 "void main(){\n"
10430 " color = vec4(1);\n"
10431 "}\n";
10432
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010435
10436 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010437 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010438 pipe.AddShader(&vs);
10439 pipe.AddShader(&fs);
10440
10441 pipe.AddVertexInputBindings(input_bindings, 2);
10442 pipe.AddVertexInputAttribs(&input_attrib, 1);
10443
Chris Forbes280ba2c2015-06-12 11:16:41 +120010444 VkDescriptorSetObj descriptorSet(m_device);
10445 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010446 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010447
Tony Barbour5781e8f2015-08-04 16:23:11 -060010448 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010449
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010450 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010451}
Chris Forbes8f68b562015-05-25 11:13:32 +120010452
Chris Forbes35efec72016-04-21 14:32:08 +120010453TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10454 m_errorMonitor->ExpectSuccess();
10455
10456 ASSERT_NO_FATAL_FAILURE(InitState());
10457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10458
10459 if (!m_device->phy().features().tessellationShader) {
10460 printf("Device does not support 64bit vertex attributes; skipped.\n");
10461 return;
10462 }
10463
10464 VkVertexInputBindingDescription input_bindings[1];
10465 memset(input_bindings, 0, sizeof(input_bindings));
10466
10467 VkVertexInputAttributeDescription input_attribs[4];
10468 memset(input_attribs, 0, sizeof(input_attribs));
10469 input_attribs[0].location = 0;
10470 input_attribs[0].offset = 0;
10471 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10472 input_attribs[1].location = 2;
10473 input_attribs[1].offset = 32;
10474 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10475 input_attribs[2].location = 4;
10476 input_attribs[2].offset = 64;
10477 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10478 input_attribs[3].location = 6;
10479 input_attribs[3].offset = 96;
10480 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10481
10482 char const *vsSource =
10483 "#version 450\n"
10484 "\n"
10485 "layout(location=0) in dmat4 x;\n"
10486 "out gl_PerVertex {\n"
10487 " vec4 gl_Position;\n"
10488 "};\n"
10489 "void main(){\n"
10490 " gl_Position = vec4(x[0][0]);\n"
10491 "}\n";
10492 char const *fsSource =
10493 "#version 450\n"
10494 "\n"
10495 "layout(location=0) out vec4 color;\n"
10496 "void main(){\n"
10497 " color = vec4(1);\n"
10498 "}\n";
10499
10500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10502
10503 VkPipelineObj pipe(m_device);
10504 pipe.AddColorAttachment();
10505 pipe.AddShader(&vs);
10506 pipe.AddShader(&fs);
10507
10508 pipe.AddVertexInputBindings(input_bindings, 1);
10509 pipe.AddVertexInputAttribs(input_attribs, 4);
10510
10511 VkDescriptorSetObj descriptorSet(m_device);
10512 descriptorSet.AppendDummy();
10513 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10514
10515 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10516
10517 m_errorMonitor->VerifyNotFound();
10518}
10519
Karl Schultz6addd812016-02-02 17:17:23 -070010520TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010522 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010523
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010524 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010525
10526 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010527 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010528 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010529 "out gl_PerVertex {\n"
10530 " vec4 gl_Position;\n"
10531 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010532 "void main(){\n"
10533 " gl_Position = vec4(1);\n"
10534 "}\n";
10535 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010536 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010537 "\n"
10538 "void main(){\n"
10539 "}\n";
10540
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010543
10544 VkPipelineObj pipe(m_device);
10545 pipe.AddShader(&vs);
10546 pipe.AddShader(&fs);
10547
Chia-I Wu08accc62015-07-07 11:50:03 +080010548 /* set up CB 0, not written */
10549 pipe.AddColorAttachment();
10550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010551
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010552 VkDescriptorSetObj descriptorSet(m_device);
10553 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010555
Tony Barbour5781e8f2015-08-04 16:23:11 -060010556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010557
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010558 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010559}
10560
Karl Schultz6addd812016-02-02 17:17:23 -070010561TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010562 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010563 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010564 "FS writes to output location 1 with no matching attachment");
10565
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010566 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010567
10568 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010569 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010570 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010571 "out gl_PerVertex {\n"
10572 " vec4 gl_Position;\n"
10573 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010574 "void main(){\n"
10575 " gl_Position = vec4(1);\n"
10576 "}\n";
10577 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010578 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010579 "\n"
10580 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010581 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010582 "void main(){\n"
10583 " x = vec4(1);\n"
10584 " y = vec4(1);\n"
10585 "}\n";
10586
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010587 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10588 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010589
10590 VkPipelineObj pipe(m_device);
10591 pipe.AddShader(&vs);
10592 pipe.AddShader(&fs);
10593
Chia-I Wu08accc62015-07-07 11:50:03 +080010594 /* set up CB 0, not written */
10595 pipe.AddColorAttachment();
10596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010597 /* FS writes CB 1, but we don't configure it */
10598
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010599 VkDescriptorSetObj descriptorSet(m_device);
10600 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010602
Tony Barbour5781e8f2015-08-04 16:23:11 -060010603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010605 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010606}
10607
Karl Schultz6addd812016-02-02 17:17:23 -070010608TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010610 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010611
Chris Forbesa36d69e2015-05-25 11:13:44 +120010612 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010613
10614 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010615 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010616 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010617 "out gl_PerVertex {\n"
10618 " vec4 gl_Position;\n"
10619 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010620 "void main(){\n"
10621 " gl_Position = vec4(1);\n"
10622 "}\n";
10623 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010624 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010625 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010626 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010627 "void main(){\n"
10628 " x = ivec4(1);\n"
10629 "}\n";
10630
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010633
10634 VkPipelineObj pipe(m_device);
10635 pipe.AddShader(&vs);
10636 pipe.AddShader(&fs);
10637
Chia-I Wu08accc62015-07-07 11:50:03 +080010638 /* set up CB 0; type is UNORM by default */
10639 pipe.AddColorAttachment();
10640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010641
Chris Forbesa36d69e2015-05-25 11:13:44 +120010642 VkDescriptorSetObj descriptorSet(m_device);
10643 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010645
Tony Barbour5781e8f2015-08-04 16:23:11 -060010646 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010647
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010648 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010649}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010650
Karl Schultz6addd812016-02-02 17:17:23 -070010651TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010653 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010654
Chris Forbes556c76c2015-08-14 12:04:59 +120010655 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010656
10657 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010658 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010659 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010660 "out gl_PerVertex {\n"
10661 " vec4 gl_Position;\n"
10662 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010663 "void main(){\n"
10664 " gl_Position = vec4(1);\n"
10665 "}\n";
10666 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010667 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010668 "\n"
10669 "layout(location=0) out vec4 x;\n"
10670 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10671 "void main(){\n"
10672 " x = vec4(bar.y);\n"
10673 "}\n";
10674
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010675 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010677
Chris Forbes556c76c2015-08-14 12:04:59 +120010678 VkPipelineObj pipe(m_device);
10679 pipe.AddShader(&vs);
10680 pipe.AddShader(&fs);
10681
10682 /* set up CB 0; type is UNORM by default */
10683 pipe.AddColorAttachment();
10684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10685
10686 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010687 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010688
10689 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10690
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010691 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010692}
10693
Chris Forbes5c59e902016-02-26 16:56:09 +130010694TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10696 "not declared in layout");
10697
10698 ASSERT_NO_FATAL_FAILURE(InitState());
10699
10700 char const *vsSource =
10701 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010702 "\n"
10703 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10704 "out gl_PerVertex {\n"
10705 " vec4 gl_Position;\n"
10706 "};\n"
10707 "void main(){\n"
10708 " gl_Position = vec4(consts.x);\n"
10709 "}\n";
10710 char const *fsSource =
10711 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010712 "\n"
10713 "layout(location=0) out vec4 x;\n"
10714 "void main(){\n"
10715 " x = vec4(1);\n"
10716 "}\n";
10717
10718 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10719 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10720
10721 VkPipelineObj pipe(m_device);
10722 pipe.AddShader(&vs);
10723 pipe.AddShader(&fs);
10724
10725 /* set up CB 0; type is UNORM by default */
10726 pipe.AddColorAttachment();
10727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10728
10729 VkDescriptorSetObj descriptorSet(m_device);
10730 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10731
10732 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10733
10734 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010735 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010736}
10737
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010738TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10739 m_errorMonitor->SetDesiredFailureMsg(
10740 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10741 "Shader uses descriptor slot 0.0");
10742
10743 ASSERT_NO_FATAL_FAILURE(InitState());
10744
10745 char const *csSource =
10746 "#version 450\n"
10747 "\n"
10748 "layout(local_size_x=1) in;\n"
10749 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10750 "void main(){\n"
10751 " x = vec4(1);\n"
10752 "}\n";
10753
10754 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10755
10756 VkDescriptorSetObj descriptorSet(m_device);
10757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10758
10759 VkComputePipelineCreateInfo cpci = {
10760 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10761 nullptr, 0, {
10762 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10763 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10764 cs.handle(), "main", nullptr
10765 },
10766 descriptorSet.GetPipelineLayout(),
10767 VK_NULL_HANDLE, -1
10768 };
10769
10770 VkPipeline pipe;
10771 VkResult err = vkCreateComputePipelines(
10772 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10773
10774 m_errorMonitor->VerifyFound();
10775
10776 if (err == VK_SUCCESS) {
10777 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10778 }
10779}
10780
10781TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
10782 m_errorMonitor->ExpectSuccess();
10783
10784 ASSERT_NO_FATAL_FAILURE(InitState());
10785
10786 char const *csSource =
10787 "#version 450\n"
10788 "\n"
10789 "layout(local_size_x=1) in;\n"
10790 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10791 "void main(){\n"
10792 " // x is not used.\n"
10793 "}\n";
10794
10795 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10796
10797 VkDescriptorSetObj descriptorSet(m_device);
10798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10799
10800 VkComputePipelineCreateInfo cpci = {
10801 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10802 nullptr, 0, {
10803 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10804 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10805 cs.handle(), "main", nullptr
10806 },
10807 descriptorSet.GetPipelineLayout(),
10808 VK_NULL_HANDLE, -1
10809 };
10810
10811 VkPipeline pipe;
10812 VkResult err = vkCreateComputePipelines(
10813 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10814
10815 m_errorMonitor->VerifyNotFound();
10816
10817 if (err == VK_SUCCESS) {
10818 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10819 }
10820}
10821
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010822#endif // SHADER_CHECKER_TESTS
10823
10824#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060010825TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070010826 m_errorMonitor->SetDesiredFailureMsg(
10827 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010828 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010829
10830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010831
10832 // Create an image
10833 VkImage image;
10834
Karl Schultz6addd812016-02-02 17:17:23 -070010835 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10836 const int32_t tex_width = 32;
10837 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010838
10839 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010840 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10841 image_create_info.pNext = NULL;
10842 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10843 image_create_info.format = tex_format;
10844 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010845 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070010846 image_create_info.extent.depth = 1;
10847 image_create_info.mipLevels = 1;
10848 image_create_info.arrayLayers = 1;
10849 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10850 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10851 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10852 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010853
10854 // Introduce error by sending down a bogus width extent
10855 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010856 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010857
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010858 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010859}
10860
Mark Youngc48c4c12016-04-11 14:26:49 -060010861TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
10862 m_errorMonitor->SetDesiredFailureMsg(
10863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10864 "CreateImage extents is 0 for at least one required dimension");
10865
10866 ASSERT_NO_FATAL_FAILURE(InitState());
10867
10868 // Create an image
10869 VkImage image;
10870
10871 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10872 const int32_t tex_width = 32;
10873 const int32_t tex_height = 32;
10874
10875 VkImageCreateInfo image_create_info = {};
10876 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10877 image_create_info.pNext = NULL;
10878 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10879 image_create_info.format = tex_format;
10880 image_create_info.extent.width = tex_width;
10881 image_create_info.extent.height = tex_height;
10882 image_create_info.extent.depth = 1;
10883 image_create_info.mipLevels = 1;
10884 image_create_info.arrayLayers = 1;
10885 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10886 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10887 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10888 image_create_info.flags = 0;
10889
10890 // Introduce error by sending down a bogus width extent
10891 image_create_info.extent.width = 0;
10892 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
10893
10894 m_errorMonitor->VerifyFound();
10895}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010896#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120010897
Tobin Ehliscde08892015-09-22 10:11:37 -060010898#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070010899TEST_F(VkLayerTest, InvalidImageView) {
10900 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060010901
Karl Schultz6addd812016-02-02 17:17:23 -070010902 m_errorMonitor->SetDesiredFailureMsg(
10903 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010904 "vkCreateImageView called with baseMipLevel 10 ");
10905
Tobin Ehliscde08892015-09-22 10:11:37 -060010906 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060010907
Mike Stroyana3082432015-09-25 13:39:21 -060010908 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070010909 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060010910
Karl Schultz6addd812016-02-02 17:17:23 -070010911 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10912 const int32_t tex_width = 32;
10913 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060010914
10915 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010916 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10917 image_create_info.pNext = NULL;
10918 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10919 image_create_info.format = tex_format;
10920 image_create_info.extent.width = tex_width;
10921 image_create_info.extent.height = tex_height;
10922 image_create_info.extent.depth = 1;
10923 image_create_info.mipLevels = 1;
10924 image_create_info.arrayLayers = 1;
10925 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10926 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10927 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10928 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060010929
Chia-I Wuf7458c52015-10-26 21:10:41 +080010930 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060010931 ASSERT_VK_SUCCESS(err);
10932
10933 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010934 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10935 image_view_create_info.image = image;
10936 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10937 image_view_create_info.format = tex_format;
10938 image_view_create_info.subresourceRange.layerCount = 1;
10939 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
10940 image_view_create_info.subresourceRange.levelCount = 1;
10941 image_view_create_info.subresourceRange.aspectMask =
10942 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060010943
10944 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010945 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10946 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060010947
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010948 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010949 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060010950}
Mike Stroyana3082432015-09-25 13:39:21 -060010951
Karl Schultz6addd812016-02-02 17:17:23 -070010952TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010953 TEST_DESCRIPTION(
10954 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010956 "vkCreateImageView: Color image "
10957 "formats must have ONLY the "
10958 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010959
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010960 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010961
Karl Schultz6addd812016-02-02 17:17:23 -070010962 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010963 VkImageObj image(m_device);
10964 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
10965 VK_IMAGE_TILING_LINEAR, 0);
10966 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010967
10968 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010969 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010970 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070010971 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10972 image_view_create_info.format = tex_format;
10973 image_view_create_info.subresourceRange.baseMipLevel = 0;
10974 image_view_create_info.subresourceRange.levelCount = 1;
10975 // Cause an error by setting an invalid image aspect
10976 image_view_create_info.subresourceRange.aspectMask =
10977 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010978
10979 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010980 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010981
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010982 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010983}
10984
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010985TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010986 VkResult err;
10987 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010988
Karl Schultz6addd812016-02-02 17:17:23 -070010989 m_errorMonitor->SetDesiredFailureMsg(
10990 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010991 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010992
Mike Stroyana3082432015-09-25 13:39:21 -060010993 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010994
10995 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010996 VkImage srcImage;
10997 VkImage dstImage;
10998 VkDeviceMemory srcMem;
10999 VkDeviceMemory destMem;
11000 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011001
11002 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011003 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11004 image_create_info.pNext = NULL;
11005 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11006 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11007 image_create_info.extent.width = 32;
11008 image_create_info.extent.height = 32;
11009 image_create_info.extent.depth = 1;
11010 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011011 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011012 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11013 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11014 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11015 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011016
Karl Schultz6addd812016-02-02 17:17:23 -070011017 err =
11018 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011019 ASSERT_VK_SUCCESS(err);
11020
Karl Schultz6addd812016-02-02 17:17:23 -070011021 err =
11022 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011023 ASSERT_VK_SUCCESS(err);
11024
11025 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011026 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011027 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11028 memAlloc.pNext = NULL;
11029 memAlloc.allocationSize = 0;
11030 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011031
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011032 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011033 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011034 pass =
11035 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011036 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011037 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011038 ASSERT_VK_SUCCESS(err);
11039
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011040 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011041 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011042 pass =
11043 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011044 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011045 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011046 ASSERT_VK_SUCCESS(err);
11047
11048 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11049 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011050 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011051 ASSERT_VK_SUCCESS(err);
11052
11053 BeginCommandBuffer();
11054 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011055 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011056 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011057 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011058 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011059 copyRegion.srcOffset.x = 0;
11060 copyRegion.srcOffset.y = 0;
11061 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011062 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011063 copyRegion.dstSubresource.mipLevel = 0;
11064 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011065 // Introduce failure by forcing the dst layerCount to differ from src
11066 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011067 copyRegion.dstOffset.x = 0;
11068 copyRegion.dstOffset.y = 0;
11069 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011070 copyRegion.extent.width = 1;
11071 copyRegion.extent.height = 1;
11072 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011073 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11074 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011075 EndCommandBuffer();
11076
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011077 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011078
Chia-I Wuf7458c52015-10-26 21:10:41 +080011079 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011080 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011081 vkFreeMemory(m_device->device(), srcMem, NULL);
11082 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011083}
11084
Tony Barbourd6673642016-05-05 14:46:39 -060011085TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11086
11087 TEST_DESCRIPTION("Creating images with unsuported formats ");
11088
11089 ASSERT_NO_FATAL_FAILURE(InitState());
11090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11091 VkImageObj image(m_device);
11092 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11093 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11094 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11095 VK_IMAGE_TILING_OPTIMAL, 0);
11096 ASSERT_TRUE(image.initialized());
11097
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011098 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11099 VkImageCreateInfo image_create_info;
11100 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11101 image_create_info.pNext = NULL;
11102 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11103 image_create_info.format = VK_FORMAT_UNDEFINED;
11104 image_create_info.extent.width = 32;
11105 image_create_info.extent.height = 32;
11106 image_create_info.extent.depth = 1;
11107 image_create_info.mipLevels = 1;
11108 image_create_info.arrayLayers = 1;
11109 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11110 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11111 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11112 image_create_info.flags = 0;
11113
11114 m_errorMonitor->SetDesiredFailureMsg(
11115 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11116 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11117
11118 VkImage localImage;
11119 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11120 m_errorMonitor->VerifyFound();
11121
Tony Barbourd6673642016-05-05 14:46:39 -060011122 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011123 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011124 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11125 VkFormat format = static_cast<VkFormat>(f);
11126 VkFormatProperties fProps = m_device->format_properties(format);
11127 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11128 fProps.optimalTilingFeatures == 0) {
11129 unsupported = format;
11130 break;
11131 }
11132 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011133
Tony Barbourd6673642016-05-05 14:46:39 -060011134 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011135 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011137 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011138
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011139 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011140 m_errorMonitor->VerifyFound();
11141 }
11142}
11143
11144TEST_F(VkLayerTest, ImageLayerViewTests) {
11145 VkResult ret;
11146 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11147
11148 ASSERT_NO_FATAL_FAILURE(InitState());
11149
11150 VkImageObj image(m_device);
11151 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11152 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11153 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11154 VK_IMAGE_TILING_OPTIMAL, 0);
11155 ASSERT_TRUE(image.initialized());
11156
11157 VkImageView imgView;
11158 VkImageViewCreateInfo imgViewInfo = {};
11159 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11160 imgViewInfo.image = image.handle();
11161 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11162 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11163 imgViewInfo.subresourceRange.layerCount = 1;
11164 imgViewInfo.subresourceRange.baseMipLevel = 0;
11165 imgViewInfo.subresourceRange.levelCount = 1;
11166 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11167
11168 m_errorMonitor->SetDesiredFailureMsg(
11169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11170 "vkCreateImageView called with baseMipLevel");
11171 // View can't have baseMipLevel >= image's mipLevels - Expect
11172 // VIEW_CREATE_ERROR
11173 imgViewInfo.subresourceRange.baseMipLevel = 1;
11174 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11175 m_errorMonitor->VerifyFound();
11176 imgViewInfo.subresourceRange.baseMipLevel = 0;
11177
11178 m_errorMonitor->SetDesiredFailureMsg(
11179 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11180 "vkCreateImageView called with baseArrayLayer");
11181 // View can't have baseArrayLayer >= image's arraySize - Expect
11182 // VIEW_CREATE_ERROR
11183 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11184 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11185 m_errorMonitor->VerifyFound();
11186 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11187
11188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11189 "vkCreateImageView called with 0 in "
11190 "pCreateInfo->subresourceRange."
11191 "levelCount");
11192 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11193 imgViewInfo.subresourceRange.levelCount = 0;
11194 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11195 m_errorMonitor->VerifyFound();
11196 imgViewInfo.subresourceRange.levelCount = 1;
11197
11198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11199 "vkCreateImageView called with 0 in "
11200 "pCreateInfo->subresourceRange."
11201 "layerCount");
11202 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11203 imgViewInfo.subresourceRange.layerCount = 0;
11204 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11205 m_errorMonitor->VerifyFound();
11206 imgViewInfo.subresourceRange.layerCount = 1;
11207
11208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11209 "but both must be color formats");
11210 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11211 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11212 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11213 m_errorMonitor->VerifyFound();
11214 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11215
11216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11217 "Formats MUST be IDENTICAL unless "
11218 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11219 "was set on image creation.");
11220 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11221 // VIEW_CREATE_ERROR
11222 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11223 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11224 m_errorMonitor->VerifyFound();
11225 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11226
11227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11228 "can support ImageViews with "
11229 "differing formats but they must be "
11230 "in the same compatibility class.");
11231 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11232 // VIEW_CREATE_ERROR
11233 VkImageCreateInfo mutImgInfo = image.create_info();
11234 VkImage mutImage;
11235 mutImgInfo.format = VK_FORMAT_R8_UINT;
11236 assert(
11237 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11238 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11239 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11240 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11241 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11242 ASSERT_VK_SUCCESS(ret);
11243 imgViewInfo.image = mutImage;
11244 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11245 m_errorMonitor->VerifyFound();
11246 imgViewInfo.image = image.handle();
11247 vkDestroyImage(m_device->handle(), mutImage, NULL);
11248}
11249
11250TEST_F(VkLayerTest, MiscImageLayerTests) {
11251
11252 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11253
11254 ASSERT_NO_FATAL_FAILURE(InitState());
11255
11256 VkImageObj image(m_device);
11257 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11258 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11259 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11260 VK_IMAGE_TILING_OPTIMAL, 0);
11261 ASSERT_TRUE(image.initialized());
11262
11263 m_errorMonitor->SetDesiredFailureMsg(
11264 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11265 "number of layers in image subresource is zero");
11266 vk_testing::Buffer buffer;
11267 VkMemoryPropertyFlags reqs = 0;
11268 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11269 VkBufferImageCopy region = {};
11270 region.bufferRowLength = 128;
11271 region.bufferImageHeight = 128;
11272 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11273 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11274 region.imageSubresource.layerCount = 0;
11275 region.imageExtent.height = 4;
11276 region.imageExtent.width = 4;
11277 region.imageExtent.depth = 1;
11278 m_commandBuffer->BeginCommandBuffer();
11279 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11280 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11281 1, &region);
11282 m_errorMonitor->VerifyFound();
11283 region.imageSubresource.layerCount = 1;
11284
11285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11286 "aspectMasks for each region must "
11287 "specify only COLOR or DEPTH or "
11288 "STENCIL");
11289 // Expect MISMATCHED_IMAGE_ASPECT
11290 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11291 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11292 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11293 1, &region);
11294 m_errorMonitor->VerifyFound();
11295 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11296
11297 m_errorMonitor->SetDesiredFailureMsg(
11298 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11299 "If the format of srcImage is a depth, stencil, depth stencil or "
11300 "integer-based format then filter must be VK_FILTER_NEAREST");
11301 // Expect INVALID_FILTER
11302 VkImageObj intImage1(m_device);
11303 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11304 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11305 0);
11306 VkImageObj intImage2(m_device);
11307 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11308 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11309 0);
11310 VkImageBlit blitRegion = {};
11311 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11312 blitRegion.srcSubresource.baseArrayLayer = 0;
11313 blitRegion.srcSubresource.layerCount = 1;
11314 blitRegion.srcSubresource.mipLevel = 0;
11315 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11316 blitRegion.dstSubresource.baseArrayLayer = 0;
11317 blitRegion.dstSubresource.layerCount = 1;
11318 blitRegion.dstSubresource.mipLevel = 0;
11319
11320 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11321 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11322 16, &blitRegion, VK_FILTER_LINEAR);
11323 m_errorMonitor->VerifyFound();
11324
11325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11326 "called with 0 in ppMemoryBarriers");
11327 VkImageMemoryBarrier img_barrier;
11328 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11329 img_barrier.pNext = NULL;
11330 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11331 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11332 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11333 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11334 img_barrier.image = image.handle();
11335 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11336 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11337 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11338 img_barrier.subresourceRange.baseArrayLayer = 0;
11339 img_barrier.subresourceRange.baseMipLevel = 0;
11340 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11341 img_barrier.subresourceRange.layerCount = 0;
11342 img_barrier.subresourceRange.levelCount = 1;
11343 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11344 VK_PIPELINE_STAGE_HOST_BIT,
11345 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11346 nullptr, 1, &img_barrier);
11347 m_errorMonitor->VerifyFound();
11348 img_barrier.subresourceRange.layerCount = 1;
11349}
11350
11351TEST_F(VkLayerTest, ImageFormatLimits) {
11352
11353 TEST_DESCRIPTION("Exceed the limits of image format ");
11354
11355 m_errorMonitor->SetDesiredFailureMsg(
11356 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11357 "CreateImage extents exceed allowable limits for format");
11358 VkImageCreateInfo image_create_info = {};
11359 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11360 image_create_info.pNext = NULL;
11361 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11362 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11363 image_create_info.extent.width = 32;
11364 image_create_info.extent.height = 32;
11365 image_create_info.extent.depth = 1;
11366 image_create_info.mipLevels = 1;
11367 image_create_info.arrayLayers = 1;
11368 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11369 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11370 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11372 image_create_info.flags = 0;
11373
11374 VkImage nullImg;
11375 VkImageFormatProperties imgFmtProps;
11376 vkGetPhysicalDeviceImageFormatProperties(
11377 gpu(), image_create_info.format, image_create_info.imageType,
11378 image_create_info.tiling, image_create_info.usage,
11379 image_create_info.flags, &imgFmtProps);
11380 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11381 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11382 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11383 m_errorMonitor->VerifyFound();
11384 image_create_info.extent.depth = 1;
11385
11386 m_errorMonitor->SetDesiredFailureMsg(
11387 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11388 "exceeds allowable maximum supported by format of");
11389 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11390 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11391 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11392 m_errorMonitor->VerifyFound();
11393 image_create_info.mipLevels = 1;
11394
11395 m_errorMonitor->SetDesiredFailureMsg(
11396 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11397 "exceeds allowable maximum supported by format of");
11398 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11399 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11400 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11401 m_errorMonitor->VerifyFound();
11402 image_create_info.arrayLayers = 1;
11403
11404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11405 "is not supported by format");
11406 int samples = imgFmtProps.sampleCounts >> 1;
11407 image_create_info.samples = (VkSampleCountFlagBits)samples;
11408 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11409 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11410 m_errorMonitor->VerifyFound();
11411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11412
11413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11414 "pCreateInfo->initialLayout, must be "
11415 "VK_IMAGE_LAYOUT_UNDEFINED or "
11416 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11417 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11418 // Expect INVALID_LAYOUT
11419 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11420 m_errorMonitor->VerifyFound();
11421 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11422}
11423
Karl Schultz6addd812016-02-02 17:17:23 -070011424TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011425 VkResult err;
11426 bool pass;
11427
11428 // Create color images with different format sizes and try to copy between them
11429 m_errorMonitor->SetDesiredFailureMsg(
11430 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11431 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11432
11433 ASSERT_NO_FATAL_FAILURE(InitState());
11434
11435 // Create two images of different types and try to copy between them
11436 VkImage srcImage;
11437 VkImage dstImage;
11438 VkDeviceMemory srcMem;
11439 VkDeviceMemory destMem;
11440 VkMemoryRequirements memReqs;
11441
11442 VkImageCreateInfo image_create_info = {};
11443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11444 image_create_info.pNext = NULL;
11445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11446 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11447 image_create_info.extent.width = 32;
11448 image_create_info.extent.height = 32;
11449 image_create_info.extent.depth = 1;
11450 image_create_info.mipLevels = 1;
11451 image_create_info.arrayLayers = 1;
11452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11454 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11455 image_create_info.flags = 0;
11456
11457 err =
11458 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11459 ASSERT_VK_SUCCESS(err);
11460
11461 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11462 // Introduce failure by creating second image with a different-sized format.
11463 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11464
11465 err =
11466 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11467 ASSERT_VK_SUCCESS(err);
11468
11469 // Allocate memory
11470 VkMemoryAllocateInfo memAlloc = {};
11471 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11472 memAlloc.pNext = NULL;
11473 memAlloc.allocationSize = 0;
11474 memAlloc.memoryTypeIndex = 0;
11475
11476 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11477 memAlloc.allocationSize = memReqs.size;
11478 pass =
11479 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11480 ASSERT_TRUE(pass);
11481 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11482 ASSERT_VK_SUCCESS(err);
11483
11484 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11485 memAlloc.allocationSize = memReqs.size;
11486 pass =
11487 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11488 ASSERT_TRUE(pass);
11489 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11490 ASSERT_VK_SUCCESS(err);
11491
11492 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11493 ASSERT_VK_SUCCESS(err);
11494 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11495 ASSERT_VK_SUCCESS(err);
11496
11497 BeginCommandBuffer();
11498 VkImageCopy copyRegion;
11499 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11500 copyRegion.srcSubresource.mipLevel = 0;
11501 copyRegion.srcSubresource.baseArrayLayer = 0;
11502 copyRegion.srcSubresource.layerCount = 0;
11503 copyRegion.srcOffset.x = 0;
11504 copyRegion.srcOffset.y = 0;
11505 copyRegion.srcOffset.z = 0;
11506 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11507 copyRegion.dstSubresource.mipLevel = 0;
11508 copyRegion.dstSubresource.baseArrayLayer = 0;
11509 copyRegion.dstSubresource.layerCount = 0;
11510 copyRegion.dstOffset.x = 0;
11511 copyRegion.dstOffset.y = 0;
11512 copyRegion.dstOffset.z = 0;
11513 copyRegion.extent.width = 1;
11514 copyRegion.extent.height = 1;
11515 copyRegion.extent.depth = 1;
11516 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11517 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11518 EndCommandBuffer();
11519
11520 m_errorMonitor->VerifyFound();
11521
11522 vkDestroyImage(m_device->device(), srcImage, NULL);
11523 vkDestroyImage(m_device->device(), dstImage, NULL);
11524 vkFreeMemory(m_device->device(), srcMem, NULL);
11525 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011526}
11527
Karl Schultz6addd812016-02-02 17:17:23 -070011528TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11529 VkResult err;
11530 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011531
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011532 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011533 m_errorMonitor->SetDesiredFailureMsg(
11534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011535 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011536
Mike Stroyana3082432015-09-25 13:39:21 -060011537 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011538
11539 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011540 VkImage srcImage;
11541 VkImage dstImage;
11542 VkDeviceMemory srcMem;
11543 VkDeviceMemory destMem;
11544 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011545
11546 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11548 image_create_info.pNext = NULL;
11549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11550 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11551 image_create_info.extent.width = 32;
11552 image_create_info.extent.height = 32;
11553 image_create_info.extent.depth = 1;
11554 image_create_info.mipLevels = 1;
11555 image_create_info.arrayLayers = 1;
11556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11557 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11558 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11559 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011560
Karl Schultz6addd812016-02-02 17:17:23 -070011561 err =
11562 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011563 ASSERT_VK_SUCCESS(err);
11564
Karl Schultzbdb75952016-04-19 11:36:49 -060011565 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11566
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011567 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011568 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011569 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11570 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011571
Karl Schultz6addd812016-02-02 17:17:23 -070011572 err =
11573 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011574 ASSERT_VK_SUCCESS(err);
11575
11576 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011577 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011578 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11579 memAlloc.pNext = NULL;
11580 memAlloc.allocationSize = 0;
11581 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011582
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011583 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011584 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011585 pass =
11586 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011587 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011588 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011589 ASSERT_VK_SUCCESS(err);
11590
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011591 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011592 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011593 pass =
11594 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011595 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011596 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011597 ASSERT_VK_SUCCESS(err);
11598
11599 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11600 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011601 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011602 ASSERT_VK_SUCCESS(err);
11603
11604 BeginCommandBuffer();
11605 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011606 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011607 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011608 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011610 copyRegion.srcOffset.x = 0;
11611 copyRegion.srcOffset.y = 0;
11612 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011613 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011614 copyRegion.dstSubresource.mipLevel = 0;
11615 copyRegion.dstSubresource.baseArrayLayer = 0;
11616 copyRegion.dstSubresource.layerCount = 0;
11617 copyRegion.dstOffset.x = 0;
11618 copyRegion.dstOffset.y = 0;
11619 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011620 copyRegion.extent.width = 1;
11621 copyRegion.extent.height = 1;
11622 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011623 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11624 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011625 EndCommandBuffer();
11626
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011627 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011628
Chia-I Wuf7458c52015-10-26 21:10:41 +080011629 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011630 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011631 vkFreeMemory(m_device->device(), srcMem, NULL);
11632 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011633}
11634
Karl Schultz6addd812016-02-02 17:17:23 -070011635TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11636 VkResult err;
11637 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011638
Karl Schultz6addd812016-02-02 17:17:23 -070011639 m_errorMonitor->SetDesiredFailureMsg(
11640 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011641 "vkCmdResolveImage called with source sample count less than 2.");
11642
Mike Stroyana3082432015-09-25 13:39:21 -060011643 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011644
11645 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011646 VkImage srcImage;
11647 VkImage dstImage;
11648 VkDeviceMemory srcMem;
11649 VkDeviceMemory destMem;
11650 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011651
11652 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011653 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11654 image_create_info.pNext = NULL;
11655 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11656 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11657 image_create_info.extent.width = 32;
11658 image_create_info.extent.height = 1;
11659 image_create_info.extent.depth = 1;
11660 image_create_info.mipLevels = 1;
11661 image_create_info.arrayLayers = 1;
11662 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11663 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11664 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11665 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011666
Karl Schultz6addd812016-02-02 17:17:23 -070011667 err =
11668 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011669 ASSERT_VK_SUCCESS(err);
11670
Karl Schultz6addd812016-02-02 17:17:23 -070011671 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011672
Karl Schultz6addd812016-02-02 17:17:23 -070011673 err =
11674 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011675 ASSERT_VK_SUCCESS(err);
11676
11677 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011678 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011679 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11680 memAlloc.pNext = NULL;
11681 memAlloc.allocationSize = 0;
11682 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011683
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011684 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011685 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011686 pass =
11687 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011688 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011689 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011690 ASSERT_VK_SUCCESS(err);
11691
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011692 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011693 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011694 pass =
11695 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011696 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011697 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011698 ASSERT_VK_SUCCESS(err);
11699
11700 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11701 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011702 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011703 ASSERT_VK_SUCCESS(err);
11704
11705 BeginCommandBuffer();
11706 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011707 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11708 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011709 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011710 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011711 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011712 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011713 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011714 resolveRegion.srcOffset.x = 0;
11715 resolveRegion.srcOffset.y = 0;
11716 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011717 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011718 resolveRegion.dstSubresource.mipLevel = 0;
11719 resolveRegion.dstSubresource.baseArrayLayer = 0;
11720 resolveRegion.dstSubresource.layerCount = 0;
11721 resolveRegion.dstOffset.x = 0;
11722 resolveRegion.dstOffset.y = 0;
11723 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011724 resolveRegion.extent.width = 1;
11725 resolveRegion.extent.height = 1;
11726 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011727 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11728 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011729 EndCommandBuffer();
11730
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011731 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011732
Chia-I Wuf7458c52015-10-26 21:10:41 +080011733 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011734 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011735 vkFreeMemory(m_device->device(), srcMem, NULL);
11736 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011737}
11738
Karl Schultz6addd812016-02-02 17:17:23 -070011739TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11740 VkResult err;
11741 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011742
Karl Schultz6addd812016-02-02 17:17:23 -070011743 m_errorMonitor->SetDesiredFailureMsg(
11744 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011745 "vkCmdResolveImage called with dest sample count greater than 1.");
11746
Mike Stroyana3082432015-09-25 13:39:21 -060011747 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011748
Chris Forbesa7530692016-05-08 12:35:39 +120011749 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011750 VkImage srcImage;
11751 VkImage dstImage;
11752 VkDeviceMemory srcMem;
11753 VkDeviceMemory destMem;
11754 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011755
11756 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011757 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11758 image_create_info.pNext = NULL;
11759 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11760 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11761 image_create_info.extent.width = 32;
11762 image_create_info.extent.height = 1;
11763 image_create_info.extent.depth = 1;
11764 image_create_info.mipLevels = 1;
11765 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120011766 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070011767 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11768 // Note: Some implementations expect color attachment usage for any
11769 // multisample surface
11770 image_create_info.usage =
11771 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11772 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011773
Karl Schultz6addd812016-02-02 17:17:23 -070011774 err =
11775 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011776 ASSERT_VK_SUCCESS(err);
11777
Karl Schultz6addd812016-02-02 17:17:23 -070011778 // Note: Some implementations expect color attachment usage for any
11779 // multisample surface
11780 image_create_info.usage =
11781 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011782
Karl Schultz6addd812016-02-02 17:17:23 -070011783 err =
11784 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011785 ASSERT_VK_SUCCESS(err);
11786
11787 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011788 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011789 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11790 memAlloc.pNext = NULL;
11791 memAlloc.allocationSize = 0;
11792 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011793
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011794 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011795 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011796 pass =
11797 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011798 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011799 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011800 ASSERT_VK_SUCCESS(err);
11801
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011802 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011803 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011804 pass =
11805 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011806 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011807 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011808 ASSERT_VK_SUCCESS(err);
11809
11810 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11811 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011812 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011813 ASSERT_VK_SUCCESS(err);
11814
11815 BeginCommandBuffer();
11816 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011817 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11818 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011819 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011820 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011821 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011822 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011823 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011824 resolveRegion.srcOffset.x = 0;
11825 resolveRegion.srcOffset.y = 0;
11826 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011827 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011828 resolveRegion.dstSubresource.mipLevel = 0;
11829 resolveRegion.dstSubresource.baseArrayLayer = 0;
11830 resolveRegion.dstSubresource.layerCount = 0;
11831 resolveRegion.dstOffset.x = 0;
11832 resolveRegion.dstOffset.y = 0;
11833 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011834 resolveRegion.extent.width = 1;
11835 resolveRegion.extent.height = 1;
11836 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011837 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11838 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011839 EndCommandBuffer();
11840
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011841 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011842
Chia-I Wuf7458c52015-10-26 21:10:41 +080011843 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011844 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011845 vkFreeMemory(m_device->device(), srcMem, NULL);
11846 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011847}
11848
Karl Schultz6addd812016-02-02 17:17:23 -070011849TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
11850 VkResult err;
11851 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011852
Karl Schultz6addd812016-02-02 17:17:23 -070011853 m_errorMonitor->SetDesiredFailureMsg(
11854 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011855 "vkCmdResolveImage called with unmatched source and dest formats.");
11856
Mike Stroyana3082432015-09-25 13:39:21 -060011857 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011858
11859 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011860 VkImage srcImage;
11861 VkImage dstImage;
11862 VkDeviceMemory srcMem;
11863 VkDeviceMemory destMem;
11864 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011865
11866 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11868 image_create_info.pNext = NULL;
11869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11870 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11871 image_create_info.extent.width = 32;
11872 image_create_info.extent.height = 1;
11873 image_create_info.extent.depth = 1;
11874 image_create_info.mipLevels = 1;
11875 image_create_info.arrayLayers = 1;
11876 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11877 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11878 // Note: Some implementations expect color attachment usage for any
11879 // multisample surface
11880 image_create_info.usage =
11881 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11882 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011883
Karl Schultz6addd812016-02-02 17:17:23 -070011884 err =
11885 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011886 ASSERT_VK_SUCCESS(err);
11887
Karl Schultz6addd812016-02-02 17:17:23 -070011888 // Set format to something other than source image
11889 image_create_info.format = VK_FORMAT_R32_SFLOAT;
11890 // Note: Some implementations expect color attachment usage for any
11891 // multisample surface
11892 image_create_info.usage =
11893 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11894 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011895
Karl Schultz6addd812016-02-02 17:17:23 -070011896 err =
11897 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011898 ASSERT_VK_SUCCESS(err);
11899
11900 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011901 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011902 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11903 memAlloc.pNext = NULL;
11904 memAlloc.allocationSize = 0;
11905 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011906
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011907 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011908 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011909 pass =
11910 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011911 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011912 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011913 ASSERT_VK_SUCCESS(err);
11914
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011915 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011916 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011917 pass =
11918 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011919 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011920 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011921 ASSERT_VK_SUCCESS(err);
11922
11923 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11924 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011925 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011926 ASSERT_VK_SUCCESS(err);
11927
11928 BeginCommandBuffer();
11929 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011930 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11931 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011932 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011933 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011934 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011935 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011936 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011937 resolveRegion.srcOffset.x = 0;
11938 resolveRegion.srcOffset.y = 0;
11939 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011940 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011941 resolveRegion.dstSubresource.mipLevel = 0;
11942 resolveRegion.dstSubresource.baseArrayLayer = 0;
11943 resolveRegion.dstSubresource.layerCount = 0;
11944 resolveRegion.dstOffset.x = 0;
11945 resolveRegion.dstOffset.y = 0;
11946 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011947 resolveRegion.extent.width = 1;
11948 resolveRegion.extent.height = 1;
11949 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011950 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11951 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011952 EndCommandBuffer();
11953
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011954 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011955
Chia-I Wuf7458c52015-10-26 21:10:41 +080011956 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011957 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011958 vkFreeMemory(m_device->device(), srcMem, NULL);
11959 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011960}
11961
Karl Schultz6addd812016-02-02 17:17:23 -070011962TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11963 VkResult err;
11964 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011965
Karl Schultz6addd812016-02-02 17:17:23 -070011966 m_errorMonitor->SetDesiredFailureMsg(
11967 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011968 "vkCmdResolveImage called with unmatched source and dest image types.");
11969
Mike Stroyana3082432015-09-25 13:39:21 -060011970 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011971
11972 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011973 VkImage srcImage;
11974 VkImage dstImage;
11975 VkDeviceMemory srcMem;
11976 VkDeviceMemory destMem;
11977 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011978
11979 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011980 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11981 image_create_info.pNext = NULL;
11982 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11983 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11984 image_create_info.extent.width = 32;
11985 image_create_info.extent.height = 1;
11986 image_create_info.extent.depth = 1;
11987 image_create_info.mipLevels = 1;
11988 image_create_info.arrayLayers = 1;
11989 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11990 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11991 // Note: Some implementations expect color attachment usage for any
11992 // multisample surface
11993 image_create_info.usage =
11994 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11995 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011996
Karl Schultz6addd812016-02-02 17:17:23 -070011997 err =
11998 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011999 ASSERT_VK_SUCCESS(err);
12000
Karl Schultz6addd812016-02-02 17:17:23 -070012001 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12002 // Note: Some implementations expect color attachment usage for any
12003 // multisample surface
12004 image_create_info.usage =
12005 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12006 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012007
Karl Schultz6addd812016-02-02 17:17:23 -070012008 err =
12009 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012010 ASSERT_VK_SUCCESS(err);
12011
12012 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012013 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012014 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12015 memAlloc.pNext = NULL;
12016 memAlloc.allocationSize = 0;
12017 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012018
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012019 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012020 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012021 pass =
12022 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012023 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012024 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012025 ASSERT_VK_SUCCESS(err);
12026
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012027 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012028 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012029 pass =
12030 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012031 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012032 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012033 ASSERT_VK_SUCCESS(err);
12034
12035 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12036 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012037 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012038 ASSERT_VK_SUCCESS(err);
12039
12040 BeginCommandBuffer();
12041 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012042 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12043 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012044 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012045 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012046 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012047 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012048 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012049 resolveRegion.srcOffset.x = 0;
12050 resolveRegion.srcOffset.y = 0;
12051 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012052 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012053 resolveRegion.dstSubresource.mipLevel = 0;
12054 resolveRegion.dstSubresource.baseArrayLayer = 0;
12055 resolveRegion.dstSubresource.layerCount = 0;
12056 resolveRegion.dstOffset.x = 0;
12057 resolveRegion.dstOffset.y = 0;
12058 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012059 resolveRegion.extent.width = 1;
12060 resolveRegion.extent.height = 1;
12061 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012062 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12063 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012064 EndCommandBuffer();
12065
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012066 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012067
Chia-I Wuf7458c52015-10-26 21:10:41 +080012068 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012069 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012070 vkFreeMemory(m_device->device(), srcMem, NULL);
12071 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012072}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012073
Karl Schultz6addd812016-02-02 17:17:23 -070012074TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012075 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012076 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12077 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012078 // The image format check comes 2nd in validation so we trigger it first,
12079 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012080 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012081
Karl Schultz6addd812016-02-02 17:17:23 -070012082 m_errorMonitor->SetDesiredFailureMsg(
12083 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012084 "Combination depth/stencil image formats can have only the ");
12085
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012086 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012087
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012088 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012089 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12090 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012091
12092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12094 ds_pool_ci.pNext = NULL;
12095 ds_pool_ci.maxSets = 1;
12096 ds_pool_ci.poolSizeCount = 1;
12097 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012098
12099 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012100 err =
12101 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012102 ASSERT_VK_SUCCESS(err);
12103
12104 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012105 dsl_binding.binding = 0;
12106 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12107 dsl_binding.descriptorCount = 1;
12108 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12109 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012110
12111 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012112 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12113 ds_layout_ci.pNext = NULL;
12114 ds_layout_ci.bindingCount = 1;
12115 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012116 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012117 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12118 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012119 ASSERT_VK_SUCCESS(err);
12120
12121 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012122 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012123 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012124 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012125 alloc_info.descriptorPool = ds_pool;
12126 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012127 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12128 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012129 ASSERT_VK_SUCCESS(err);
12130
Karl Schultz6addd812016-02-02 17:17:23 -070012131 VkImage image_bad;
12132 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012133 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012134 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012135 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012136 const int32_t tex_width = 32;
12137 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012138
12139 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012140 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12141 image_create_info.pNext = NULL;
12142 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12143 image_create_info.format = tex_format_bad;
12144 image_create_info.extent.width = tex_width;
12145 image_create_info.extent.height = tex_height;
12146 image_create_info.extent.depth = 1;
12147 image_create_info.mipLevels = 1;
12148 image_create_info.arrayLayers = 1;
12149 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12150 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12151 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12152 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12153 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012154
Karl Schultz6addd812016-02-02 17:17:23 -070012155 err =
12156 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012157 ASSERT_VK_SUCCESS(err);
12158 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012159 image_create_info.usage =
12160 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12161 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12162 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012163 ASSERT_VK_SUCCESS(err);
12164
12165 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012166 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12167 image_view_create_info.image = image_bad;
12168 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12169 image_view_create_info.format = tex_format_bad;
12170 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12171 image_view_create_info.subresourceRange.baseMipLevel = 0;
12172 image_view_create_info.subresourceRange.layerCount = 1;
12173 image_view_create_info.subresourceRange.levelCount = 1;
12174 image_view_create_info.subresourceRange.aspectMask =
12175 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012176
12177 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012178 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12179 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012181 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012182
Chia-I Wuf7458c52015-10-26 21:10:41 +080012183 vkDestroyImage(m_device->device(), image_bad, NULL);
12184 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012187}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012188
12189TEST_F(VkLayerTest, ClearImageErrors) {
12190 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12191 "ClearDepthStencilImage with a color image.");
12192
12193 ASSERT_NO_FATAL_FAILURE(InitState());
12194 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12195
12196 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12197 BeginCommandBuffer();
12198 m_commandBuffer->EndRenderPass();
12199
12200 // Color image
12201 VkClearColorValue clear_color;
12202 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12203 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12204 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12205 const int32_t img_width = 32;
12206 const int32_t img_height = 32;
12207 VkImageCreateInfo image_create_info = {};
12208 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12209 image_create_info.pNext = NULL;
12210 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12211 image_create_info.format = color_format;
12212 image_create_info.extent.width = img_width;
12213 image_create_info.extent.height = img_height;
12214 image_create_info.extent.depth = 1;
12215 image_create_info.mipLevels = 1;
12216 image_create_info.arrayLayers = 1;
12217 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12218 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12219 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12220
12221 vk_testing::Image color_image;
12222 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12223 reqs);
12224
12225 const VkImageSubresourceRange color_range =
12226 vk_testing::Image::subresource_range(image_create_info,
12227 VK_IMAGE_ASPECT_COLOR_BIT);
12228
12229 // Depth/Stencil image
12230 VkClearDepthStencilValue clear_value = {0};
12231 reqs = 0; // don't need HOST_VISIBLE DS image
12232 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12233 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12234 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12235 ds_image_create_info.extent.width = 64;
12236 ds_image_create_info.extent.height = 64;
12237 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12238 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12239
12240 vk_testing::Image ds_image;
12241 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12242 reqs);
12243
12244 const VkImageSubresourceRange ds_range =
12245 vk_testing::Image::subresource_range(ds_image_create_info,
12246 VK_IMAGE_ASPECT_DEPTH_BIT);
12247
12248 m_errorMonitor->SetDesiredFailureMsg(
12249 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12250 "vkCmdClearColorImage called with depth/stencil image.");
12251
12252 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12253 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12254 &color_range);
12255
12256 m_errorMonitor->VerifyFound();
12257
Tony Barbour26434b92016-06-02 09:43:50 -060012258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12259 "vkCmdClearColorImage called with "
12260 "image created without "
12261 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12262
12263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12264 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12265 &color_range);
12266
12267 m_errorMonitor->VerifyFound();
12268
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012269 // Call CmdClearDepthStencilImage with color image
12270 m_errorMonitor->SetDesiredFailureMsg(
12271 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12272 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12273
12274 vkCmdClearDepthStencilImage(
12275 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12276 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12277 &ds_range);
12278
12279 m_errorMonitor->VerifyFound();
12280}
Tobin Ehliscde08892015-09-22 10:11:37 -060012281#endif // IMAGE_TESTS
12282
Tony Barbour300a6082015-04-07 13:44:53 -060012283int main(int argc, char **argv) {
12284 int result;
12285
Cody Northrop8e54a402016-03-08 22:25:52 -070012286#ifdef ANDROID
12287 int vulkanSupport = InitVulkan();
12288 if (vulkanSupport == 0)
12289 return 1;
12290#endif
12291
Tony Barbour300a6082015-04-07 13:44:53 -060012292 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012293 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012294
12295 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12296
12297 result = RUN_ALL_TESTS();
12298
Tony Barbour6918cd52015-04-09 12:58:51 -060012299 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012300 return result;
12301}