blob: ed7aa10b572bf48957501be717cd2c002d35dc3e [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 = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001424 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001425 mmr.memory = mem;
1426 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1427 m_errorMonitor->SetDesiredFailureMsg(
1428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1429 ") is less than Memory Object's offset (");
1430 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1431 m_errorMonitor->VerifyFound();
1432 // Now flush range that oversteps mapped range
1433 vkUnmapMemory(m_device->device(), mem);
1434 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1435 ASSERT_VK_SUCCESS(err);
1436 mmr.offset = 16;
1437 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1438 m_errorMonitor->SetDesiredFailureMsg(
1439 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1440 ") exceeds the Memory Object's upper-bound (");
1441 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1442 m_errorMonitor->VerifyFound();
1443
1444 pass =
1445 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1446 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1447 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1448 if (!pass) {
1449 vkFreeMemory(m_device->device(), mem, NULL);
1450 vkDestroyBuffer(m_device->device(), buffer, NULL);
1451 return;
1452 }
1453 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1454 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1455
1456 vkDestroyBuffer(m_device->device(), buffer, NULL);
1457 vkFreeMemory(m_device->device(), mem, NULL);
1458}
1459
Ian Elliott1c32c772016-04-28 14:47:13 -06001460TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1461 VkResult err;
1462 bool pass;
1463
Ian Elliott489eec02016-05-05 14:12:44 -06001464// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1465// following declaration (which is temporarily being moved below):
1466// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001467 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1468 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1469 uint32_t swapchain_image_count = 0;
1470// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1471 uint32_t image_index = 0;
1472// VkPresentInfoKHR present_info = {};
1473
1474 ASSERT_NO_FATAL_FAILURE(InitState());
1475
Ian Elliott3f06ce52016-04-29 14:46:21 -06001476#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1477#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1478 // Use the functions from the VK_KHR_android_surface extension without
1479 // enabling that extension:
1480
1481 // Create a surface:
1482 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483 m_errorMonitor->SetDesiredFailureMsg(
1484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1485 "extension was not enabled for this");
1486 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1487 &surface);
1488 pass = (err != VK_SUCCESS);
1489 ASSERT_TRUE(pass);
1490 m_errorMonitor->VerifyFound();
1491#endif // VK_USE_PLATFORM_ANDROID_KHR
1492
1493
1494#if defined(VK_USE_PLATFORM_MIR_KHR)
1495 // Use the functions from the VK_KHR_mir_surface extension without enabling
1496 // that extension:
1497
1498 // Create a surface:
1499 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001500 m_errorMonitor->SetDesiredFailureMsg(
1501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1502 "extension was not enabled for this");
1503 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1504 pass = (err != VK_SUCCESS);
1505 ASSERT_TRUE(pass);
1506 m_errorMonitor->VerifyFound();
1507
1508 // Tell whether an mir_connection supports presentation:
1509 MirConnection *mir_connection = NULL;
1510 m_errorMonitor->SetDesiredFailureMsg(
1511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1512 "extension was not enabled for this");
1513 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1514 visual_id);
1515 m_errorMonitor->VerifyFound();
1516#endif // VK_USE_PLATFORM_MIR_KHR
1517
1518
1519#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1520 // Use the functions from the VK_KHR_wayland_surface extension without
1521 // enabling that extension:
1522
1523 // Create a surface:
1524 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001525 m_errorMonitor->SetDesiredFailureMsg(
1526 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1527 "extension was not enabled for this");
1528 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1529 &surface);
1530 pass = (err != VK_SUCCESS);
1531 ASSERT_TRUE(pass);
1532 m_errorMonitor->VerifyFound();
1533
1534 // Tell whether an wayland_display supports presentation:
1535 struct wl_display wayland_display = {};
1536 m_errorMonitor->SetDesiredFailureMsg(
1537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1538 "extension was not enabled for this");
1539 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1540 &wayland_display);
1541 m_errorMonitor->VerifyFound();
1542#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001543#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544
1545
1546#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001547// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1548// TO NON-LINUX PLATFORMS:
1549VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 // Use the functions from the VK_KHR_win32_surface extension without
1551 // enabling that extension:
1552
1553 // Create a surface:
1554 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555 m_errorMonitor->SetDesiredFailureMsg(
1556 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1557 "extension was not enabled for this");
1558 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1559 &surface);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001565 m_errorMonitor->SetDesiredFailureMsg(
1566 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1567 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001568 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001570// Set this (for now, until all platforms are supported and tested):
1571#define NEED_TO_TEST_THIS_ON_PLATFORM
1572#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573
1574
Ian Elliott1c32c772016-04-28 14:47:13 -06001575#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001576// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1577// TO NON-LINUX PLATFORMS:
1578VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001579 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1580 // that extension:
1581
1582 // Create a surface:
1583 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 m_errorMonitor->SetDesiredFailureMsg(
1585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1586 "extension was not enabled for this");
1587 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1588 pass = (err != VK_SUCCESS);
1589 ASSERT_TRUE(pass);
1590 m_errorMonitor->VerifyFound();
1591
1592 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001594 xcb_visualid_t visual_id = 0;
1595 m_errorMonitor->SetDesiredFailureMsg(
1596 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1597 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001599 visual_id);
1600 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001601// Set this (for now, until all platforms are supported and tested):
1602#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001603#endif // VK_USE_PLATFORM_XCB_KHR
1604
1605
Ian Elliott12630812016-04-29 14:35:43 -06001606#if defined(VK_USE_PLATFORM_XLIB_KHR)
1607 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
1611 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001612 m_errorMonitor->SetDesiredFailureMsg(
1613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1614 "extension was not enabled for this");
1615 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1616 pass = (err != VK_SUCCESS);
1617 ASSERT_TRUE(pass);
1618 m_errorMonitor->VerifyFound();
1619
1620 // Tell whether an Xlib VisualID supports presentation:
1621 Display *dpy = NULL;
1622 VisualID visual = 0;
1623 m_errorMonitor->SetDesiredFailureMsg(
1624 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1625 "extension was not enabled for this");
1626 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1627 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001628// Set this (for now, until all platforms are supported and tested):
1629#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001630#endif // VK_USE_PLATFORM_XLIB_KHR
1631
1632
Ian Elliott1c32c772016-04-28 14:47:13 -06001633 // Use the functions from the VK_KHR_surface extension without enabling
1634 // that extension:
1635
Ian Elliott489eec02016-05-05 14:12:44 -06001636#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 // Destroy a surface:
1638 m_errorMonitor->SetDesiredFailureMsg(
1639 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1640 "extension was not enabled for this");
1641 vkDestroySurfaceKHR(instance(), surface, NULL);
1642 m_errorMonitor->VerifyFound();
1643
1644 // Check if surface supports presentation:
1645 VkBool32 supported = false;
1646 m_errorMonitor->SetDesiredFailureMsg(
1647 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1648 "extension was not enabled for this");
1649 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface capabilities:
1655 VkSurfaceCapabilitiesKHR capabilities = {};
1656 m_errorMonitor->SetDesiredFailureMsg(
1657 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1658 "extension was not enabled for this");
1659 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1660 &capabilities);
1661 pass = (err != VK_SUCCESS);
1662 ASSERT_TRUE(pass);
1663 m_errorMonitor->VerifyFound();
1664
1665 // Check surface formats:
1666 uint32_t format_count = 0;
1667 VkSurfaceFormatKHR *formats = NULL;
1668 m_errorMonitor->SetDesiredFailureMsg(
1669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1670 "extension was not enabled for this");
1671 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1672 &format_count, formats);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Check surface present modes:
1678 uint32_t present_mode_count = 0;
1679 VkSurfaceFormatKHR *present_modes = NULL;
1680 m_errorMonitor->SetDesiredFailureMsg(
1681 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "extension was not enabled for this");
1683 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1684 &present_mode_count, present_modes);
1685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001688#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001689
1690
1691 // Use the functions from the VK_KHR_swapchain extension without enabling
1692 // that extension:
1693
1694 // Create a swapchain:
1695 m_errorMonitor->SetDesiredFailureMsg(
1696 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1697 "extension was not enabled for this");
1698 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1699 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001700 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1701 NULL, &swapchain);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Get the images from the swapchain:
1707 m_errorMonitor->SetDesiredFailureMsg(
1708 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1709 "extension was not enabled for this");
1710 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1711 &swapchain_image_count, NULL);
1712 pass = (err != VK_SUCCESS);
1713 ASSERT_TRUE(pass);
1714 m_errorMonitor->VerifyFound();
1715
1716 // Try to acquire an image:
1717 m_errorMonitor->SetDesiredFailureMsg(
1718 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1719 "extension was not enabled for this");
1720 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1721 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1722 pass = (err != VK_SUCCESS);
1723 ASSERT_TRUE(pass);
1724 m_errorMonitor->VerifyFound();
1725
1726 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001727 //
1728 // NOTE: Currently can't test this because a real swapchain is needed (as
1729 // opposed to the fake one we created) in order for the layer to lookup the
1730 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001731
1732 // Destroy the swapchain:
1733 m_errorMonitor->SetDesiredFailureMsg(
1734 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1735 "extension was not enabled for this");
1736 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1737 m_errorMonitor->VerifyFound();
1738}
1739
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001741
Dustin Graves6c6d8982016-05-17 10:09:21 -06001742#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001745 VkResult err;
1746 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001747 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1748 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001749 // uint32_t swapchain_image_count = 0;
1750 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1751 // uint32_t image_index = 0;
1752 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753
1754 ASSERT_NO_FATAL_FAILURE(InitState());
1755
1756 // Use the create function from one of the VK_KHR_*_surface extension in
1757 // order to create a surface, testing all known errors in the process,
1758 // before successfully creating a surface:
1759 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1761 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001762 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1763 pass = (err != VK_SUCCESS);
1764 ASSERT_TRUE(pass);
1765 m_errorMonitor->VerifyFound();
1766
1767 // Next, try to create a surface with the wrong
1768 // VkXcbSurfaceCreateInfoKHR::sType:
1769 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1770 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1772 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1774 pass = (err != VK_SUCCESS);
1775 ASSERT_TRUE(pass);
1776 m_errorMonitor->VerifyFound();
1777
Ian Elliott2c1daf52016-05-12 09:41:46 -06001778 // Create a native window, and then correctly create a surface:
1779 xcb_connection_t *connection;
1780 xcb_screen_t *screen;
1781 xcb_window_t xcb_window;
1782 xcb_intern_atom_reply_t *atom_wm_delete_window;
1783
1784 const xcb_setup_t *setup;
1785 xcb_screen_iterator_t iter;
1786 int scr;
1787 uint32_t value_mask, value_list[32];
1788 int width = 1;
1789 int height = 1;
1790
1791 connection = xcb_connect(NULL, &scr);
1792 ASSERT_TRUE(connection != NULL);
1793 setup = xcb_get_setup(connection);
1794 iter = xcb_setup_roots_iterator(setup);
1795 while (scr-- > 0)
1796 xcb_screen_next(&iter);
1797 screen = iter.data;
1798
1799 xcb_window = xcb_generate_id(connection);
1800
1801 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1802 value_list[0] = screen->black_pixel;
1803 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1804 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1805
1806 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1807 screen->root, 0, 0, width, height, 0,
1808 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1809 value_mask, value_list);
1810
1811 /* Magic code that will send notification when window is destroyed */
1812 xcb_intern_atom_cookie_t cookie =
1813 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1814 xcb_intern_atom_reply_t *reply =
1815 xcb_intern_atom_reply(connection, cookie, 0);
1816
1817 xcb_intern_atom_cookie_t cookie2 =
1818 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001819 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001820 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1821 (*reply).atom, 4, 32, 1,
1822 &(*atom_wm_delete_window).atom);
1823 free(reply);
1824
1825 xcb_map_window(connection, xcb_window);
1826
1827 // Force the x/y coordinates to 100,100 results are identical in consecutive
1828 // runs
1829 const uint32_t coords[] = {100, 100};
1830 xcb_configure_window(connection, xcb_window,
1831 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1832
Ian Elliott2c1daf52016-05-12 09:41:46 -06001833 // Finally, try to correctly create a surface:
1834 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1835 xcb_create_info.pNext = NULL;
1836 xcb_create_info.flags = 0;
1837 xcb_create_info.connection = connection;
1838 xcb_create_info.window = xcb_window;
1839 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1840 pass = (err == VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842
Ian Elliott2c1daf52016-05-12 09:41:46 -06001843 // Check if surface supports presentation:
1844
1845 // 1st, do so without having queried the queue families:
1846 VkBool32 supported = false;
1847 // TODO: Get the following error to come out:
1848 m_errorMonitor->SetDesiredFailureMsg(
1849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1850 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1851 "function");
1852 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1853 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001854 // ASSERT_TRUE(pass);
1855 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001856
1857 // Next, query a queue family index that's too large:
1858 m_errorMonitor->SetDesiredFailureMsg(
1859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1860 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001861 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1862 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001863 pass = (err != VK_SUCCESS);
1864 ASSERT_TRUE(pass);
1865 m_errorMonitor->VerifyFound();
1866
1867 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001868 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1869 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001870 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1871 pass = (err == VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873
Ian Elliott2c1daf52016-05-12 09:41:46 -06001874 // Before proceeding, try to create a swapchain without having called
1875 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1876 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1877 swapchain_create_info.pNext = NULL;
1878 swapchain_create_info.flags = 0;
1879 m_errorMonitor->SetDesiredFailureMsg(
1880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1881 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001882 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1883 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001884 pass = (err != VK_SUCCESS);
1885 ASSERT_TRUE(pass);
1886 m_errorMonitor->VerifyFound();
1887
Ian Elliott2c1daf52016-05-12 09:41:46 -06001888 // Get the surface capabilities:
1889 VkSurfaceCapabilitiesKHR surface_capabilities;
1890
1891 // Do so correctly (only error logged by this entrypoint is if the
1892 // extension isn't enabled):
1893 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1894 &surface_capabilities);
1895 pass = (err == VK_SUCCESS);
1896 ASSERT_TRUE(pass);
1897
Ian Elliott2c1daf52016-05-12 09:41:46 -06001898 // Get the surface formats:
1899 uint32_t surface_format_count;
1900
1901 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1903 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001904 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1905 pass = (err == VK_SUCCESS);
1906 ASSERT_TRUE(pass);
1907 m_errorMonitor->VerifyFound();
1908
1909 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1910 // correctly done a 1st try (to get the count):
1911 m_errorMonitor->SetDesiredFailureMsg(
1912 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1913 "but no prior positive value has been seen for");
1914 surface_format_count = 0;
1915 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001916 gpu(), surface, &surface_format_count,
1917 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001918 pass = (err == VK_SUCCESS);
1919 ASSERT_TRUE(pass);
1920 m_errorMonitor->VerifyFound();
1921
1922 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001923 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1924 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001925 pass = (err == VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927
1928 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1930 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001931
1932 // Next, do a 2nd try with surface_format_count being set too high:
1933 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1935 "that is greater than the value");
1936 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001937 surface_formats);
1938 pass = (err == VK_SUCCESS);
1939 ASSERT_TRUE(pass);
1940 m_errorMonitor->VerifyFound();
1941
1942 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001943 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err == VK_SUCCESS);
1946 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001947 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001948 surface_formats);
1949 pass = (err == VK_SUCCESS);
1950 ASSERT_TRUE(pass);
1951
Ian Elliott2c1daf52016-05-12 09:41:46 -06001952 // Get the surface present modes:
1953 uint32_t surface_present_mode_count;
1954
1955 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1957 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001958 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1959 pass = (err == VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
1963 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1964 // correctly done a 1st try (to get the count):
1965 m_errorMonitor->SetDesiredFailureMsg(
1966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1967 "but no prior positive value has been seen for");
1968 surface_present_mode_count = 0;
1969 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001970 gpu(), surface, &surface_present_mode_count,
1971 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001972 pass = (err == VK_SUCCESS);
1973 ASSERT_TRUE(pass);
1974 m_errorMonitor->VerifyFound();
1975
1976 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001977 vkGetPhysicalDeviceSurfacePresentModesKHR(
1978 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001979 pass = (err == VK_SUCCESS);
1980 ASSERT_TRUE(pass);
1981
1982 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001983 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1984 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001985
1986 // Next, do a 2nd try with surface_format_count being set too high:
1987 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1989 "that is greater than the value");
1990 vkGetPhysicalDeviceSurfacePresentModesKHR(
1991 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001992 pass = (err == VK_SUCCESS);
1993 ASSERT_TRUE(pass);
1994 m_errorMonitor->VerifyFound();
1995
1996 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 vkGetPhysicalDeviceSurfacePresentModesKHR(
1998 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 pass = (err == VK_SUCCESS);
2000 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002001 vkGetPhysicalDeviceSurfacePresentModesKHR(
2002 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002003 pass = (err == VK_SUCCESS);
2004 ASSERT_TRUE(pass);
2005
Ian Elliott2c1daf52016-05-12 09:41:46 -06002006 // Create a swapchain:
2007
2008 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2010 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002011 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2012 pass = (err != VK_SUCCESS);
2013 ASSERT_TRUE(pass);
2014 m_errorMonitor->VerifyFound();
2015
2016 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2017 // sType:
2018 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2020 "called with the wrong value for");
2021 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2022 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002023 pass = (err != VK_SUCCESS);
2024 ASSERT_TRUE(pass);
2025 m_errorMonitor->VerifyFound();
2026
2027 // Next, call with a NULL swapchain pointer:
2028 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2029 swapchain_create_info.pNext = NULL;
2030 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2032 "called with NULL pointer");
2033 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2034 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002035 pass = (err != VK_SUCCESS);
2036 ASSERT_TRUE(pass);
2037 m_errorMonitor->VerifyFound();
2038
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002039 // TODO: Enhance swapchain layer so that
2040 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002041
2042 // Next, call with a queue family index that's too large:
2043 uint32_t queueFamilyIndex[2] = {100000, 0};
2044 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2045 swapchain_create_info.queueFamilyIndexCount = 2;
2046 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2047 m_errorMonitor->SetDesiredFailureMsg(
2048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2049 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002050 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2051 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002052 pass = (err != VK_SUCCESS);
2053 ASSERT_TRUE(pass);
2054 m_errorMonitor->VerifyFound();
2055
2056 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2057 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2058 swapchain_create_info.queueFamilyIndexCount = 1;
2059 m_errorMonitor->SetDesiredFailureMsg(
2060 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2061 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2062 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002063 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2064 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002065 pass = (err != VK_SUCCESS);
2066 ASSERT_TRUE(pass);
2067 m_errorMonitor->VerifyFound();
2068
2069 // Next, call with an invalid imageSharingMode:
2070 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2071 swapchain_create_info.queueFamilyIndexCount = 1;
2072 m_errorMonitor->SetDesiredFailureMsg(
2073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2074 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002075 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2076 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002077 pass = (err != VK_SUCCESS);
2078 ASSERT_TRUE(pass);
2079 m_errorMonitor->VerifyFound();
2080 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002081 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2082 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002083 swapchain_create_info.queueFamilyIndexCount = 0;
2084 queueFamilyIndex[0] = 0;
2085 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2086
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002087 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002091 // Destroy the swapchain:
2092
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002093 // TODOs:
2094 //
2095 // - Try destroying the device without first destroying the swapchain
2096 //
2097 // - Try destroying the device without first destroying the surface
2098 //
2099 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002100
2101 // Destroy the surface:
2102 vkDestroySurfaceKHR(instance(), surface, NULL);
2103
Ian Elliott2c1daf52016-05-12 09:41:46 -06002104 // Tear down the window:
2105 xcb_destroy_window(connection, xcb_window);
2106 xcb_disconnect(connection);
2107
2108#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002109 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002110#endif // VK_USE_PLATFORM_XCB_KHR
2111}
2112
Karl Schultz6addd812016-02-02 17:17:23 -07002113TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2114 VkResult err;
2115 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 m_errorMonitor->SetDesiredFailureMsg(
2118 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002119 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2120
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002122
2123 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002124 VkImage image;
2125 VkDeviceMemory mem;
2126 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2129 const int32_t tex_width = 32;
2130 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002131
Tony Barboureb254902015-07-15 12:50:33 -06002132 VkImageCreateInfo image_create_info = {};
2133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002134 image_create_info.pNext = NULL;
2135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2136 image_create_info.format = tex_format;
2137 image_create_info.extent.width = tex_width;
2138 image_create_info.extent.height = tex_height;
2139 image_create_info.extent.depth = 1;
2140 image_create_info.mipLevels = 1;
2141 image_create_info.arrayLayers = 1;
2142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2143 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2145 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002146
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002148 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 mem_alloc.pNext = NULL;
2150 mem_alloc.allocationSize = 0;
2151 // Introduce failure, do NOT set memProps to
2152 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2153 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002154
Chia-I Wuf7458c52015-10-26 21:10:41 +08002155 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002156 ASSERT_VK_SUCCESS(err);
2157
Karl Schultz6addd812016-02-02 17:17:23 -07002158 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002159
Mark Lobodzinski23065352015-05-29 09:32:35 -05002160 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002161
Karl Schultz6addd812016-02-02 17:17:23 -07002162 pass =
2163 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2165 if (!pass) { // If we can't find any unmappable memory this test doesn't
2166 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002167 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002168 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002169 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002170
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002171 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002172 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173 ASSERT_VK_SUCCESS(err);
2174
2175 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002176 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002177 ASSERT_VK_SUCCESS(err);
2178
2179 // Map memory as if to initialize the image
2180 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002181 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2182 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002183
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002184 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002185
Chia-I Wuf7458c52015-10-26 21:10:41 +08002186 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002187 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002188}
2189
Karl Schultz6addd812016-02-02 17:17:23 -07002190TEST_F(VkLayerTest, RebindMemory) {
2191 VkResult err;
2192 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002193
Karl Schultz6addd812016-02-02 17:17:23 -07002194 m_errorMonitor->SetDesiredFailureMsg(
2195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002196 "which has already been bound to mem object");
2197
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002199
2200 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002201 VkImage image;
2202 VkDeviceMemory mem1;
2203 VkDeviceMemory mem2;
2204 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002205
Karl Schultz6addd812016-02-02 17:17:23 -07002206 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2207 const int32_t tex_width = 32;
2208 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002209
Tony Barboureb254902015-07-15 12:50:33 -06002210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2212 image_create_info.pNext = NULL;
2213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2214 image_create_info.format = tex_format;
2215 image_create_info.extent.width = tex_width;
2216 image_create_info.extent.height = tex_height;
2217 image_create_info.extent.depth = 1;
2218 image_create_info.mipLevels = 1;
2219 image_create_info.arrayLayers = 1;
2220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2222 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2223 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002224
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002225 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002226 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2227 mem_alloc.pNext = NULL;
2228 mem_alloc.allocationSize = 0;
2229 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002230
Karl Schultz6addd812016-02-02 17:17:23 -07002231 // Introduce failure, do NOT set memProps to
2232 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002233 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002234 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002235 ASSERT_VK_SUCCESS(err);
2236
Karl Schultz6addd812016-02-02 17:17:23 -07002237 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002238
2239 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002240 pass =
2241 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002242 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002243
2244 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002245 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002246 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002247 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002248 ASSERT_VK_SUCCESS(err);
2249
2250 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002251 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002252 ASSERT_VK_SUCCESS(err);
2253
Karl Schultz6addd812016-02-02 17:17:23 -07002254 // Introduce validation failure, try to bind a different memory object to
2255 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002256 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002259
Chia-I Wuf7458c52015-10-26 21:10:41 +08002260 vkDestroyImage(m_device->device(), image, NULL);
2261 vkFreeMemory(m_device->device(), mem1, NULL);
2262 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002263}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002264
Karl Schultz6addd812016-02-02 17:17:23 -07002265TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002266 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002267
Karl Schultz6addd812016-02-02 17:17:23 -07002268 m_errorMonitor->SetDesiredFailureMsg(
2269 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2270 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002271
2272 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002273 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2274 fenceInfo.pNext = NULL;
2275 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002276
Tony Barbour300a6082015-04-07 13:44:53 -06002277 ASSERT_NO_FATAL_FAILURE(InitState());
2278 ASSERT_NO_FATAL_FAILURE(InitViewport());
2279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2280
Tony Barbourfe3351b2015-07-28 10:17:20 -06002281 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002282 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2283 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002284 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002285
2286 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002287
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002288 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2290 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002291 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002292 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002293 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002294 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002296 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002297 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002298
2299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002300 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002302 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002303}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002304// This is a positive test. We used to expect error in this case but spec now
2305// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002306TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002307 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002308 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002309 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002310 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2311 fenceInfo.pNext = NULL;
2312
Tony Barbour0b4d9562015-04-09 10:48:04 -06002313 ASSERT_NO_FATAL_FAILURE(InitState());
2314 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002315 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002316 VkResult result = vkResetFences(m_device->device(), 1, fences);
2317 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002318
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002319 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002320}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002321
Chris Forbese70b7d32016-06-15 15:49:12 +12002322#if 0
2323TEST_F(VkLayerTest, LongFenceChain)
2324{
2325 m_errorMonitor->ExpectSuccess();
2326
2327 ASSERT_NO_FATAL_FAILURE(InitState());
2328 VkResult err;
2329
2330 std::vector<VkFence> fences;
2331
2332 const int chainLength = 32768;
2333
2334 for (int i = 0; i < chainLength; i++) {
2335 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2336 VkFence fence;
2337 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2338 ASSERT_VK_SUCCESS(err);
2339
2340 fences.push_back(fence);
2341
2342 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2343 0, nullptr, 0, nullptr };
2344 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2345 ASSERT_VK_SUCCESS(err);
2346
2347 }
2348
2349 // BOOM, stack overflow.
2350 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
2351
2352 for (auto fence : fences)
2353 vkDestroyFence(m_device->device(), fence, nullptr);
2354
2355 m_errorMonitor->VerifyNotFound();
2356}
2357#endif
2358
Chris Forbes18127d12016-06-08 16:52:28 +12002359TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2360{
2361 m_errorMonitor->ExpectSuccess();
2362
2363 ASSERT_NO_FATAL_FAILURE(InitState());
2364 VkResult err;
2365
2366 // Record (empty!) command buffer that can be submitted multiple times
2367 // simultaneously.
2368 VkCommandBufferBeginInfo cbbi = {
2369 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2370 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2371 };
2372 m_commandBuffer->BeginCommandBuffer(&cbbi);
2373 m_commandBuffer->EndCommandBuffer();
2374
2375 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2376 VkFence fence;
2377 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2378 ASSERT_VK_SUCCESS(err);
2379
2380 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2381 VkSemaphore s1, s2;
2382 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2383 ASSERT_VK_SUCCESS(err);
2384 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2385 ASSERT_VK_SUCCESS(err);
2386
2387 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2388 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2389 1, &m_commandBuffer->handle(), 1, &s1 };
2390 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2391 ASSERT_VK_SUCCESS(err);
2392
2393 // Submit CB again, signaling s2.
2394 si.pSignalSemaphores = &s2;
2395 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2396 ASSERT_VK_SUCCESS(err);
2397
2398 // Wait for fence.
2399 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2400 ASSERT_VK_SUCCESS(err);
2401
2402 // CB is still in flight from second submission, but semaphore s1 is no
2403 // longer in flight. delete it.
2404 vkDestroySemaphore(m_device->device(), s1, nullptr);
2405
2406 m_errorMonitor->VerifyNotFound();
2407
2408 // Force device idle and clean up remaining objects
2409 vkDeviceWaitIdle(m_device->device());
2410 vkDestroySemaphore(m_device->device(), s2, nullptr);
2411 vkDestroyFence(m_device->device(), fence, nullptr);
2412}
2413
Tobin Ehlis41376e12015-07-03 08:45:14 -06002414TEST_F(VkLayerTest, InvalidUsageBits)
2415{
Tony Barbourf92621a2016-05-02 14:28:12 -06002416 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002417 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002418 "Initialize buffer with wrong usage then perform copy expecting errors "
2419 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002421 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002422
2423 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002424 VkImageObj image(m_device);
2425 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002426 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002427 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2428 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002429
Tony Barbourf92621a2016-05-02 14:28:12 -06002430 VkImageView dsv;
2431 VkImageViewCreateInfo dsvci = {};
2432 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2433 dsvci.image = image.handle();
2434 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2435 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2436 dsvci.subresourceRange.layerCount = 1;
2437 dsvci.subresourceRange.baseMipLevel = 0;
2438 dsvci.subresourceRange.levelCount = 1;
2439 dsvci.subresourceRange.aspectMask =
2440 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002441
Tony Barbourf92621a2016-05-02 14:28:12 -06002442 // Create a view with depth / stencil aspect for image with different usage
2443 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002445 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002446
2447 // Initialize buffer with TRANSFER_DST usage
2448 vk_testing::Buffer buffer;
2449 VkMemoryPropertyFlags reqs = 0;
2450 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2451 VkBufferImageCopy region = {};
2452 region.bufferRowLength = 128;
2453 region.bufferImageHeight = 128;
2454 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2455 region.imageSubresource.layerCount = 1;
2456 region.imageExtent.height = 16;
2457 region.imageExtent.width = 16;
2458 region.imageExtent.depth = 1;
2459
2460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2461 "Invalid usage flag for buffer ");
2462 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2463 // TRANSFER_DST
2464 BeginCommandBuffer();
2465 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2466 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2467 1, &region);
2468 m_errorMonitor->VerifyFound();
2469
2470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2471 "Invalid usage flag for image ");
2472 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2473 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2474 1, &region);
2475 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002476}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002477#endif // MEM_TRACKER_TESTS
2478
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002479#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002480
2481TEST_F(VkLayerTest, LeakAnObject) {
2482 VkResult err;
2483
2484 TEST_DESCRIPTION(
2485 "Create a fence and destroy its device without first destroying the fence.");
2486
2487 // Note that we have to create a new device since destroying the
2488 // framework's device causes Teardown() to fail and just calling Teardown
2489 // will destroy the errorMonitor.
2490
2491 m_errorMonitor->SetDesiredFailureMsg(
2492 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2493 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2494
2495 ASSERT_NO_FATAL_FAILURE(InitState());
2496
2497 const std::vector<VkQueueFamilyProperties> queue_props =
2498 m_device->queue_props;
2499 std::vector<VkDeviceQueueCreateInfo> queue_info;
2500 queue_info.reserve(queue_props.size());
2501 std::vector<std::vector<float>> queue_priorities;
2502 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2503 VkDeviceQueueCreateInfo qi = {};
2504 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2505 qi.pNext = NULL;
2506 qi.queueFamilyIndex = i;
2507 qi.queueCount = queue_props[i].queueCount;
2508 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2509 qi.pQueuePriorities = queue_priorities[i].data();
2510 queue_info.push_back(qi);
2511 }
2512
2513 std::vector<const char *> device_layer_names;
2514 std::vector<const char *> device_extension_names;
2515 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2516 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2517 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2518 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2519 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2520 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2521 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2522
2523 // The sacrificial device object
2524 VkDevice testDevice;
2525 VkDeviceCreateInfo device_create_info = {};
2526 auto features = m_device->phy().features();
2527 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2528 device_create_info.pNext = NULL;
2529 device_create_info.queueCreateInfoCount = queue_info.size();
2530 device_create_info.pQueueCreateInfos = queue_info.data();
2531 device_create_info.enabledLayerCount = device_layer_names.size();
2532 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2533 device_create_info.pEnabledFeatures = &features;
2534 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2535 ASSERT_VK_SUCCESS(err);
2536
2537 VkFence fence;
2538 VkFenceCreateInfo fence_create_info = {};
2539 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2540 fence_create_info.pNext = NULL;
2541 fence_create_info.flags = 0;
2542 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2543 ASSERT_VK_SUCCESS(err);
2544
2545 // Induce failure by not calling vkDestroyFence
2546 vkDestroyDevice(testDevice, NULL);
2547 m_errorMonitor->VerifyFound();
2548}
2549
2550TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2551
2552 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2553 "attempt to delete them from another.");
2554
2555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2556 "FreeCommandBuffers is attempting to free Command Buffer");
2557
2558 VkCommandPool command_pool_one;
2559 VkCommandPool command_pool_two;
2560
2561 VkCommandPoolCreateInfo pool_create_info{};
2562 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2563 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2564 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2565
2566 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2567 &command_pool_one);
2568
2569 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2570 &command_pool_two);
2571
2572 VkCommandBuffer command_buffer[9];
2573 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2574 command_buffer_allocate_info.sType =
2575 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2576 command_buffer_allocate_info.commandPool = command_pool_one;
2577 command_buffer_allocate_info.commandBufferCount = 9;
2578 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2579 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2580 command_buffer);
2581
2582 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2583 &command_buffer[3]);
2584
2585 m_errorMonitor->VerifyFound();
2586
2587 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2588 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2589}
2590
2591TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2592 VkResult err;
2593
2594 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2595 "attempt to delete them from another.");
2596
2597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2598 "FreeDescriptorSets is attempting to free descriptorSet");
2599
2600 ASSERT_NO_FATAL_FAILURE(InitState());
2601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2602
2603 VkDescriptorPoolSize ds_type_count = {};
2604 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2605 ds_type_count.descriptorCount = 1;
2606
2607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2609 ds_pool_ci.pNext = NULL;
2610 ds_pool_ci.flags = 0;
2611 ds_pool_ci.maxSets = 1;
2612 ds_pool_ci.poolSizeCount = 1;
2613 ds_pool_ci.pPoolSizes = &ds_type_count;
2614
2615 VkDescriptorPool ds_pool_one;
2616 err =
2617 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2618 ASSERT_VK_SUCCESS(err);
2619
2620 // Create a second descriptor pool
2621 VkDescriptorPool ds_pool_two;
2622 err =
2623 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2624 ASSERT_VK_SUCCESS(err);
2625
2626 VkDescriptorSetLayoutBinding dsl_binding = {};
2627 dsl_binding.binding = 0;
2628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2629 dsl_binding.descriptorCount = 1;
2630 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2631 dsl_binding.pImmutableSamplers = NULL;
2632
2633 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2634 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2635 ds_layout_ci.pNext = NULL;
2636 ds_layout_ci.bindingCount = 1;
2637 ds_layout_ci.pBindings = &dsl_binding;
2638
2639 VkDescriptorSetLayout ds_layout;
2640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2641 &ds_layout);
2642 ASSERT_VK_SUCCESS(err);
2643
2644 VkDescriptorSet descriptorSet;
2645 VkDescriptorSetAllocateInfo alloc_info = {};
2646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2647 alloc_info.descriptorSetCount = 1;
2648 alloc_info.descriptorPool = ds_pool_one;
2649 alloc_info.pSetLayouts = &ds_layout;
2650 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2651 &descriptorSet);
2652 ASSERT_VK_SUCCESS(err);
2653
2654 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2655
2656 m_errorMonitor->VerifyFound();
2657
2658 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2659 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2660 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2661}
2662
2663TEST_F(VkLayerTest, CreateUnknownObject) {
2664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2665 "Invalid VkImage Object ");
2666
2667 TEST_DESCRIPTION(
2668 "Pass an invalid image object handle into a Vulkan API call.");
2669
2670 ASSERT_NO_FATAL_FAILURE(InitState());
2671
2672 // Pass bogus handle into GetImageMemoryRequirements
2673 VkMemoryRequirements mem_reqs;
2674 uint64_t fakeImageHandle = 0xCADECADE;
2675 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2676
2677 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2678
2679 m_errorMonitor->VerifyFound();
2680}
2681
Karl Schultz6addd812016-02-02 17:17:23 -07002682TEST_F(VkLayerTest, PipelineNotBound) {
2683 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002684
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002685 TEST_DESCRIPTION(
2686 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2687
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002689 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002690
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002691 ASSERT_NO_FATAL_FAILURE(InitState());
2692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002693
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002694 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002695 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2696 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002697
2698 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002699 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2700 ds_pool_ci.pNext = NULL;
2701 ds_pool_ci.maxSets = 1;
2702 ds_pool_ci.poolSizeCount = 1;
2703 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002704
2705 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002706 err =
2707 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002708 ASSERT_VK_SUCCESS(err);
2709
2710 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002711 dsl_binding.binding = 0;
2712 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2713 dsl_binding.descriptorCount = 1;
2714 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2715 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002716
2717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2719 ds_layout_ci.pNext = NULL;
2720 ds_layout_ci.bindingCount = 1;
2721 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002722
2723 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2725 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002726 ASSERT_VK_SUCCESS(err);
2727
2728 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002729 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002730 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002731 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002732 alloc_info.descriptorPool = ds_pool;
2733 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2735 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002736 ASSERT_VK_SUCCESS(err);
2737
2738 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002739 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2740 pipeline_layout_ci.pNext = NULL;
2741 pipeline_layout_ci.setLayoutCount = 1;
2742 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002743
2744 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002745 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2746 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002747 ASSERT_VK_SUCCESS(err);
2748
Mark Youngad779052016-01-06 14:26:04 -07002749 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002750
2751 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002752 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2753 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002754
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002755 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002756
Chia-I Wuf7458c52015-10-26 21:10:41 +08002757 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2758 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2759 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002760}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002761#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002762TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2763 VkResult err;
2764
2765 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2766 "during bind[Buffer|Image]Memory time");
2767
2768 m_errorMonitor->SetDesiredFailureMsg(
2769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2770 "for this object type are not compatible with the memory");
2771
2772 ASSERT_NO_FATAL_FAILURE(InitState());
2773
2774 // Create an image, allocate memory, set a bad typeIndex and then try to
2775 // bind it
2776 VkImage image;
2777 VkDeviceMemory mem;
2778 VkMemoryRequirements mem_reqs;
2779 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2780 const int32_t tex_width = 32;
2781 const int32_t tex_height = 32;
2782
2783 VkImageCreateInfo image_create_info = {};
2784 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2785 image_create_info.pNext = NULL;
2786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2787 image_create_info.format = tex_format;
2788 image_create_info.extent.width = tex_width;
2789 image_create_info.extent.height = tex_height;
2790 image_create_info.extent.depth = 1;
2791 image_create_info.mipLevels = 1;
2792 image_create_info.arrayLayers = 1;
2793 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2794 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2795 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2796 image_create_info.flags = 0;
2797
2798 VkMemoryAllocateInfo mem_alloc = {};
2799 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2800 mem_alloc.pNext = NULL;
2801 mem_alloc.allocationSize = 0;
2802 mem_alloc.memoryTypeIndex = 0;
2803
2804 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2805 ASSERT_VK_SUCCESS(err);
2806
2807 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2808 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002809 // TODO : This is not an ideal way to cause the error and triggers a segF
2810 // on at least one android driver when attempting to Allocate the memory.
2811 // That segF may or may not be a driver bug, but really what we want to do
2812 // here is find a device-supported memory type that is also not supported
2813 // for the particular image we're binding the memory too. If no such
2814 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002815 // Introduce Failure, select likely invalid TypeIndex
2816 mem_alloc.memoryTypeIndex = 31;
2817
2818 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2819 ASSERT_VK_SUCCESS(err);
2820
2821 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2822 (void)err;
2823
2824 m_errorMonitor->VerifyFound();
2825
2826 vkDestroyImage(m_device->device(), image, NULL);
2827 vkFreeMemory(m_device->device(), mem, NULL);
2828}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002829#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002830TEST_F(VkLayerTest, BindInvalidMemory) {
2831 VkResult err;
2832 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002833
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002835 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002836
Tobin Ehlisec598302015-09-15 15:02:17 -06002837 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002838
2839 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002840 VkImage image;
2841 VkDeviceMemory mem;
2842 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002843
Karl Schultz6addd812016-02-02 17:17:23 -07002844 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2845 const int32_t tex_width = 32;
2846 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002847
2848 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2850 image_create_info.pNext = NULL;
2851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2852 image_create_info.format = tex_format;
2853 image_create_info.extent.width = tex_width;
2854 image_create_info.extent.height = tex_height;
2855 image_create_info.extent.depth = 1;
2856 image_create_info.mipLevels = 1;
2857 image_create_info.arrayLayers = 1;
2858 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2859 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2860 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2861 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002862
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002863 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002864 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2865 mem_alloc.pNext = NULL;
2866 mem_alloc.allocationSize = 0;
2867 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002868
Chia-I Wuf7458c52015-10-26 21:10:41 +08002869 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002870 ASSERT_VK_SUCCESS(err);
2871
Karl Schultz6addd812016-02-02 17:17:23 -07002872 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002873
2874 mem_alloc.allocationSize = mem_reqs.size;
2875
Karl Schultz6addd812016-02-02 17:17:23 -07002876 pass =
2877 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002878 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002879
2880 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002881 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002882 ASSERT_VK_SUCCESS(err);
2883
2884 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002885 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002886
2887 // Try to bind free memory that has been freed
2888 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2889 // This may very well return an error.
2890 (void)err;
2891
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002892 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002893
Chia-I Wuf7458c52015-10-26 21:10:41 +08002894 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002895}
2896
Karl Schultz6addd812016-02-02 17:17:23 -07002897TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2898 VkResult err;
2899 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002900
Karl Schultz6addd812016-02-02 17:17:23 -07002901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2902 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002903
Tobin Ehlisec598302015-09-15 15:02:17 -06002904 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002905
Karl Schultz6addd812016-02-02 17:17:23 -07002906 // Create an image object, allocate memory, destroy the object and then try
2907 // to bind it
2908 VkImage image;
2909 VkDeviceMemory mem;
2910 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002911
Karl Schultz6addd812016-02-02 17:17:23 -07002912 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2913 const int32_t tex_width = 32;
2914 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002915
2916 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2918 image_create_info.pNext = NULL;
2919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2920 image_create_info.format = tex_format;
2921 image_create_info.extent.width = tex_width;
2922 image_create_info.extent.height = tex_height;
2923 image_create_info.extent.depth = 1;
2924 image_create_info.mipLevels = 1;
2925 image_create_info.arrayLayers = 1;
2926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2927 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2928 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2929 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002930
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002931 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002932 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2933 mem_alloc.pNext = NULL;
2934 mem_alloc.allocationSize = 0;
2935 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002936
Chia-I Wuf7458c52015-10-26 21:10:41 +08002937 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002938 ASSERT_VK_SUCCESS(err);
2939
Karl Schultz6addd812016-02-02 17:17:23 -07002940 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002941
2942 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002943 pass =
2944 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002945 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002946
2947 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002948 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002949 ASSERT_VK_SUCCESS(err);
2950
2951 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002952 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002953 ASSERT_VK_SUCCESS(err);
2954
2955 // Now Try to bind memory to this destroyed object
2956 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2957 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002958 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002959
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002960 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002961
Chia-I Wuf7458c52015-10-26 21:10:41 +08002962 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002963}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002964
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002965#endif // OBJ_TRACKER_TESTS
2966
Tobin Ehlis0788f522015-05-26 16:11:58 -06002967#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002968
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002969// This is a positive test. No errors are expected.
2970TEST_F(VkLayerTest, StencilLoadOp) {
2971 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2972 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2973 VkResult result = VK_SUCCESS;
2974 VkImageFormatProperties formatProps;
2975 vkGetPhysicalDeviceImageFormatProperties(
2976 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2977 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2978 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2979 0, &formatProps);
2980 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2981 return;
2982 }
2983
2984 ASSERT_NO_FATAL_FAILURE(InitState());
2985 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2986 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2987 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2988 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2989 VkAttachmentDescription att = {};
2990 VkAttachmentReference ref = {};
2991 att.format = depth_stencil_fmt;
2992 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2993 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2994 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2995 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2996 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2997 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2998
2999 VkClearValue clear;
3000 clear.depthStencil.depth = 1.0;
3001 clear.depthStencil.stencil = 0;
3002 ref.attachment = 0;
3003 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3004
3005 VkSubpassDescription subpass = {};
3006 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
3007 subpass.flags = 0;
3008 subpass.inputAttachmentCount = 0;
3009 subpass.pInputAttachments = NULL;
3010 subpass.colorAttachmentCount = 0;
3011 subpass.pColorAttachments = NULL;
3012 subpass.pResolveAttachments = NULL;
3013 subpass.pDepthStencilAttachment = &ref;
3014 subpass.preserveAttachmentCount = 0;
3015 subpass.pPreserveAttachments = NULL;
3016
3017 VkRenderPass rp;
3018 VkRenderPassCreateInfo rp_info = {};
3019 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3020 rp_info.attachmentCount = 1;
3021 rp_info.pAttachments = &att;
3022 rp_info.subpassCount = 1;
3023 rp_info.pSubpasses = &subpass;
3024 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
3025 ASSERT_VK_SUCCESS(result);
3026
3027 VkImageView *depthView = m_depthStencil->BindInfo();
3028 VkFramebufferCreateInfo fb_info = {};
3029 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3030 fb_info.pNext = NULL;
3031 fb_info.renderPass = rp;
3032 fb_info.attachmentCount = 1;
3033 fb_info.pAttachments = depthView;
3034 fb_info.width = 100;
3035 fb_info.height = 100;
3036 fb_info.layers = 1;
3037 VkFramebuffer fb;
3038 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3039 ASSERT_VK_SUCCESS(result);
3040
3041
3042 VkRenderPassBeginInfo rpbinfo = {};
3043 rpbinfo.clearValueCount = 1;
3044 rpbinfo.pClearValues = &clear;
3045 rpbinfo.pNext = NULL;
3046 rpbinfo.renderPass = rp;
3047 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3048 rpbinfo.renderArea.extent.width = 100;
3049 rpbinfo.renderArea.extent.height = 100;
3050 rpbinfo.renderArea.offset.x = 0;
3051 rpbinfo.renderArea.offset.y = 0;
3052 rpbinfo.framebuffer = fb;
3053
3054 VkFence fence = {};
3055 VkFenceCreateInfo fence_ci = {};
3056 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3057 fence_ci.pNext = nullptr;
3058 fence_ci.flags = 0;
3059 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3060 ASSERT_VK_SUCCESS(result);
3061
3062
3063 m_commandBuffer->BeginCommandBuffer();
3064 m_commandBuffer->BeginRenderPass(rpbinfo);
3065 m_commandBuffer->EndRenderPass();
3066 m_commandBuffer->EndCommandBuffer();
3067 m_commandBuffer->QueueCommandBuffer(fence);
3068
3069 VkImageObj destImage(m_device);
3070 destImage.init(100, 100, depth_stencil_fmt,
3071 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3072 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3073 VK_IMAGE_TILING_OPTIMAL, 0);
3074 VkImageMemoryBarrier barrier = {};
3075 VkImageSubresourceRange range;
3076 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3077 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3078 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3079 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3080 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3081 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3082 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3083 barrier.image = m_depthStencil->handle();
3084 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3085 range.baseMipLevel = 0;
3086 range.levelCount = 1;
3087 range.baseArrayLayer = 0;
3088 range.layerCount = 1;
3089 barrier.subresourceRange = range;
3090 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3091 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3092 cmdbuf.BeginCommandBuffer();
3093 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3094 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3095 nullptr, 1, &barrier);
3096 barrier.srcAccessMask = 0;
3097 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3098 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3099 barrier.image = destImage.handle();
3100 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3101 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3102 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3103 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3104 nullptr, 1, &barrier);
3105 VkImageCopy cregion;
3106 cregion.srcSubresource.aspectMask =
3107 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3108 cregion.srcSubresource.mipLevel = 0;
3109 cregion.srcSubresource.baseArrayLayer = 0;
3110 cregion.srcSubresource.layerCount = 1;
3111 cregion.srcOffset.x = 0;
3112 cregion.srcOffset.y = 0;
3113 cregion.srcOffset.z = 0;
3114 cregion.dstSubresource.aspectMask =
3115 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3116 cregion.dstSubresource.mipLevel = 0;
3117 cregion.dstSubresource.baseArrayLayer = 0;
3118 cregion.dstSubresource.layerCount = 1;
3119 cregion.dstOffset.x = 0;
3120 cregion.dstOffset.y = 0;
3121 cregion.dstOffset.z = 0;
3122 cregion.extent.width = 100;
3123 cregion.extent.height = 100;
3124 cregion.extent.depth = 1;
3125 cmdbuf.CopyImage(m_depthStencil->handle(),
3126 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3127 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3128 cmdbuf.EndCommandBuffer();
3129
3130 VkSubmitInfo submit_info;
3131 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3132 submit_info.pNext = NULL;
3133 submit_info.waitSemaphoreCount = 0;
3134 submit_info.pWaitSemaphores = NULL;
3135 submit_info.pWaitDstStageMask = NULL;
3136 submit_info.commandBufferCount = 1;
3137 submit_info.pCommandBuffers = &cmdbuf.handle();
3138 submit_info.signalSemaphoreCount = 0;
3139 submit_info.pSignalSemaphores = NULL;
3140
3141 m_errorMonitor->ExpectSuccess();
3142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3143 m_errorMonitor->VerifyNotFound();
3144
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003145 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003146 vkDestroyFence(m_device->device(), fence, nullptr);
3147 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3148 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3149}
3150
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003151TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3152 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3153 "attachment reference of VK_ATTACHMENT_UNUSED");
3154
3155 ASSERT_NO_FATAL_FAILURE(InitState());
3156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3157
3158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3159 "must not be VK_ATTACHMENT_UNUSED");
3160
3161 VkAttachmentReference color_attach = {};
3162 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3163 color_attach.attachment = 0;
3164 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3165 VkSubpassDescription subpass = {};
3166 subpass.colorAttachmentCount = 1;
3167 subpass.pColorAttachments = &color_attach;
3168 subpass.preserveAttachmentCount = 1;
3169 subpass.pPreserveAttachments = &preserve_attachment;
3170
3171 VkRenderPassCreateInfo rpci = {};
3172 rpci.subpassCount = 1;
3173 rpci.pSubpasses = &subpass;
3174 rpci.attachmentCount = 1;
3175 VkAttachmentDescription attach_desc = {};
3176 attach_desc.format = VK_FORMAT_UNDEFINED;
3177 rpci.pAttachments = &attach_desc;
3178 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3179 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003180 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003181
3182 m_errorMonitor->VerifyFound();
3183
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003184 if (result == VK_SUCCESS) {
3185 vkDestroyRenderPass(m_device->device(), rp, NULL);
3186 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003187}
3188
3189TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3190 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3191 "in the depthStencil attachment point");
3192
3193 ASSERT_NO_FATAL_FAILURE(InitState());
3194 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3195
3196 m_errorMonitor->SetDesiredFailureMsg(
3197 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3198 "conflicts with the image's IMAGE_USAGE flags");
3199
3200 // Create a renderPass with a depth-stencil attachment created with
3201 // IMAGE_USAGE_COLOR_ATTACHMENT
3202 VkAttachmentReference attach = {};
3203 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3204 VkSubpassDescription subpass = {};
3205 // Add our color attachment to pDepthStencilAttachment
3206 subpass.pDepthStencilAttachment = &attach;
3207 VkRenderPassCreateInfo rpci = {};
3208 rpci.subpassCount = 1;
3209 rpci.pSubpasses = &subpass;
3210 rpci.attachmentCount = 1;
3211 VkAttachmentDescription attach_desc = {};
3212 attach_desc.format = VK_FORMAT_UNDEFINED;
3213 rpci.pAttachments = &attach_desc;
3214 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3217 ASSERT_VK_SUCCESS(err);
3218
3219 VkImageView imageView =
3220 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3221 VkFramebufferCreateInfo fb_info = {};
3222 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3223 fb_info.pNext = NULL;
3224 fb_info.renderPass = rp;
3225 fb_info.attachmentCount = 1;
3226 fb_info.pAttachments = &imageView;
3227 fb_info.width = 100;
3228 fb_info.height = 100;
3229 fb_info.layers = 1;
3230
3231 VkFramebuffer fb;
3232 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3233
3234 m_errorMonitor->VerifyFound();
3235
3236 if (err == VK_SUCCESS) {
3237 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3238 }
3239 vkDestroyRenderPass(m_device->device(), rp, NULL);
3240}
3241
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003242// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003243TEST_F(VkLayerTest, WaitEventThenSet) {
3244 TEST_DESCRIPTION(
3245 "Wait on a event then set it after the wait has been submitted.");
3246
Michael Lentine860b0fe2016-05-20 10:14:00 -05003247 m_errorMonitor->ExpectSuccess();
3248
3249 VkEvent event;
3250 VkEventCreateInfo event_create_info{};
3251 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3252 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3253
3254 VkCommandPool command_pool;
3255 VkCommandPoolCreateInfo pool_create_info{};
3256 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3257 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3258 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3259 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3260 &command_pool);
3261
3262 VkCommandBuffer command_buffer;
3263 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3264 command_buffer_allocate_info.sType =
3265 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3266 command_buffer_allocate_info.commandPool = command_pool;
3267 command_buffer_allocate_info.commandBufferCount = 1;
3268 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3269 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3270 &command_buffer);
3271
3272 VkQueue queue = VK_NULL_HANDLE;
3273 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003274 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003275
3276 {
3277 VkCommandBufferBeginInfo begin_info{};
3278 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3279 vkBeginCommandBuffer(command_buffer, &begin_info);
3280
3281 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3282 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3283 nullptr, 0, nullptr);
3284 vkCmdResetEvent(command_buffer, event,
3285 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3286 vkEndCommandBuffer(command_buffer);
3287 }
3288 {
3289 VkSubmitInfo submit_info{};
3290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3291 submit_info.commandBufferCount = 1;
3292 submit_info.pCommandBuffers = &command_buffer;
3293 submit_info.signalSemaphoreCount = 0;
3294 submit_info.pSignalSemaphores = nullptr;
3295 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3296 }
3297 { vkSetEvent(m_device->device(), event); }
3298
3299 vkQueueWaitIdle(queue);
3300
3301 vkDestroyEvent(m_device->device(), event, nullptr);
3302 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3303 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3304
3305 m_errorMonitor->VerifyNotFound();
3306}
Michael Lentine5627e692016-05-20 17:45:02 -05003307// This is a positive test. No errors should be generated.
3308TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3309 TEST_DESCRIPTION(
3310 "Issue a query and copy from it on a second command buffer.");
3311
3312 if ((m_device->queue_props.empty()) ||
3313 (m_device->queue_props[0].queueCount < 2))
3314 return;
3315
3316 m_errorMonitor->ExpectSuccess();
3317
3318 VkQueryPool query_pool;
3319 VkQueryPoolCreateInfo query_pool_create_info{};
3320 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3321 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3322 query_pool_create_info.queryCount = 1;
3323 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3324 &query_pool);
3325
3326 VkCommandPool command_pool;
3327 VkCommandPoolCreateInfo pool_create_info{};
3328 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3329 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3330 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3331 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3332 &command_pool);
3333
3334 VkCommandBuffer command_buffer[2];
3335 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3336 command_buffer_allocate_info.sType =
3337 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3338 command_buffer_allocate_info.commandPool = command_pool;
3339 command_buffer_allocate_info.commandBufferCount = 2;
3340 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3341 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3342 command_buffer);
3343
3344 VkQueue queue = VK_NULL_HANDLE;
3345 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3346 1, &queue);
3347
3348 uint32_t qfi = 0;
3349 VkBufferCreateInfo buff_create_info = {};
3350 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3351 buff_create_info.size = 1024;
3352 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3353 buff_create_info.queueFamilyIndexCount = 1;
3354 buff_create_info.pQueueFamilyIndices = &qfi;
3355
3356 VkResult err;
3357 VkBuffer buffer;
3358 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3359 ASSERT_VK_SUCCESS(err);
3360 VkMemoryAllocateInfo mem_alloc = {};
3361 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3362 mem_alloc.pNext = NULL;
3363 mem_alloc.allocationSize = 1024;
3364 mem_alloc.memoryTypeIndex = 0;
3365
3366 VkMemoryRequirements memReqs;
3367 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3368 bool pass =
3369 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3370 if (!pass) {
3371 vkDestroyBuffer(m_device->device(), buffer, NULL);
3372 return;
3373 }
3374
3375 VkDeviceMemory mem;
3376 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3377 ASSERT_VK_SUCCESS(err);
3378 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3379 ASSERT_VK_SUCCESS(err);
3380
3381 {
3382 VkCommandBufferBeginInfo begin_info{};
3383 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3384 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3385
3386 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3387 vkCmdWriteTimestamp(command_buffer[0],
3388 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3389
3390 vkEndCommandBuffer(command_buffer[0]);
3391
3392 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3393
3394 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3395 0, 0, 0);
3396
3397 vkEndCommandBuffer(command_buffer[1]);
3398 }
3399 {
3400 VkSubmitInfo submit_info{};
3401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3402 submit_info.commandBufferCount = 2;
3403 submit_info.pCommandBuffers = command_buffer;
3404 submit_info.signalSemaphoreCount = 0;
3405 submit_info.pSignalSemaphores = nullptr;
3406 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3407 }
3408
3409 vkQueueWaitIdle(queue);
3410
3411 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3412 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3413 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003414 vkDestroyBuffer(m_device->device(), buffer, NULL);
3415 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003416
3417 m_errorMonitor->VerifyNotFound();
3418}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003419
3420TEST_F(VkLayerTest, ResetEventThenSet) {
3421 TEST_DESCRIPTION(
3422 "Reset an event then set it after the reset has been submitted.");
3423
Michael Lentine860b0fe2016-05-20 10:14:00 -05003424 m_errorMonitor->ExpectSuccess();
3425
3426 VkEvent event;
3427 VkEventCreateInfo event_create_info{};
3428 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3429 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3430
3431 VkCommandPool command_pool;
3432 VkCommandPoolCreateInfo pool_create_info{};
3433 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3434 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3435 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3436 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3437 &command_pool);
3438
3439 VkCommandBuffer command_buffer;
3440 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3441 command_buffer_allocate_info.sType =
3442 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3443 command_buffer_allocate_info.commandPool = command_pool;
3444 command_buffer_allocate_info.commandBufferCount = 1;
3445 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3446 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3447 &command_buffer);
3448
3449 VkQueue queue = VK_NULL_HANDLE;
3450 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003451 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003452
3453 {
3454 VkCommandBufferBeginInfo begin_info{};
3455 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3456 vkBeginCommandBuffer(command_buffer, &begin_info);
3457
3458 vkCmdResetEvent(command_buffer, event,
3459 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3460 vkCmdWaitEvents(command_buffer, 1, &event,
3461 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3462 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3463 nullptr, 0, nullptr);
3464 vkEndCommandBuffer(command_buffer);
3465 }
3466 {
3467 VkSubmitInfo submit_info{};
3468 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3469 submit_info.commandBufferCount = 1;
3470 submit_info.pCommandBuffers = &command_buffer;
3471 submit_info.signalSemaphoreCount = 0;
3472 submit_info.pSignalSemaphores = nullptr;
3473 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3474 }
3475 {
3476 m_errorMonitor->SetDesiredFailureMsg(
3477 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3478 "0x1 that is already in use by a "
3479 "command buffer.");
3480 vkSetEvent(m_device->device(), event);
3481 m_errorMonitor->VerifyFound();
3482 }
3483
3484 vkQueueWaitIdle(queue);
3485
3486 vkDestroyEvent(m_device->device(), event, nullptr);
3487 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3488 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3489}
3490
3491// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003492TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3493 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3494 "run through a Submit & WaitForFences cycle 3 times. This "
3495 "previously revealed a bug so running this positive test "
3496 "to prevent a regression.");
3497 m_errorMonitor->ExpectSuccess();
3498
3499 ASSERT_NO_FATAL_FAILURE(InitState());
3500 VkQueue queue = VK_NULL_HANDLE;
3501 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3502 0, &queue);
3503
3504 static const uint32_t NUM_OBJECTS = 2;
3505 static const uint32_t NUM_FRAMES = 3;
3506 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3507 VkFence fences[NUM_OBJECTS] = {};
3508
3509 VkCommandPool cmd_pool;
3510 VkCommandPoolCreateInfo cmd_pool_ci = {};
3511 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3512 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3513 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3514 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3515 nullptr, &cmd_pool);
3516 ASSERT_VK_SUCCESS(err);
3517
3518 VkCommandBufferAllocateInfo cmd_buf_info = {};
3519 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3520 cmd_buf_info.commandPool = cmd_pool;
3521 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3522 cmd_buf_info.commandBufferCount = 1;
3523
3524 VkFenceCreateInfo fence_ci = {};
3525 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3526 fence_ci.pNext = nullptr;
3527 fence_ci.flags = 0;
3528
3529 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3530 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3531 &cmd_buffers[i]);
3532 ASSERT_VK_SUCCESS(err);
3533 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3534 ASSERT_VK_SUCCESS(err);
3535 }
3536
3537 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003538 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3539 // Create empty cmd buffer
3540 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3541 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003542
Tobin Ehlisf9025162016-05-26 06:55:21 -06003543 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3544 ASSERT_VK_SUCCESS(err);
3545 err = vkEndCommandBuffer(cmd_buffers[obj]);
3546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003547
Tobin Ehlisf9025162016-05-26 06:55:21 -06003548 VkSubmitInfo submit_info = {};
3549 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3550 submit_info.commandBufferCount = 1;
3551 submit_info.pCommandBuffers = &cmd_buffers[obj];
3552 // Submit cmd buffer and wait for fence
3553 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3554 ASSERT_VK_SUCCESS(err);
3555 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3556 UINT64_MAX);
3557 ASSERT_VK_SUCCESS(err);
3558 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3559 ASSERT_VK_SUCCESS(err);
3560 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003561 }
3562 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003563 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3564 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3565 vkDestroyFence(m_device->device(), fences[i], nullptr);
3566 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003567}
3568// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003569TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3570
3571 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3572 "submitted on separate queues followed by a QueueWaitIdle.");
3573
Dustin Graves48458142016-04-29 16:11:55 -06003574 if ((m_device->queue_props.empty()) ||
3575 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003576 return;
3577
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003578 m_errorMonitor->ExpectSuccess();
3579
3580 VkSemaphore semaphore;
3581 VkSemaphoreCreateInfo semaphore_create_info{};
3582 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3583 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3584 &semaphore);
3585
3586 VkCommandPool command_pool;
3587 VkCommandPoolCreateInfo pool_create_info{};
3588 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3589 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3590 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3591 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3592 &command_pool);
3593
3594 VkCommandBuffer command_buffer[2];
3595 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3596 command_buffer_allocate_info.sType =
3597 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3598 command_buffer_allocate_info.commandPool = command_pool;
3599 command_buffer_allocate_info.commandBufferCount = 2;
3600 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3601 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3602 command_buffer);
3603
3604 VkQueue queue = VK_NULL_HANDLE;
3605 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3606 1, &queue);
3607
3608 {
3609 VkCommandBufferBeginInfo begin_info{};
3610 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3611 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3612
3613 vkCmdPipelineBarrier(command_buffer[0],
3614 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3615 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3616 0, nullptr, 0, nullptr);
3617
3618 VkViewport viewport{};
3619 viewport.maxDepth = 1.0f;
3620 viewport.minDepth = 0.0f;
3621 viewport.width = 512;
3622 viewport.height = 512;
3623 viewport.x = 0;
3624 viewport.y = 0;
3625 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3626 vkEndCommandBuffer(command_buffer[0]);
3627 }
3628 {
3629 VkCommandBufferBeginInfo begin_info{};
3630 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3631 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3632
3633 VkViewport viewport{};
3634 viewport.maxDepth = 1.0f;
3635 viewport.minDepth = 0.0f;
3636 viewport.width = 512;
3637 viewport.height = 512;
3638 viewport.x = 0;
3639 viewport.y = 0;
3640 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3641 vkEndCommandBuffer(command_buffer[1]);
3642 }
3643 {
3644 VkSubmitInfo submit_info{};
3645 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3646 submit_info.commandBufferCount = 1;
3647 submit_info.pCommandBuffers = &command_buffer[0];
3648 submit_info.signalSemaphoreCount = 1;
3649 submit_info.pSignalSemaphores = &semaphore;
3650 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3651 }
3652 {
3653 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3654 VkSubmitInfo submit_info{};
3655 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3656 submit_info.commandBufferCount = 1;
3657 submit_info.pCommandBuffers = &command_buffer[1];
3658 submit_info.waitSemaphoreCount = 1;
3659 submit_info.pWaitSemaphores = &semaphore;
3660 submit_info.pWaitDstStageMask = flags;
3661 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3662 }
3663
3664 vkQueueWaitIdle(m_device->m_queue);
3665
3666 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3667 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3668 &command_buffer[0]);
3669 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3670
3671 m_errorMonitor->VerifyNotFound();
3672}
3673
3674// This is a positive test. No errors should be generated.
3675TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3676
3677 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3678 "submitted on separate queues, the second having a fence"
3679 "followed by a QueueWaitIdle.");
3680
Dustin Graves48458142016-04-29 16:11:55 -06003681 if ((m_device->queue_props.empty()) ||
3682 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003683 return;
3684
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003685 m_errorMonitor->ExpectSuccess();
3686
3687 VkFence fence;
3688 VkFenceCreateInfo fence_create_info{};
3689 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3690 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3691
3692 VkSemaphore semaphore;
3693 VkSemaphoreCreateInfo semaphore_create_info{};
3694 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3695 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3696 &semaphore);
3697
3698 VkCommandPool command_pool;
3699 VkCommandPoolCreateInfo pool_create_info{};
3700 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3701 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3702 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3703 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3704 &command_pool);
3705
3706 VkCommandBuffer command_buffer[2];
3707 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3708 command_buffer_allocate_info.sType =
3709 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3710 command_buffer_allocate_info.commandPool = command_pool;
3711 command_buffer_allocate_info.commandBufferCount = 2;
3712 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3713 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3714 command_buffer);
3715
3716 VkQueue queue = VK_NULL_HANDLE;
3717 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3718 1, &queue);
3719
3720 {
3721 VkCommandBufferBeginInfo begin_info{};
3722 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3723 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3724
3725 vkCmdPipelineBarrier(command_buffer[0],
3726 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3727 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3728 0, nullptr, 0, nullptr);
3729
3730 VkViewport viewport{};
3731 viewport.maxDepth = 1.0f;
3732 viewport.minDepth = 0.0f;
3733 viewport.width = 512;
3734 viewport.height = 512;
3735 viewport.x = 0;
3736 viewport.y = 0;
3737 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3738 vkEndCommandBuffer(command_buffer[0]);
3739 }
3740 {
3741 VkCommandBufferBeginInfo begin_info{};
3742 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3743 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3744
3745 VkViewport viewport{};
3746 viewport.maxDepth = 1.0f;
3747 viewport.minDepth = 0.0f;
3748 viewport.width = 512;
3749 viewport.height = 512;
3750 viewport.x = 0;
3751 viewport.y = 0;
3752 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3753 vkEndCommandBuffer(command_buffer[1]);
3754 }
3755 {
3756 VkSubmitInfo submit_info{};
3757 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3758 submit_info.commandBufferCount = 1;
3759 submit_info.pCommandBuffers = &command_buffer[0];
3760 submit_info.signalSemaphoreCount = 1;
3761 submit_info.pSignalSemaphores = &semaphore;
3762 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3763 }
3764 {
3765 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3766 VkSubmitInfo submit_info{};
3767 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3768 submit_info.commandBufferCount = 1;
3769 submit_info.pCommandBuffers = &command_buffer[1];
3770 submit_info.waitSemaphoreCount = 1;
3771 submit_info.pWaitSemaphores = &semaphore;
3772 submit_info.pWaitDstStageMask = flags;
3773 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3774 }
3775
3776 vkQueueWaitIdle(m_device->m_queue);
3777
3778 vkDestroyFence(m_device->device(), fence, nullptr);
3779 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3780 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3781 &command_buffer[0]);
3782 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3783
3784 m_errorMonitor->VerifyNotFound();
3785}
3786
3787// This is a positive test. No errors should be generated.
3788TEST_F(VkLayerTest,
3789 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3790
3791 TEST_DESCRIPTION(
3792 "Two command buffers, each in a separate QueueSubmit call "
3793 "submitted on separate queues, the second having a fence"
3794 "followed by two consecutive WaitForFences calls on the same fence.");
3795
Dustin Graves48458142016-04-29 16:11:55 -06003796 if ((m_device->queue_props.empty()) ||
3797 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003798 return;
3799
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003800 m_errorMonitor->ExpectSuccess();
3801
3802 VkFence fence;
3803 VkFenceCreateInfo fence_create_info{};
3804 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3805 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3806
3807 VkSemaphore semaphore;
3808 VkSemaphoreCreateInfo semaphore_create_info{};
3809 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3810 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3811 &semaphore);
3812
3813 VkCommandPool command_pool;
3814 VkCommandPoolCreateInfo pool_create_info{};
3815 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3816 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3817 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3818 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3819 &command_pool);
3820
3821 VkCommandBuffer command_buffer[2];
3822 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3823 command_buffer_allocate_info.sType =
3824 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3825 command_buffer_allocate_info.commandPool = command_pool;
3826 command_buffer_allocate_info.commandBufferCount = 2;
3827 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3828 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3829 command_buffer);
3830
3831 VkQueue queue = VK_NULL_HANDLE;
3832 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3833 1, &queue);
3834
3835 {
3836 VkCommandBufferBeginInfo begin_info{};
3837 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3838 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3839
3840 vkCmdPipelineBarrier(command_buffer[0],
3841 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3842 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3843 0, nullptr, 0, nullptr);
3844
3845 VkViewport viewport{};
3846 viewport.maxDepth = 1.0f;
3847 viewport.minDepth = 0.0f;
3848 viewport.width = 512;
3849 viewport.height = 512;
3850 viewport.x = 0;
3851 viewport.y = 0;
3852 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3853 vkEndCommandBuffer(command_buffer[0]);
3854 }
3855 {
3856 VkCommandBufferBeginInfo begin_info{};
3857 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3858 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3859
3860 VkViewport viewport{};
3861 viewport.maxDepth = 1.0f;
3862 viewport.minDepth = 0.0f;
3863 viewport.width = 512;
3864 viewport.height = 512;
3865 viewport.x = 0;
3866 viewport.y = 0;
3867 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3868 vkEndCommandBuffer(command_buffer[1]);
3869 }
3870 {
3871 VkSubmitInfo submit_info{};
3872 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3873 submit_info.commandBufferCount = 1;
3874 submit_info.pCommandBuffers = &command_buffer[0];
3875 submit_info.signalSemaphoreCount = 1;
3876 submit_info.pSignalSemaphores = &semaphore;
3877 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3878 }
3879 {
3880 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3881 VkSubmitInfo submit_info{};
3882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3883 submit_info.commandBufferCount = 1;
3884 submit_info.pCommandBuffers = &command_buffer[1];
3885 submit_info.waitSemaphoreCount = 1;
3886 submit_info.pWaitSemaphores = &semaphore;
3887 submit_info.pWaitDstStageMask = flags;
3888 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3889 }
3890
3891 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3892 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3893
3894 vkDestroyFence(m_device->device(), fence, nullptr);
3895 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3896 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3897 &command_buffer[0]);
3898 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3899
3900 m_errorMonitor->VerifyNotFound();
3901}
3902
3903// This is a positive test. No errors should be generated.
3904TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3905
3906 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3907 "submitted on separate queues, the second having a fence, "
3908 "followed by a WaitForFences call.");
3909
Dustin Graves48458142016-04-29 16:11:55 -06003910 if ((m_device->queue_props.empty()) ||
3911 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003912 return;
3913
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003914 m_errorMonitor->ExpectSuccess();
3915
3916 VkFence fence;
3917 VkFenceCreateInfo fence_create_info{};
3918 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3919 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3920
3921 VkSemaphore semaphore;
3922 VkSemaphoreCreateInfo semaphore_create_info{};
3923 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3924 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3925 &semaphore);
3926
3927 VkCommandPool command_pool;
3928 VkCommandPoolCreateInfo pool_create_info{};
3929 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3930 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3931 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3932 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3933 &command_pool);
3934
3935 VkCommandBuffer command_buffer[2];
3936 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3937 command_buffer_allocate_info.sType =
3938 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3939 command_buffer_allocate_info.commandPool = command_pool;
3940 command_buffer_allocate_info.commandBufferCount = 2;
3941 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3942 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3943 command_buffer);
3944
3945 VkQueue queue = VK_NULL_HANDLE;
3946 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3947 1, &queue);
3948
3949
3950 {
3951 VkCommandBufferBeginInfo begin_info{};
3952 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3953 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3954
3955 vkCmdPipelineBarrier(command_buffer[0],
3956 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3957 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3958 0, nullptr, 0, nullptr);
3959
3960 VkViewport viewport{};
3961 viewport.maxDepth = 1.0f;
3962 viewport.minDepth = 0.0f;
3963 viewport.width = 512;
3964 viewport.height = 512;
3965 viewport.x = 0;
3966 viewport.y = 0;
3967 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3968 vkEndCommandBuffer(command_buffer[0]);
3969 }
3970 {
3971 VkCommandBufferBeginInfo begin_info{};
3972 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3973 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3974
3975 VkViewport viewport{};
3976 viewport.maxDepth = 1.0f;
3977 viewport.minDepth = 0.0f;
3978 viewport.width = 512;
3979 viewport.height = 512;
3980 viewport.x = 0;
3981 viewport.y = 0;
3982 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3983 vkEndCommandBuffer(command_buffer[1]);
3984 }
3985 {
3986 VkSubmitInfo submit_info{};
3987 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3988 submit_info.commandBufferCount = 1;
3989 submit_info.pCommandBuffers = &command_buffer[0];
3990 submit_info.signalSemaphoreCount = 1;
3991 submit_info.pSignalSemaphores = &semaphore;
3992 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3993 }
3994 {
3995 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3996 VkSubmitInfo submit_info{};
3997 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3998 submit_info.commandBufferCount = 1;
3999 submit_info.pCommandBuffers = &command_buffer[1];
4000 submit_info.waitSemaphoreCount = 1;
4001 submit_info.pWaitSemaphores = &semaphore;
4002 submit_info.pWaitDstStageMask = flags;
4003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4004 }
4005
4006 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4007
4008 vkDestroyFence(m_device->device(), fence, nullptr);
4009 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4010 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4011 &command_buffer[0]);
4012 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4013
4014 m_errorMonitor->VerifyNotFound();
4015}
4016
4017// This is a positive test. No errors should be generated.
4018TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
4019
4020 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4021 "on the same queue, sharing a signal/wait semaphore, the "
4022 "second having a fence, "
4023 "followed by a WaitForFences call.");
4024
4025 m_errorMonitor->ExpectSuccess();
4026
4027 VkFence fence;
4028 VkFenceCreateInfo fence_create_info{};
4029 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4030 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4031
4032 VkSemaphore semaphore;
4033 VkSemaphoreCreateInfo semaphore_create_info{};
4034 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4035 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4036 &semaphore);
4037
4038 VkCommandPool command_pool;
4039 VkCommandPoolCreateInfo pool_create_info{};
4040 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4041 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4042 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4043 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4044 &command_pool);
4045
4046 VkCommandBuffer command_buffer[2];
4047 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4048 command_buffer_allocate_info.sType =
4049 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4050 command_buffer_allocate_info.commandPool = command_pool;
4051 command_buffer_allocate_info.commandBufferCount = 2;
4052 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4053 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4054 command_buffer);
4055
4056 {
4057 VkCommandBufferBeginInfo begin_info{};
4058 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4059 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4060
4061 vkCmdPipelineBarrier(command_buffer[0],
4062 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4063 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4064 0, nullptr, 0, nullptr);
4065
4066 VkViewport viewport{};
4067 viewport.maxDepth = 1.0f;
4068 viewport.minDepth = 0.0f;
4069 viewport.width = 512;
4070 viewport.height = 512;
4071 viewport.x = 0;
4072 viewport.y = 0;
4073 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4074 vkEndCommandBuffer(command_buffer[0]);
4075 }
4076 {
4077 VkCommandBufferBeginInfo begin_info{};
4078 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4079 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4080
4081 VkViewport viewport{};
4082 viewport.maxDepth = 1.0f;
4083 viewport.minDepth = 0.0f;
4084 viewport.width = 512;
4085 viewport.height = 512;
4086 viewport.x = 0;
4087 viewport.y = 0;
4088 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4089 vkEndCommandBuffer(command_buffer[1]);
4090 }
4091 {
4092 VkSubmitInfo submit_info{};
4093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4094 submit_info.commandBufferCount = 1;
4095 submit_info.pCommandBuffers = &command_buffer[0];
4096 submit_info.signalSemaphoreCount = 1;
4097 submit_info.pSignalSemaphores = &semaphore;
4098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4099 }
4100 {
4101 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4102 VkSubmitInfo submit_info{};
4103 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4104 submit_info.commandBufferCount = 1;
4105 submit_info.pCommandBuffers = &command_buffer[1];
4106 submit_info.waitSemaphoreCount = 1;
4107 submit_info.pWaitSemaphores = &semaphore;
4108 submit_info.pWaitDstStageMask = flags;
4109 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4110 }
4111
4112 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4113
4114 vkDestroyFence(m_device->device(), fence, nullptr);
4115 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4116 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4117 &command_buffer[0]);
4118 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4119
4120 m_errorMonitor->VerifyNotFound();
4121}
4122
4123// This is a positive test. No errors should be generated.
4124TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4125
4126 TEST_DESCRIPTION(
4127 "Two command buffers, each in a separate QueueSubmit call "
4128 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4129 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4130
4131 m_errorMonitor->ExpectSuccess();
4132
4133 VkFence fence;
4134 VkFenceCreateInfo fence_create_info{};
4135 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4136 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4137
4138 VkCommandPool command_pool;
4139 VkCommandPoolCreateInfo pool_create_info{};
4140 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4141 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4142 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4143 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4144 &command_pool);
4145
4146 VkCommandBuffer command_buffer[2];
4147 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4148 command_buffer_allocate_info.sType =
4149 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4150 command_buffer_allocate_info.commandPool = command_pool;
4151 command_buffer_allocate_info.commandBufferCount = 2;
4152 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4153 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4154 command_buffer);
4155
4156 {
4157 VkCommandBufferBeginInfo begin_info{};
4158 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4159 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4160
4161 vkCmdPipelineBarrier(command_buffer[0],
4162 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4163 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4164 0, nullptr, 0, nullptr);
4165
4166 VkViewport viewport{};
4167 viewport.maxDepth = 1.0f;
4168 viewport.minDepth = 0.0f;
4169 viewport.width = 512;
4170 viewport.height = 512;
4171 viewport.x = 0;
4172 viewport.y = 0;
4173 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4174 vkEndCommandBuffer(command_buffer[0]);
4175 }
4176 {
4177 VkCommandBufferBeginInfo begin_info{};
4178 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4179 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4180
4181 VkViewport viewport{};
4182 viewport.maxDepth = 1.0f;
4183 viewport.minDepth = 0.0f;
4184 viewport.width = 512;
4185 viewport.height = 512;
4186 viewport.x = 0;
4187 viewport.y = 0;
4188 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4189 vkEndCommandBuffer(command_buffer[1]);
4190 }
4191 {
4192 VkSubmitInfo submit_info{};
4193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4194 submit_info.commandBufferCount = 1;
4195 submit_info.pCommandBuffers = &command_buffer[0];
4196 submit_info.signalSemaphoreCount = 0;
4197 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4199 }
4200 {
4201 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4202 VkSubmitInfo submit_info{};
4203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4204 submit_info.commandBufferCount = 1;
4205 submit_info.pCommandBuffers = &command_buffer[1];
4206 submit_info.waitSemaphoreCount = 0;
4207 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4208 submit_info.pWaitDstStageMask = flags;
4209 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4210 }
4211
4212 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4213
4214 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4215
4216 vkDestroyFence(m_device->device(), fence, nullptr);
4217 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4218 &command_buffer[0]);
4219 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4220
4221 m_errorMonitor->VerifyNotFound();
4222}
4223
4224// This is a positive test. No errors should be generated.
4225TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4226
4227 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4228 "on the same queue, the second having a fence, followed "
4229 "by a WaitForFences call.");
4230
4231 m_errorMonitor->ExpectSuccess();
4232
4233 VkFence fence;
4234 VkFenceCreateInfo fence_create_info{};
4235 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4236 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4237
4238 VkCommandPool command_pool;
4239 VkCommandPoolCreateInfo pool_create_info{};
4240 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4241 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4242 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4243 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4244 &command_pool);
4245
4246 VkCommandBuffer command_buffer[2];
4247 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4248 command_buffer_allocate_info.sType =
4249 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4250 command_buffer_allocate_info.commandPool = command_pool;
4251 command_buffer_allocate_info.commandBufferCount = 2;
4252 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4253 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4254 command_buffer);
4255
4256 {
4257 VkCommandBufferBeginInfo begin_info{};
4258 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4259 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4260
4261 vkCmdPipelineBarrier(command_buffer[0],
4262 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4263 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4264 0, nullptr, 0, nullptr);
4265
4266 VkViewport viewport{};
4267 viewport.maxDepth = 1.0f;
4268 viewport.minDepth = 0.0f;
4269 viewport.width = 512;
4270 viewport.height = 512;
4271 viewport.x = 0;
4272 viewport.y = 0;
4273 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4274 vkEndCommandBuffer(command_buffer[0]);
4275 }
4276 {
4277 VkCommandBufferBeginInfo begin_info{};
4278 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4279 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4280
4281 VkViewport viewport{};
4282 viewport.maxDepth = 1.0f;
4283 viewport.minDepth = 0.0f;
4284 viewport.width = 512;
4285 viewport.height = 512;
4286 viewport.x = 0;
4287 viewport.y = 0;
4288 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4289 vkEndCommandBuffer(command_buffer[1]);
4290 }
4291 {
4292 VkSubmitInfo submit_info{};
4293 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4294 submit_info.commandBufferCount = 1;
4295 submit_info.pCommandBuffers = &command_buffer[0];
4296 submit_info.signalSemaphoreCount = 0;
4297 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4299 }
4300 {
4301 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4302 VkSubmitInfo submit_info{};
4303 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4304 submit_info.commandBufferCount = 1;
4305 submit_info.pCommandBuffers = &command_buffer[1];
4306 submit_info.waitSemaphoreCount = 0;
4307 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4308 submit_info.pWaitDstStageMask = flags;
4309 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4310 }
4311
4312 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4313
4314 vkDestroyFence(m_device->device(), fence, nullptr);
4315 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4316 &command_buffer[0]);
4317 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4318
4319 m_errorMonitor->VerifyNotFound();
4320}
4321
4322// This is a positive test. No errors should be generated.
4323TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4324
4325 TEST_DESCRIPTION(
4326 "Two command buffers each in a separate SubmitInfo sent in a single "
4327 "QueueSubmit call followed by a WaitForFences call.");
4328
4329 m_errorMonitor->ExpectSuccess();
4330
4331 VkFence fence;
4332 VkFenceCreateInfo fence_create_info{};
4333 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4334 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4335
4336 VkSemaphore semaphore;
4337 VkSemaphoreCreateInfo semaphore_create_info{};
4338 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4339 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4340 &semaphore);
4341
4342 VkCommandPool command_pool;
4343 VkCommandPoolCreateInfo pool_create_info{};
4344 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4345 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4346 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4347 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4348 &command_pool);
4349
4350 VkCommandBuffer command_buffer[2];
4351 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4352 command_buffer_allocate_info.sType =
4353 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4354 command_buffer_allocate_info.commandPool = command_pool;
4355 command_buffer_allocate_info.commandBufferCount = 2;
4356 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4357 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4358 command_buffer);
4359
4360 {
4361 VkCommandBufferBeginInfo begin_info{};
4362 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4363 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4364
4365 vkCmdPipelineBarrier(command_buffer[0],
4366 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4367 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4368 0, nullptr, 0, nullptr);
4369
4370 VkViewport viewport{};
4371 viewport.maxDepth = 1.0f;
4372 viewport.minDepth = 0.0f;
4373 viewport.width = 512;
4374 viewport.height = 512;
4375 viewport.x = 0;
4376 viewport.y = 0;
4377 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4378 vkEndCommandBuffer(command_buffer[0]);
4379 }
4380 {
4381 VkCommandBufferBeginInfo begin_info{};
4382 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4383 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4384
4385 VkViewport viewport{};
4386 viewport.maxDepth = 1.0f;
4387 viewport.minDepth = 0.0f;
4388 viewport.width = 512;
4389 viewport.height = 512;
4390 viewport.x = 0;
4391 viewport.y = 0;
4392 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4393 vkEndCommandBuffer(command_buffer[1]);
4394 }
4395 {
4396 VkSubmitInfo submit_info[2];
4397 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4398
4399 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4400 submit_info[0].pNext = NULL;
4401 submit_info[0].commandBufferCount = 1;
4402 submit_info[0].pCommandBuffers = &command_buffer[0];
4403 submit_info[0].signalSemaphoreCount = 1;
4404 submit_info[0].pSignalSemaphores = &semaphore;
4405 submit_info[0].waitSemaphoreCount = 0;
4406 submit_info[0].pWaitSemaphores = NULL;
4407 submit_info[0].pWaitDstStageMask = 0;
4408
4409 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4410 submit_info[1].pNext = NULL;
4411 submit_info[1].commandBufferCount = 1;
4412 submit_info[1].pCommandBuffers = &command_buffer[1];
4413 submit_info[1].waitSemaphoreCount = 1;
4414 submit_info[1].pWaitSemaphores = &semaphore;
4415 submit_info[1].pWaitDstStageMask = flags;
4416 submit_info[1].signalSemaphoreCount = 0;
4417 submit_info[1].pSignalSemaphores = NULL;
4418 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4419 }
4420
4421 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4422
4423 vkDestroyFence(m_device->device(), fence, nullptr);
4424 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4425 &command_buffer[0]);
4426 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004427 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004428
4429 m_errorMonitor->VerifyNotFound();
4430}
4431
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004432TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004433 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004434 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4435 "state is required but not correctly bound.");
4436
4437 // Dynamic depth bias
4438 m_errorMonitor->SetDesiredFailureMsg(
4439 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4440 "Dynamic depth bias state not set for this command buffer");
4441 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4442 BsoFailDepthBias);
4443 m_errorMonitor->VerifyFound();
4444}
4445
4446TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4447 TEST_DESCRIPTION(
4448 "Run a simple draw calls to validate failure when Line Width dynamic "
4449 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004450
4451 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004452 m_errorMonitor->SetDesiredFailureMsg(
4453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004454 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004455 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4456 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004457 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004458}
4459
4460TEST_F(VkLayerTest, DynamicViewportNotBound) {
4461 TEST_DESCRIPTION(
4462 "Run a simple draw calls to validate failure when Viewport dynamic "
4463 "state is required but not correctly bound.");
4464
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004465 // Dynamic viewport state
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 viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004469 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4470 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004471 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004472}
4473
4474TEST_F(VkLayerTest, DynamicScissorNotBound) {
4475 TEST_DESCRIPTION(
4476 "Run a simple draw calls to validate failure when Scissor dynamic "
4477 "state is required but not correctly bound.");
4478
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004479 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004480 m_errorMonitor->SetDesiredFailureMsg(
4481 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004482 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004483 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4484 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004485 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004486}
4487
Tobin Ehlis21c88352016-05-26 06:15:45 -06004488TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004489 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004490 "Run a simple draw calls to validate failure when Blend Constants "
4491 "dynamic state is required but not correctly bound.");
4492 // Dynamic blend constant state
4493 m_errorMonitor->SetDesiredFailureMsg(
4494 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4495 "Dynamic blend constants state not set for this command buffer");
4496 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4497 BsoFailBlend);
4498 m_errorMonitor->VerifyFound();
4499}
4500
4501TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4502 TEST_DESCRIPTION(
4503 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004504 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004505 if (!m_device->phy().features().depthBounds) {
4506 printf("Device does not support depthBounds test; skipped.\n");
4507 return;
4508 }
4509 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004510 m_errorMonitor->SetDesiredFailureMsg(
4511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004512 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004513 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4514 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004515 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004516}
4517
4518TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4519 TEST_DESCRIPTION(
4520 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4521 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004522 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004523 m_errorMonitor->SetDesiredFailureMsg(
4524 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004525 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004526 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4527 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004528 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004529}
4530
4531TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4532 TEST_DESCRIPTION(
4533 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4534 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004535 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004536 m_errorMonitor->SetDesiredFailureMsg(
4537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004538 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004539 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4540 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004541 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004542}
4543
4544TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4545 TEST_DESCRIPTION(
4546 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4547 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004548 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004549 m_errorMonitor->SetDesiredFailureMsg(
4550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004551 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004552 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4553 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004554 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004555}
4556
Karl Schultz6addd812016-02-02 17:17:23 -07004557TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004558 m_errorMonitor->SetDesiredFailureMsg(
4559 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4560 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4561 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004562
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004563 ASSERT_NO_FATAL_FAILURE(InitState());
4564 ASSERT_NO_FATAL_FAILURE(InitViewport());
4565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4566
Karl Schultz6addd812016-02-02 17:17:23 -07004567 // We luck out b/c by default the framework creates CB w/ the
4568 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004569 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004570 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4571 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004572 EndCommandBuffer();
4573
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004574 // Bypass framework since it does the waits automatically
4575 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004576 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004577 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4578 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004579 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004580 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004581 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004582 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004583 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004584 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004585 submit_info.pSignalSemaphores = NULL;
4586
Chris Forbes40028e22016-06-13 09:59:34 +12004587 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004589
Karl Schultz6addd812016-02-02 17:17:23 -07004590 // Cause validation error by re-submitting cmd buffer that should only be
4591 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004592 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004594 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004595}
4596
Karl Schultz6addd812016-02-02 17:17:23 -07004597TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004598 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004599 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004600
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004602 "Unable to allocate 1 descriptors of "
4603 "type "
4604 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004605
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004606 ASSERT_NO_FATAL_FAILURE(InitState());
4607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004608
Karl Schultz6addd812016-02-02 17:17:23 -07004609 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4610 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004611 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004612 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4613 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004614
4615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4617 ds_pool_ci.pNext = NULL;
4618 ds_pool_ci.flags = 0;
4619 ds_pool_ci.maxSets = 1;
4620 ds_pool_ci.poolSizeCount = 1;
4621 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004622
4623 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004624 err =
4625 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004626 ASSERT_VK_SUCCESS(err);
4627
4628 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004629 dsl_binding.binding = 0;
4630 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4631 dsl_binding.descriptorCount = 1;
4632 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4633 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004634
4635 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004636 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4637 ds_layout_ci.pNext = NULL;
4638 ds_layout_ci.bindingCount = 1;
4639 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004640
4641 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004642 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4643 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004644 ASSERT_VK_SUCCESS(err);
4645
4646 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004647 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004649 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004650 alloc_info.descriptorPool = ds_pool;
4651 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004652 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4653 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004655 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004656
Chia-I Wuf7458c52015-10-26 21:10:41 +08004657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004659}
4660
Karl Schultz6addd812016-02-02 17:17:23 -07004661TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4662 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004663
Karl Schultz6addd812016-02-02 17:17:23 -07004664 m_errorMonitor->SetDesiredFailureMsg(
4665 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4666 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4667 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004668
Tobin Ehlise735c692015-10-08 13:13:50 -06004669 ASSERT_NO_FATAL_FAILURE(InitState());
4670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004671
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004672 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004673 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4674 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004675
4676 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004677 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4678 ds_pool_ci.pNext = NULL;
4679 ds_pool_ci.maxSets = 1;
4680 ds_pool_ci.poolSizeCount = 1;
4681 ds_pool_ci.flags = 0;
4682 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4683 // app can only call vkResetDescriptorPool on this pool.;
4684 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004685
4686 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004687 err =
4688 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004689 ASSERT_VK_SUCCESS(err);
4690
4691 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004692 dsl_binding.binding = 0;
4693 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4694 dsl_binding.descriptorCount = 1;
4695 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4696 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004697
4698 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004699 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4700 ds_layout_ci.pNext = NULL;
4701 ds_layout_ci.bindingCount = 1;
4702 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004703
4704 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004705 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4706 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004707 ASSERT_VK_SUCCESS(err);
4708
4709 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004710 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004711 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004712 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004713 alloc_info.descriptorPool = ds_pool;
4714 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004715 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4716 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004717 ASSERT_VK_SUCCESS(err);
4718
4719 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004720 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004721
Chia-I Wuf7458c52015-10-26 21:10:41 +08004722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4723 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004724}
4725
Karl Schultz6addd812016-02-02 17:17:23 -07004726TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004727 // Attempt to clear Descriptor Pool with bad object.
4728 // ObjectTracker should catch this.
4729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4730 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004731 uint64_t fake_pool_handle = 0xbaad6001;
4732 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4733 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004734 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004735}
4736
Karl Schultz6addd812016-02-02 17:17:23 -07004737TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004738 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4739 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004740 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004741 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004742
4743 uint64_t fake_set_handle = 0xbaad6001;
4744 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004745 VkResult err;
4746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4747 "Invalid VkDescriptorSet Object 0xbaad6001");
4748
4749 ASSERT_NO_FATAL_FAILURE(InitState());
4750
4751 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4752 layout_bindings[0].binding = 0;
4753 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4754 layout_bindings[0].descriptorCount = 1;
4755 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4756 layout_bindings[0].pImmutableSamplers = NULL;
4757
4758 VkDescriptorSetLayout descriptor_set_layout;
4759 VkDescriptorSetLayoutCreateInfo dslci = {};
4760 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4761 dslci.pNext = NULL;
4762 dslci.bindingCount = 1;
4763 dslci.pBindings = layout_bindings;
4764 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004765 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004766
4767 VkPipelineLayout pipeline_layout;
4768 VkPipelineLayoutCreateInfo plci = {};
4769 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4770 plci.pNext = NULL;
4771 plci.setLayoutCount = 1;
4772 plci.pSetLayouts = &descriptor_set_layout;
4773 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004774 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004775
4776 BeginCommandBuffer();
4777 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004778 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004779 m_errorMonitor->VerifyFound();
4780 EndCommandBuffer();
4781 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4782 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004783}
4784
Karl Schultz6addd812016-02-02 17:17:23 -07004785TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004786 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4787 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004788 uint64_t fake_layout_handle = 0xbaad6001;
4789 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4791 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4792
4793 VkPipelineLayout pipeline_layout;
4794 VkPipelineLayoutCreateInfo plci = {};
4795 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4796 plci.pNext = NULL;
4797 plci.setLayoutCount = 1;
4798 plci.pSetLayouts = &bad_layout;
4799 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4800
4801 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004802}
4803
Mark Muellerd4914412016-06-13 17:52:06 -06004804TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4805 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4806 "1) A uniform buffer update must have a valid buffer index."
4807 "2) When using an array of descriptors in a single WriteDescriptor,"
4808 " the descriptor types and stageflags must all be the same."
4809 "3) Immutable Sampler state must match across descriptors");
4810
4811 const char *invalid_BufferInfo_ErrorMessage =
4812 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4813 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4814 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4815 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004816 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004817 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004818 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004819
Mark Muellerd4914412016-06-13 17:52:06 -06004820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4821
4822 ASSERT_NO_FATAL_FAILURE(InitState());
4823 VkDescriptorPoolSize ds_type_count[4] = {};
4824 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4825 ds_type_count[0].descriptorCount = 1;
4826 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4827 ds_type_count[1].descriptorCount = 1;
4828 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4829 ds_type_count[2].descriptorCount = 1;
4830 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4831 ds_type_count[3].descriptorCount = 1;
4832
4833 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4834 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4835 ds_pool_ci.maxSets = 1;
4836 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4837 ds_pool_ci.pPoolSizes = ds_type_count;
4838
4839 VkDescriptorPool ds_pool;
4840 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4841 ASSERT_VK_SUCCESS(err);
4842
Mark Muellerb9896722016-06-16 09:54:29 -06004843 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004844 layout_binding[0].binding = 0;
4845 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4846 layout_binding[0].descriptorCount = 1;
4847 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4848 layout_binding[0].pImmutableSamplers = NULL;
4849
4850 layout_binding[1].binding = 1;
4851 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4852 layout_binding[1].descriptorCount = 1;
4853 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4854 layout_binding[1].pImmutableSamplers = NULL;
4855
4856 VkSamplerCreateInfo sampler_ci = {};
4857 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4858 sampler_ci.pNext = NULL;
4859 sampler_ci.magFilter = VK_FILTER_NEAREST;
4860 sampler_ci.minFilter = VK_FILTER_NEAREST;
4861 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4862 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4863 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4864 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4865 sampler_ci.mipLodBias = 1.0;
4866 sampler_ci.anisotropyEnable = VK_FALSE;
4867 sampler_ci.maxAnisotropy = 1;
4868 sampler_ci.compareEnable = VK_FALSE;
4869 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4870 sampler_ci.minLod = 1.0;
4871 sampler_ci.maxLod = 1.0;
4872 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4873 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4874 VkSampler sampler;
4875
4876 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4877 ASSERT_VK_SUCCESS(err);
4878
4879 layout_binding[2].binding = 2;
4880 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4881 layout_binding[2].descriptorCount = 1;
4882 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4883 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4884
Mark Muellerd4914412016-06-13 17:52:06 -06004885 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4886 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4887 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4888 ds_layout_ci.pBindings = layout_binding;
4889 VkDescriptorSetLayout ds_layout;
4890 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4891 ASSERT_VK_SUCCESS(err);
4892
4893 VkDescriptorSetAllocateInfo alloc_info = {};
4894 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4895 alloc_info.descriptorSetCount = 1;
4896 alloc_info.descriptorPool = ds_pool;
4897 alloc_info.pSetLayouts = &ds_layout;
4898 VkDescriptorSet descriptorSet;
4899 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4900 ASSERT_VK_SUCCESS(err);
4901
4902 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4903 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4904 pipeline_layout_ci.pNext = NULL;
4905 pipeline_layout_ci.setLayoutCount = 1;
4906 pipeline_layout_ci.pSetLayouts = &ds_layout;
4907
4908 VkPipelineLayout pipeline_layout;
4909 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4910 ASSERT_VK_SUCCESS(err);
4911
Mark Mueller5c838ce2016-06-16 09:54:29 -06004912 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4914 descriptor_write.dstSet = descriptorSet;
4915 descriptor_write.dstBinding = 0;
4916 descriptor_write.descriptorCount = 1;
4917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4918
Mark Mueller5c838ce2016-06-16 09:54:29 -06004919 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4921 m_errorMonitor->VerifyFound();
4922
4923 // Create a buffer to update the descriptor with
4924 uint32_t qfi = 0;
4925 VkBufferCreateInfo buffCI = {};
4926 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4927 buffCI.size = 1024;
4928 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4929 buffCI.queueFamilyIndexCount = 1;
4930 buffCI.pQueueFamilyIndices = &qfi;
4931
4932 VkBuffer dyub;
4933 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4934 ASSERT_VK_SUCCESS(err);
4935 VkDescriptorBufferInfo buffInfo = {};
4936 buffInfo.buffer = dyub;
4937 buffInfo.offset = 0;
4938 buffInfo.range = 1024;
4939
4940 descriptor_write.pBufferInfo = &buffInfo;
4941 descriptor_write.descriptorCount = 2;
4942
Mark Mueller5c838ce2016-06-16 09:54:29 -06004943 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4945 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4946 m_errorMonitor->VerifyFound();
4947
Mark Mueller5c838ce2016-06-16 09:54:29 -06004948 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4949 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004950 descriptor_write.dstBinding = 1;
4951 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004952
4953
4954 // Make pImageInfo index non-null to avoid complaints of it missing
4955 VkDescriptorImageInfo imageInfo = {};
4956 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4957 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4959 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4960 m_errorMonitor->VerifyFound();
4961
Mark Muellerd4914412016-06-13 17:52:06 -06004962 vkDestroyBuffer(m_device->device(), dyub, NULL);
4963 vkDestroySampler(m_device->device(), sampler, NULL);
4964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4967}
4968
Karl Schultz6addd812016-02-02 17:17:23 -07004969TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004970 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4971 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004972 // Create a valid cmd buffer
4973 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004974 uint64_t fake_pipeline_handle = 0xbaad6001;
4975 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4977 "Invalid VkPipeline Object 0xbaad6001");
4978 ASSERT_NO_FATAL_FAILURE(InitState());
4979 BeginCommandBuffer();
4980 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4981 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4982 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004983 // Now issue a draw call with no pipeline bound
4984 m_errorMonitor->SetDesiredFailureMsg(
4985 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4986 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004987
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004988 BeginCommandBuffer();
4989 Draw(1, 0, 0, 0);
4990 m_errorMonitor->VerifyFound();
4991 // Finally same check once more but with Dispatch/Compute
4992 m_errorMonitor->SetDesiredFailureMsg(
4993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4994 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004995 BeginCommandBuffer();
4996 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4997 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004998}
4999
Karl Schultz6addd812016-02-02 17:17:23 -07005000TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
5001 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
5002 // CommandBuffer
5003 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005004
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005006 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005007
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005008 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005009 ASSERT_NO_FATAL_FAILURE(InitViewport());
5010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005011 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005012 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5013 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005014
5015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5017 ds_pool_ci.pNext = NULL;
5018 ds_pool_ci.maxSets = 1;
5019 ds_pool_ci.poolSizeCount = 1;
5020 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005021
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005022 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005023 err =
5024 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005025 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005026
Tony Barboureb254902015-07-15 12:50:33 -06005027 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005028 dsl_binding.binding = 0;
5029 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5030 dsl_binding.descriptorCount = 1;
5031 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5032 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005033
Tony Barboureb254902015-07-15 12:50:33 -06005034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5036 ds_layout_ci.pNext = NULL;
5037 ds_layout_ci.bindingCount = 1;
5038 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005039 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005040 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5041 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005042 ASSERT_VK_SUCCESS(err);
5043
5044 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005045 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005047 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005048 alloc_info.descriptorPool = ds_pool;
5049 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5051 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005052 ASSERT_VK_SUCCESS(err);
5053
Tony Barboureb254902015-07-15 12:50:33 -06005054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5056 pipeline_layout_ci.pNext = NULL;
5057 pipeline_layout_ci.setLayoutCount = 1;
5058 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005059
5060 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5062 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005063 ASSERT_VK_SUCCESS(err);
5064
Karl Schultz6addd812016-02-02 17:17:23 -07005065 VkShaderObj vs(m_device, bindStateVertShaderText,
5066 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005067 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005068 // on more devices
5069 VkShaderObj fs(m_device, bindStateFragShaderText,
5070 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005071
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005072 VkPipelineObj pipe(m_device);
5073 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005074 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005075 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005076 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005077
5078 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005079 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5080 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5081 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5082 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5083 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005084
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005085 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005086
Chia-I Wuf7458c52015-10-26 21:10:41 +08005087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5088 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005090}
5091
Karl Schultz6addd812016-02-02 17:17:23 -07005092TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005093 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005094 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005095
Karl Schultz6addd812016-02-02 17:17:23 -07005096 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005097 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5098 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005099
5100 ASSERT_NO_FATAL_FAILURE(InitState());
5101 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005102 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5103 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005104
5105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5107 ds_pool_ci.pNext = NULL;
5108 ds_pool_ci.maxSets = 1;
5109 ds_pool_ci.poolSizeCount = 1;
5110 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005111
5112 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005113 err =
5114 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005115 ASSERT_VK_SUCCESS(err);
5116
5117 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005118 dsl_binding.binding = 0;
5119 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5120 dsl_binding.descriptorCount = 1;
5121 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5122 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005123
5124 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005125 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5126 ds_layout_ci.pNext = NULL;
5127 ds_layout_ci.bindingCount = 1;
5128 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005129 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5131 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005132 ASSERT_VK_SUCCESS(err);
5133
5134 VkDescriptorSet descriptorSet;
5135 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005137 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005138 alloc_info.descriptorPool = ds_pool;
5139 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5141 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005142 ASSERT_VK_SUCCESS(err);
5143
Karl Schultz6addd812016-02-02 17:17:23 -07005144 VkBufferView view =
5145 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005146 VkWriteDescriptorSet descriptor_write;
5147 memset(&descriptor_write, 0, sizeof(descriptor_write));
5148 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5149 descriptor_write.dstSet = descriptorSet;
5150 descriptor_write.dstBinding = 0;
5151 descriptor_write.descriptorCount = 1;
5152 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5153 descriptor_write.pTexelBufferView = &view;
5154
5155 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5156
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005157 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005158
5159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5161}
5162
Karl Schultz6addd812016-02-02 17:17:23 -07005163TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5164 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5165 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005166 // 1. No dynamicOffset supplied
5167 // 2. Too many dynamicOffsets supplied
5168 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005169 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005171 " requires 1 dynamicOffsets, but only "
5172 "0 dynamicOffsets are left in "
5173 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005174
5175 ASSERT_NO_FATAL_FAILURE(InitState());
5176 ASSERT_NO_FATAL_FAILURE(InitViewport());
5177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5178
5179 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005180 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5181 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005182
5183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5185 ds_pool_ci.pNext = NULL;
5186 ds_pool_ci.maxSets = 1;
5187 ds_pool_ci.poolSizeCount = 1;
5188 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005189
5190 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005191 err =
5192 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005193 ASSERT_VK_SUCCESS(err);
5194
5195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005196 dsl_binding.binding = 0;
5197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5198 dsl_binding.descriptorCount = 1;
5199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005201
5202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5204 ds_layout_ci.pNext = NULL;
5205 ds_layout_ci.bindingCount = 1;
5206 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005207 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5209 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005210 ASSERT_VK_SUCCESS(err);
5211
5212 VkDescriptorSet descriptorSet;
5213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005215 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005216 alloc_info.descriptorPool = ds_pool;
5217 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5219 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005220 ASSERT_VK_SUCCESS(err);
5221
5222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5224 pipeline_layout_ci.pNext = NULL;
5225 pipeline_layout_ci.setLayoutCount = 1;
5226 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005227
5228 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5230 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005231 ASSERT_VK_SUCCESS(err);
5232
5233 // Create a buffer to update the descriptor with
5234 uint32_t qfi = 0;
5235 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005236 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5237 buffCI.size = 1024;
5238 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5239 buffCI.queueFamilyIndexCount = 1;
5240 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005241
5242 VkBuffer dyub;
5243 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5244 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005245 // Allocate memory and bind to buffer so we can make it to the appropriate
5246 // error
5247 VkMemoryAllocateInfo mem_alloc = {};
5248 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5249 mem_alloc.pNext = NULL;
5250 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005251 mem_alloc.memoryTypeIndex = 0;
5252
5253 VkMemoryRequirements memReqs;
5254 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5255 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5256 0);
5257 if (!pass) {
5258 vkDestroyBuffer(m_device->device(), dyub, NULL);
5259 return;
5260 }
5261
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005262 VkDeviceMemory mem;
5263 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5264 ASSERT_VK_SUCCESS(err);
5265 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5266 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005267 // Correctly update descriptor to avoid "NOT_UPDATED" error
5268 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005269 buffInfo.buffer = dyub;
5270 buffInfo.offset = 0;
5271 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005272
5273 VkWriteDescriptorSet descriptor_write;
5274 memset(&descriptor_write, 0, sizeof(descriptor_write));
5275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5276 descriptor_write.dstSet = descriptorSet;
5277 descriptor_write.dstBinding = 0;
5278 descriptor_write.descriptorCount = 1;
5279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5280 descriptor_write.pBufferInfo = &buffInfo;
5281
5282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5283
5284 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005285 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5286 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5287 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005288 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005289 uint32_t pDynOff[2] = {512, 756};
5290 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005291 m_errorMonitor->SetDesiredFailureMsg(
5292 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005293 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005294 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5295 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5296 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005297 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005298 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5300 " dynamic offset 512 combined with "
5301 "offset 0 and range 1024 that "
5302 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005303 // Create PSO to be used for draw-time errors below
5304 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005305 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005306 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005307 "out gl_PerVertex { \n"
5308 " vec4 gl_Position;\n"
5309 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005310 "void main(){\n"
5311 " gl_Position = vec4(1);\n"
5312 "}\n";
5313 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005314 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005315 "\n"
5316 "layout(location=0) out vec4 x;\n"
5317 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5318 "void main(){\n"
5319 " x = vec4(bar.y);\n"
5320 "}\n";
5321 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5322 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5323 VkPipelineObj pipe(m_device);
5324 pipe.AddShader(&vs);
5325 pipe.AddShader(&fs);
5326 pipe.AddColorAttachment();
5327 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5328
Karl Schultz6addd812016-02-02 17:17:23 -07005329 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5330 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5331 // This update should succeed, but offset size of 512 will overstep buffer
5332 // /w range 1024 & size 1024
5333 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5334 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5335 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005336 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005337 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005338
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005339 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005340 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005341
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005342 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005343 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005344 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5345}
5346
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005347TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005348 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005349 ASSERT_NO_FATAL_FAILURE(InitState());
5350 ASSERT_NO_FATAL_FAILURE(InitViewport());
5351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5352
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005353 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005354 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005355 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5356 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5357 pipeline_layout_ci.pushConstantRangeCount = 1;
5358 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5359
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005360 //
5361 // Check for invalid push constant ranges in pipeline layouts.
5362 //
5363 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005364 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005365 char const *msg;
5366 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005367
Karl Schultzc81037d2016-05-12 08:11:23 -06005368 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5369 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5370 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5371 "vkCreatePipelineLayout() call has push constants index 0 with "
5372 "size 0."},
5373 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5374 "vkCreatePipelineLayout() call has push constants index 0 with "
5375 "size 1."},
5376 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5377 "vkCreatePipelineLayout() call has push constants index 0 with "
5378 "size 1."},
5379 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5380 "vkCreatePipelineLayout() call has push constants index 0 with "
5381 "size 0."},
5382 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5383 "vkCreatePipelineLayout() call has push constants index 0 with "
5384 "offset 1. Offset must"},
5385 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5386 "vkCreatePipelineLayout() call has push constants index 0 "
5387 "with offset "},
5388 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5389 "vkCreatePipelineLayout() call has push constants "
5390 "index 0 with offset "},
5391 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5392 "vkCreatePipelineLayout() call has push constants index 0 "
5393 "with offset "},
5394 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5395 "vkCreatePipelineLayout() call has push "
5396 "constants index 0 with offset "},
5397 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5398 "vkCreatePipelineLayout() call has push "
5399 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005400 }};
5401
5402 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005403 for (const auto &iter : range_tests) {
5404 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5406 iter.msg);
5407 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5408 NULL, &pipeline_layout);
5409 m_errorMonitor->VerifyFound();
5410 if (VK_SUCCESS == err) {
5411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5412 }
5413 }
5414
5415 // Check for invalid stage flag
5416 pc_range.offset = 0;
5417 pc_range.size = 16;
5418 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005419 m_errorMonitor->SetDesiredFailureMsg(
5420 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005421 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005422 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5423 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005424 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005425 if (VK_SUCCESS == err) {
5426 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5427 }
5428
5429 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005430 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005431 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005432 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005433 char const *msg;
5434 };
5435
Karl Schultzc81037d2016-05-12 08:11:23 -06005436 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005437 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5438 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5439 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5440 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5441 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5442 "vkCreatePipelineLayout() call has push constants with overlapping "
5443 "ranges: 0:[0, 4), 1:[0, 4)"},
5444 {
5445 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5446 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5447 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5448 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5449 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5450 "vkCreatePipelineLayout() call has push constants with "
5451 "overlapping "
5452 "ranges: 3:[12, 20), 4:[16, 20)",
5453 },
5454 {
5455 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5456 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5457 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5458 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5459 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5460 "vkCreatePipelineLayout() call has push constants with "
5461 "overlapping "
5462 "ranges: 0:[16, 20), 1:[12, 20)",
5463 },
5464 {
5465 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5466 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5467 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5468 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5469 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5470 "vkCreatePipelineLayout() call has push constants with "
5471 "overlapping "
5472 "ranges: 0:[16, 20), 3:[12, 20)",
5473 },
5474 {
5475 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5476 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5477 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5478 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5479 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5480 "vkCreatePipelineLayout() call has push constants with "
5481 "overlapping "
5482 "ranges: 0:[16, 20), 2:[4, 100)",
5483 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005484
Karl Schultzc81037d2016-05-12 08:11:23 -06005485 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005486 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005487 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005489 iter.msg);
5490 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5491 NULL, &pipeline_layout);
5492 m_errorMonitor->VerifyFound();
5493 if (VK_SUCCESS == err) {
5494 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5495 }
5496 }
5497
5498 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005499 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5500 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5501 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5502 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5503 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5504 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5505 ""},
5506 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5507 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5508 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5509 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5510 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5511 ""}}};
5512 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005513 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5514 m_errorMonitor->ExpectSuccess();
5515 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5516 NULL, &pipeline_layout);
5517 m_errorMonitor->VerifyNotFound();
5518 if (VK_SUCCESS == err) {
5519 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5520 }
5521 }
5522
5523 //
5524 // CmdPushConstants tests
5525 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005526 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005527
5528 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005529 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5530 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5531 "vkCmdPushConstants() call has push constants with size 0. Size "
5532 "must be greater than zero and a multiple of 4."},
5533 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5534 "vkCmdPushConstants() call has push constants with size 1. Size "
5535 "must be greater than zero and a multiple of 4."},
5536 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5537 "vkCmdPushConstants() call has push constants with size 1. Size "
5538 "must be greater than zero and a multiple of 4."},
5539 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5540 "vkCmdPushConstants() call has push constants with offset 1. "
5541 "Offset must be a multiple of 4."},
5542 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5543 "vkCmdPushConstants() call has push constants with offset 1. "
5544 "Offset must be a multiple of 4."},
5545 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5546 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5547 "0x1 not within flag-matching ranges in pipeline layout"},
5548 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5549 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5550 "0x1 not within flag-matching ranges in pipeline layout"},
5551 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5552 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5553 "0x1 not within flag-matching ranges in pipeline layout"},
5554 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5555 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5556 "0x1 not within flag-matching ranges in pipeline layout"},
5557 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5558 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5559 "any of the ranges in pipeline layout"},
5560 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5561 0, 16},
5562 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5563 "any of the ranges in pipeline layout"},
5564 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005565 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005566 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005567 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005568 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005569 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005570 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005571 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005572 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005573 "vkCmdPushConstants() call has push constants with offset "},
5574 }};
5575
5576 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005577 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005578 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005579 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005580 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005581 pipeline_layout_ci.pushConstantRangeCount =
5582 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005583 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5585 &pipeline_layout);
5586 ASSERT_VK_SUCCESS(err);
5587 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005588 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5590 iter.msg);
5591 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005592 iter.range.stageFlags, iter.range.offset,
5593 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005594 m_errorMonitor->VerifyFound();
5595 }
5596
5597 // Check for invalid stage flag
5598 m_errorMonitor->SetDesiredFailureMsg(
5599 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5600 "vkCmdPushConstants() call has no stageFlags set.");
5601 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005602 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005603 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005604 EndCommandBuffer();
5605 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5606 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005607
Karl Schultzc81037d2016-05-12 08:11:23 -06005608 // overlapping range tests with cmd
5609 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5610 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5611 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5612 "0x1 not within flag-matching ranges in pipeline layout"},
5613 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5614 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5615 "0x1 not within flag-matching ranges in pipeline layout"},
5616 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5617 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5618 "0x1 not within flag-matching ranges in pipeline layout"},
5619 }};
5620 const VkPushConstantRange pc_range3[] = {
5621 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5622 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5623 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5624 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5625 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5626 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5627 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5628 };
5629 pipeline_layout_ci.pushConstantRangeCount =
5630 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5631 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5632 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5633 &pipeline_layout);
5634 ASSERT_VK_SUCCESS(err);
5635 BeginCommandBuffer();
5636 for (const auto &iter : cmd_overlap_tests) {
5637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5638 iter.msg);
5639 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5640 iter.range.stageFlags, iter.range.offset,
5641 iter.range.size, dummy_values);
5642 m_errorMonitor->VerifyFound();
5643 }
5644 EndCommandBuffer();
5645 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5646 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5647
5648 // positive overlapping range tests with cmd
5649 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5650 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5651 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5652 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5653 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5654 }};
5655 const VkPushConstantRange pc_range4[] = {
5656 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5657 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5658 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5659 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5660 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5661 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5662 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5663 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5664 };
5665 pipeline_layout_ci.pushConstantRangeCount =
5666 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5667 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5668 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5669 &pipeline_layout);
5670 ASSERT_VK_SUCCESS(err);
5671 BeginCommandBuffer();
5672 for (const auto &iter : cmd_overlap_tests_pos) {
5673 m_errorMonitor->ExpectSuccess();
5674 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5675 iter.range.stageFlags, iter.range.offset,
5676 iter.range.size, dummy_values);
5677 m_errorMonitor->VerifyNotFound();
5678 }
5679 EndCommandBuffer();
5680 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5682}
5683
Karl Schultz6addd812016-02-02 17:17:23 -07005684TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005685 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005686 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005687
5688 ASSERT_NO_FATAL_FAILURE(InitState());
5689 ASSERT_NO_FATAL_FAILURE(InitViewport());
5690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5691
5692 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5693 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005694 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5695 ds_type_count[0].descriptorCount = 10;
5696 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5697 ds_type_count[1].descriptorCount = 2;
5698 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5699 ds_type_count[2].descriptorCount = 2;
5700 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5701 ds_type_count[3].descriptorCount = 5;
5702 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5703 // type
5704 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5705 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5706 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005707
5708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5710 ds_pool_ci.pNext = NULL;
5711 ds_pool_ci.maxSets = 5;
5712 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5713 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005714
5715 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005716 err =
5717 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005718 ASSERT_VK_SUCCESS(err);
5719
5720 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5721 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005722 dsl_binding[0].binding = 0;
5723 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5724 dsl_binding[0].descriptorCount = 5;
5725 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5726 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005727
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005728 // Create layout identical to set0 layout but w/ different stageFlags
5729 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005730 dsl_fs_stage_only.binding = 0;
5731 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5732 dsl_fs_stage_only.descriptorCount = 5;
5733 dsl_fs_stage_only.stageFlags =
5734 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5735 // bind time
5736 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005737 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005738 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5739 ds_layout_ci.pNext = NULL;
5740 ds_layout_ci.bindingCount = 1;
5741 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005742 static const uint32_t NUM_LAYOUTS = 4;
5743 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005744 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005745 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5746 // layout for error case
5747 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5748 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005749 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005750 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5752 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005753 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005754 dsl_binding[0].binding = 0;
5755 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005756 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005757 dsl_binding[1].binding = 1;
5758 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5759 dsl_binding[1].descriptorCount = 2;
5760 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5761 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005762 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005763 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5765 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005766 ASSERT_VK_SUCCESS(err);
5767 dsl_binding[0].binding = 0;
5768 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005769 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005770 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005771 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5772 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005773 ASSERT_VK_SUCCESS(err);
5774 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005775 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005776 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5777 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005778 ASSERT_VK_SUCCESS(err);
5779
5780 static const uint32_t NUM_SETS = 4;
5781 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5782 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005784 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005785 alloc_info.descriptorPool = ds_pool;
5786 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005787 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5788 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005789 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005790 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005791 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005792 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005793 err =
5794 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005796
5797 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005798 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5799 pipeline_layout_ci.pNext = NULL;
5800 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5801 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005802
5803 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5805 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005806 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005807 // Create pipelineLayout with only one setLayout
5808 pipeline_layout_ci.setLayoutCount = 1;
5809 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5811 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005812 ASSERT_VK_SUCCESS(err);
5813 // Create pipelineLayout with 2 descriptor setLayout at index 0
5814 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5815 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5817 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005818 ASSERT_VK_SUCCESS(err);
5819 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5820 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5821 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005822 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5823 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005824 ASSERT_VK_SUCCESS(err);
5825 // Create pipelineLayout with UB type, but stageFlags for FS only
5826 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5827 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005828 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5829 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005830 ASSERT_VK_SUCCESS(err);
5831 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5832 VkDescriptorSetLayout pl_bad_s0[2] = {};
5833 pl_bad_s0[0] = ds_layout_fs_only;
5834 pl_bad_s0[1] = ds_layout[1];
5835 pipeline_layout_ci.setLayoutCount = 2;
5836 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5837 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5839 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005840 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005841
5842 // Create a buffer to update the descriptor with
5843 uint32_t qfi = 0;
5844 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005845 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5846 buffCI.size = 1024;
5847 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5848 buffCI.queueFamilyIndexCount = 1;
5849 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005850
5851 VkBuffer dyub;
5852 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5853 ASSERT_VK_SUCCESS(err);
5854 // Correctly update descriptor to avoid "NOT_UPDATED" error
5855 static const uint32_t NUM_BUFFS = 5;
5856 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005857 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005858 buffInfo[i].buffer = dyub;
5859 buffInfo[i].offset = 0;
5860 buffInfo[i].range = 1024;
5861 }
Karl Schultz6addd812016-02-02 17:17:23 -07005862 VkImage image;
5863 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5864 const int32_t tex_width = 32;
5865 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005866 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5868 image_create_info.pNext = NULL;
5869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5870 image_create_info.format = tex_format;
5871 image_create_info.extent.width = tex_width;
5872 image_create_info.extent.height = tex_height;
5873 image_create_info.extent.depth = 1;
5874 image_create_info.mipLevels = 1;
5875 image_create_info.arrayLayers = 1;
5876 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5877 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5878 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5879 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005880 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5881 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005882
Karl Schultz6addd812016-02-02 17:17:23 -07005883 VkMemoryRequirements memReqs;
5884 VkDeviceMemory imageMem;
5885 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005886 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005887 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5888 memAlloc.pNext = NULL;
5889 memAlloc.allocationSize = 0;
5890 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005891 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5892 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005893 pass =
5894 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005895 ASSERT_TRUE(pass);
5896 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5897 ASSERT_VK_SUCCESS(err);
5898 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5899 ASSERT_VK_SUCCESS(err);
5900
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005901 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005902 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5903 image_view_create_info.image = image;
5904 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5905 image_view_create_info.format = tex_format;
5906 image_view_create_info.subresourceRange.layerCount = 1;
5907 image_view_create_info.subresourceRange.baseMipLevel = 0;
5908 image_view_create_info.subresourceRange.levelCount = 1;
5909 image_view_create_info.subresourceRange.aspectMask =
5910 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005911
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005912 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005913 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5914 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005915 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005916 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005917 imageInfo[0].imageView = view;
5918 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5919 imageInfo[1].imageView = view;
5920 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005921 imageInfo[2].imageView = view;
5922 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5923 imageInfo[3].imageView = view;
5924 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005925
5926 static const uint32_t NUM_SET_UPDATES = 3;
5927 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5928 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5929 descriptor_write[0].dstSet = descriptorSet[0];
5930 descriptor_write[0].dstBinding = 0;
5931 descriptor_write[0].descriptorCount = 5;
5932 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5933 descriptor_write[0].pBufferInfo = buffInfo;
5934 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5935 descriptor_write[1].dstSet = descriptorSet[1];
5936 descriptor_write[1].dstBinding = 0;
5937 descriptor_write[1].descriptorCount = 2;
5938 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5939 descriptor_write[1].pImageInfo = imageInfo;
5940 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5941 descriptor_write[2].dstSet = descriptorSet[1];
5942 descriptor_write[2].dstBinding = 1;
5943 descriptor_write[2].descriptorCount = 2;
5944 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005945 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005946
5947 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005948
Tobin Ehlis88452832015-12-03 09:40:56 -07005949 // Create PSO to be used for draw-time errors below
5950 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005951 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005952 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005953 "out gl_PerVertex {\n"
5954 " vec4 gl_Position;\n"
5955 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005956 "void main(){\n"
5957 " gl_Position = vec4(1);\n"
5958 "}\n";
5959 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005960 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005961 "\n"
5962 "layout(location=0) out vec4 x;\n"
5963 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5964 "void main(){\n"
5965 " x = vec4(bar.y);\n"
5966 "}\n";
5967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005969 VkPipelineObj pipe(m_device);
5970 pipe.AddShader(&vs);
5971 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005972 pipe.AddColorAttachment();
5973 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005974
5975 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005976
Karl Schultz6addd812016-02-02 17:17:23 -07005977 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5978 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5979 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5980 // of PSO
5981 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5982 // cmd_pipeline.c
5983 // due to the fact that cmd_alloc_dset_data() has not been called in
5984 // cmd_bind_graphics_pipeline()
5985 // TODO : Want to cause various binding incompatibility issues here to test
5986 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005987 // First cause various verify_layout_compatibility() fails
5988 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005989 // verify_set_layout_compatibility fail cases:
5990 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5992 " due to: invalid VkPipelineLayout ");
5993 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5994 VK_PIPELINE_BIND_POINT_GRAPHICS,
5995 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5996 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005997 m_errorMonitor->VerifyFound();
5998
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005999 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07006000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6001 " attempting to bind set to index 1");
6002 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6003 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
6004 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006005 m_errorMonitor->VerifyFound();
6006
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006007 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006008 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6009 // descriptors
6010 m_errorMonitor->SetDesiredFailureMsg(
6011 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006012 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006013 vkCmdBindDescriptorSets(
6014 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6015 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006016 m_errorMonitor->VerifyFound();
6017
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006018 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6019 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07006020 m_errorMonitor->SetDesiredFailureMsg(
6021 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006022 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07006023 vkCmdBindDescriptorSets(
6024 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6025 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006026 m_errorMonitor->VerifyFound();
6027
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006028 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6029 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07006030 m_errorMonitor->SetDesiredFailureMsg(
6031 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006032 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006033 vkCmdBindDescriptorSets(
6034 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6035 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006036 m_errorMonitor->VerifyFound();
6037
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006038 // Cause INFO messages due to disturbing previously bound Sets
6039 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006040 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6041 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6042 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006043 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006044 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006045 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006046 " previously bound as set #0 was disturbed ");
6047 vkCmdBindDescriptorSets(
6048 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6049 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006050 m_errorMonitor->VerifyFound();
6051
Karl Schultz6addd812016-02-02 17:17:23 -07006052 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6053 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6054 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006055 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006057 " newly bound as set #0 so set #1 and "
6058 "any subsequent sets were disturbed ");
6059 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6060 VK_PIPELINE_BIND_POINT_GRAPHICS,
6061 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006062 m_errorMonitor->VerifyFound();
6063
Tobin Ehlis88452832015-12-03 09:40:56 -07006064 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006065 // 1. Error due to not binding required set (we actually use same code as
6066 // above to disturb set0)
6067 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6068 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6069 2, &descriptorSet[0], 0, NULL);
6070 vkCmdBindDescriptorSets(
6071 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6072 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6073 m_errorMonitor->SetDesiredFailureMsg(
6074 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6075 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006076 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006077 m_errorMonitor->VerifyFound();
6078
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006079 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006080 // 2. Error due to bound set not being compatible with PSO's
6081 // VkPipelineLayout (diff stageFlags in this case)
6082 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6083 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6084 2, &descriptorSet[0], 0, NULL);
6085 m_errorMonitor->SetDesiredFailureMsg(
6086 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6087 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006088 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006089 m_errorMonitor->VerifyFound();
6090
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006091 // Remaining clean-up
6092 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006093 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6095 }
6096 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006097 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6098 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006099 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006100 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006102 vkFreeMemory(m_device->device(), imageMem, NULL);
6103 vkDestroyImage(m_device->device(), image, NULL);
6104 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006105}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006106
Karl Schultz6addd812016-02-02 17:17:23 -07006107TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006108
Karl Schultz6addd812016-02-02 17:17:23 -07006109 m_errorMonitor->SetDesiredFailureMsg(
6110 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006111 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006112
6113 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006114 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006115 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006116 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006117
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006118 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006119}
6120
Karl Schultz6addd812016-02-02 17:17:23 -07006121TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6122 VkResult err;
6123 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006124
Karl Schultz6addd812016-02-02 17:17:23 -07006125 m_errorMonitor->SetDesiredFailureMsg(
6126 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006127 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006128
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006129 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006130
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006131 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006132 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006133 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006134 cmd.commandPool = m_commandPool;
6135 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006136 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006137
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006138 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006139 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006140
6141 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006142 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006143 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006144 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006145 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006146 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6147 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006148 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006149
6150 // The error should be caught by validation of the BeginCommandBuffer call
6151 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6152
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006153 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006154 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006155}
6156
Karl Schultz6addd812016-02-02 17:17:23 -07006157TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006158 // Cause error due to Begin while recording CB
6159 // Then cause 2 errors for attempting to reset CB w/o having
6160 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6161 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006163 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006164
6165 ASSERT_NO_FATAL_FAILURE(InitState());
6166
6167 // Calls AllocateCommandBuffers
6168 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6169
Karl Schultz6addd812016-02-02 17:17:23 -07006170 // Force the failure by setting the Renderpass and Framebuffer fields with
6171 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006172 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006173 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006174 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6175 cmd_buf_info.pNext = NULL;
6176 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006177 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006178
6179 // Begin CB to transition to recording state
6180 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6181 // Can't re-begin. This should trigger error
6182 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006183 m_errorMonitor->VerifyFound();
6184
Karl Schultz6addd812016-02-02 17:17:23 -07006185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6186 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006187 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6188 // Reset attempt will trigger error due to incorrect CommandPool state
6189 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006190 m_errorMonitor->VerifyFound();
6191
Karl Schultz6addd812016-02-02 17:17:23 -07006192 m_errorMonitor->SetDesiredFailureMsg(
6193 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6194 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006195 // Transition CB to RECORDED state
6196 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6197 // Now attempting to Begin will implicitly reset, which triggers error
6198 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006199 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006200}
6201
Karl Schultz6addd812016-02-02 17:17:23 -07006202TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006203 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006204 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006205
Karl Schultz6addd812016-02-02 17:17:23 -07006206 m_errorMonitor->SetDesiredFailureMsg(
6207 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006208 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6209
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006210 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006212
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006213 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006214 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6215 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006216
6217 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006218 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6219 ds_pool_ci.pNext = NULL;
6220 ds_pool_ci.maxSets = 1;
6221 ds_pool_ci.poolSizeCount = 1;
6222 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006223
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006224 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006225 err =
6226 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006227 ASSERT_VK_SUCCESS(err);
6228
Tony Barboureb254902015-07-15 12:50:33 -06006229 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006230 dsl_binding.binding = 0;
6231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6232 dsl_binding.descriptorCount = 1;
6233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6234 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006235
Tony Barboureb254902015-07-15 12:50:33 -06006236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6238 ds_layout_ci.pNext = NULL;
6239 ds_layout_ci.bindingCount = 1;
6240 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006241
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006242 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6244 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006245 ASSERT_VK_SUCCESS(err);
6246
6247 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006248 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006249 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006250 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006251 alloc_info.descriptorPool = ds_pool;
6252 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006253 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6254 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006255 ASSERT_VK_SUCCESS(err);
6256
Tony Barboureb254902015-07-15 12:50:33 -06006257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6259 pipeline_layout_ci.setLayoutCount = 1;
6260 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006261
6262 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006263 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6264 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006265 ASSERT_VK_SUCCESS(err);
6266
Tobin Ehlise68360f2015-10-01 11:15:13 -06006267 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006268 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006269
6270 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006271 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6272 vp_state_ci.scissorCount = 1;
6273 vp_state_ci.pScissors = &sc;
6274 vp_state_ci.viewportCount = 1;
6275 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006276
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006277 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6278 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6279 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6280 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6281 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6282 rs_state_ci.depthClampEnable = VK_FALSE;
6283 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6284 rs_state_ci.depthBiasEnable = VK_FALSE;
6285
Tony Barboureb254902015-07-15 12:50:33 -06006286 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006287 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6288 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006289 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6291 gp_ci.layout = pipeline_layout;
6292 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006293
6294 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006295 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6296 pc_ci.initialDataSize = 0;
6297 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006298
6299 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006300 VkPipelineCache pipelineCache;
6301
Karl Schultz6addd812016-02-02 17:17:23 -07006302 err =
6303 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006304 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6306 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006308 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006309
Chia-I Wuf7458c52015-10-26 21:10:41 +08006310 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6311 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6312 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6313 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006314}
Tobin Ehlis912df022015-09-17 08:46:18 -06006315/*// TODO : This test should be good, but needs Tess support in compiler to run
6316TEST_F(VkLayerTest, InvalidPatchControlPoints)
6317{
6318 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006319 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006320
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006322 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6323primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006324
Tobin Ehlis912df022015-09-17 08:46:18 -06006325 ASSERT_NO_FATAL_FAILURE(InitState());
6326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006327
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006328 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006329 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006330 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006331
6332 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6333 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6334 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006335 ds_pool_ci.poolSizeCount = 1;
6336 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006337
6338 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006339 err = vkCreateDescriptorPool(m_device->device(),
6340VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006341 ASSERT_VK_SUCCESS(err);
6342
6343 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006344 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006345 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006346 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006347 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6348 dsl_binding.pImmutableSamplers = NULL;
6349
6350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006351 ds_layout_ci.sType =
6352VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006353 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006354 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006355 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006356
6357 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6359&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006360 ASSERT_VK_SUCCESS(err);
6361
6362 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006363 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6364VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006365 ASSERT_VK_SUCCESS(err);
6366
6367 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006368 pipeline_layout_ci.sType =
6369VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006370 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006371 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006372 pipeline_layout_ci.pSetLayouts = &ds_layout;
6373
6374 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006375 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6376&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006377 ASSERT_VK_SUCCESS(err);
6378
6379 VkPipelineShaderStageCreateInfo shaderStages[3];
6380 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6381
Karl Schultz6addd812016-02-02 17:17:23 -07006382 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6383this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006384 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006385 VkShaderObj
6386tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6387this);
6388 VkShaderObj
6389te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6390this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006391
Karl Schultz6addd812016-02-02 17:17:23 -07006392 shaderStages[0].sType =
6393VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006394 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006395 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006396 shaderStages[1].sType =
6397VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006398 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006399 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006400 shaderStages[2].sType =
6401VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006402 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006403 shaderStages[2].shader = te.handle();
6404
6405 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006406 iaCI.sType =
6407VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006408 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006409
6410 VkPipelineTessellationStateCreateInfo tsCI = {};
6411 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6412 tsCI.patchControlPoints = 0; // This will cause an error
6413
6414 VkGraphicsPipelineCreateInfo gp_ci = {};
6415 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6416 gp_ci.pNext = NULL;
6417 gp_ci.stageCount = 3;
6418 gp_ci.pStages = shaderStages;
6419 gp_ci.pVertexInputState = NULL;
6420 gp_ci.pInputAssemblyState = &iaCI;
6421 gp_ci.pTessellationState = &tsCI;
6422 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006423 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006424 gp_ci.pMultisampleState = NULL;
6425 gp_ci.pDepthStencilState = NULL;
6426 gp_ci.pColorBlendState = NULL;
6427 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6428 gp_ci.layout = pipeline_layout;
6429 gp_ci.renderPass = renderPass();
6430
6431 VkPipelineCacheCreateInfo pc_ci = {};
6432 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6433 pc_ci.pNext = NULL;
6434 pc_ci.initialSize = 0;
6435 pc_ci.initialData = 0;
6436 pc_ci.maxSize = 0;
6437
6438 VkPipeline pipeline;
6439 VkPipelineCache pipelineCache;
6440
Karl Schultz6addd812016-02-02 17:17:23 -07006441 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6442&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006443 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006444 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6445&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006447 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006448
Chia-I Wuf7458c52015-10-26 21:10:41 +08006449 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6450 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006453}
6454*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006455// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006456TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006457 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006458
Karl Schultz6addd812016-02-02 17:17:23 -07006459 m_errorMonitor->SetDesiredFailureMsg(
6460 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006461 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6462
Tobin Ehlise68360f2015-10-01 11:15:13 -06006463 ASSERT_NO_FATAL_FAILURE(InitState());
6464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006465
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006466 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006467 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6468 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006469
6470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6472 ds_pool_ci.maxSets = 1;
6473 ds_pool_ci.poolSizeCount = 1;
6474 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006475
6476 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006477 err =
6478 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006479 ASSERT_VK_SUCCESS(err);
6480
6481 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006482 dsl_binding.binding = 0;
6483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6484 dsl_binding.descriptorCount = 1;
6485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006486
6487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6489 ds_layout_ci.bindingCount = 1;
6490 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006491
6492 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6494 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006495 ASSERT_VK_SUCCESS(err);
6496
6497 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006498 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006500 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006501 alloc_info.descriptorPool = ds_pool;
6502 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6504 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006505 ASSERT_VK_SUCCESS(err);
6506
6507 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006508 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6509 pipeline_layout_ci.setLayoutCount = 1;
6510 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006511
6512 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006513 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6514 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006515 ASSERT_VK_SUCCESS(err);
6516
6517 VkViewport vp = {}; // Just need dummy vp to point to
6518
6519 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006520 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6521 vp_state_ci.scissorCount = 0;
6522 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6523 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006524
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006525 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6526 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6527 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6528 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6529 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6530 rs_state_ci.depthClampEnable = VK_FALSE;
6531 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6532 rs_state_ci.depthBiasEnable = VK_FALSE;
6533
Cody Northropeb3a6c12015-10-05 14:44:45 -06006534 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006535 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006536
Karl Schultz6addd812016-02-02 17:17:23 -07006537 VkShaderObj vs(m_device, bindStateVertShaderText,
6538 VK_SHADER_STAGE_VERTEX_BIT, this);
6539 VkShaderObj fs(m_device, bindStateFragShaderText,
6540 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006541 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006542 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006543 shaderStages[0] = vs.GetStageCreateInfo();
6544 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006545
6546 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006547 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6548 gp_ci.stageCount = 2;
6549 gp_ci.pStages = shaderStages;
6550 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006551 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006552 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6553 gp_ci.layout = pipeline_layout;
6554 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006555
6556 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006557 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006558
6559 VkPipeline pipeline;
6560 VkPipelineCache pipelineCache;
6561
Karl Schultz6addd812016-02-02 17:17:23 -07006562 err =
6563 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006564 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006565 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6566 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006568 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006569
Chia-I Wuf7458c52015-10-26 21:10:41 +08006570 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6571 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6572 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6573 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006574}
Karl Schultz6addd812016-02-02 17:17:23 -07006575// Don't set viewport state in PSO. This is an error b/c we always need this
6576// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006577// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006578TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006579 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006580 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006581
Karl Schultz6addd812016-02-02 17:17:23 -07006582 m_errorMonitor->SetDesiredFailureMsg(
6583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006584 "Gfx Pipeline pViewportState is null. Even if ");
6585
Tobin Ehlise68360f2015-10-01 11:15:13 -06006586 ASSERT_NO_FATAL_FAILURE(InitState());
6587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006588
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006589 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6591 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006592
6593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6595 ds_pool_ci.maxSets = 1;
6596 ds_pool_ci.poolSizeCount = 1;
6597 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006598
6599 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006600 err =
6601 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006602 ASSERT_VK_SUCCESS(err);
6603
6604 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 dsl_binding.binding = 0;
6606 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6607 dsl_binding.descriptorCount = 1;
6608 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006609
6610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6612 ds_layout_ci.bindingCount = 1;
6613 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006614
6615 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6617 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006618 ASSERT_VK_SUCCESS(err);
6619
6620 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006621 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006622 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006623 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006624 alloc_info.descriptorPool = ds_pool;
6625 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006626 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6627 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006628 ASSERT_VK_SUCCESS(err);
6629
6630 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006631 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6632 pipeline_layout_ci.setLayoutCount = 1;
6633 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006634
6635 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006636 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6637 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006638 ASSERT_VK_SUCCESS(err);
6639
6640 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6641 // Set scissor as dynamic to avoid second error
6642 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006643 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6644 dyn_state_ci.dynamicStateCount = 1;
6645 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006646
Cody Northropeb3a6c12015-10-05 14:44:45 -06006647 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006648 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006649
Karl Schultz6addd812016-02-02 17:17:23 -07006650 VkShaderObj vs(m_device, bindStateVertShaderText,
6651 VK_SHADER_STAGE_VERTEX_BIT, this);
6652 VkShaderObj fs(m_device, bindStateFragShaderText,
6653 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006654 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006655 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006656 shaderStages[0] = vs.GetStageCreateInfo();
6657 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006658
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006659
6660 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6661 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6662 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6663 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6664 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6665 rs_state_ci.depthClampEnable = VK_FALSE;
6666 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6667 rs_state_ci.depthBiasEnable = VK_FALSE;
6668
Tobin Ehlise68360f2015-10-01 11:15:13 -06006669 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006670 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6671 gp_ci.stageCount = 2;
6672 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006673 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006674 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6675 // should cause validation error
6676 gp_ci.pDynamicState = &dyn_state_ci;
6677 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6678 gp_ci.layout = pipeline_layout;
6679 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006680
6681 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006682 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006683
6684 VkPipeline pipeline;
6685 VkPipelineCache pipelineCache;
6686
Karl Schultz6addd812016-02-02 17:17:23 -07006687 err =
6688 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006689 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006690 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6691 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006693 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006694
Chia-I Wuf7458c52015-10-26 21:10:41 +08006695 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6697 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6698 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006699}
6700// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006701// Then run second test where dynamic scissor count doesn't match PSO scissor
6702// count
6703TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6704 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006705
Karl Schultz6addd812016-02-02 17:17:23 -07006706 m_errorMonitor->SetDesiredFailureMsg(
6707 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006708 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6709
Tobin Ehlise68360f2015-10-01 11:15:13 -06006710 ASSERT_NO_FATAL_FAILURE(InitState());
6711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006712
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006713 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006714 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6715 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006716
6717 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006718 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6719 ds_pool_ci.maxSets = 1;
6720 ds_pool_ci.poolSizeCount = 1;
6721 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006722
6723 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006724 err =
6725 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006726 ASSERT_VK_SUCCESS(err);
6727
6728 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006729 dsl_binding.binding = 0;
6730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6731 dsl_binding.descriptorCount = 1;
6732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006733
6734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6736 ds_layout_ci.bindingCount = 1;
6737 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006738
6739 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006740 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6741 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006742 ASSERT_VK_SUCCESS(err);
6743
6744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006748 alloc_info.descriptorPool = ds_pool;
6749 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6751 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006752 ASSERT_VK_SUCCESS(err);
6753
6754 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006755 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6756 pipeline_layout_ci.setLayoutCount = 1;
6757 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006758
6759 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006760 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6761 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006762 ASSERT_VK_SUCCESS(err);
6763
6764 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006765 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6766 vp_state_ci.viewportCount = 1;
6767 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6768 vp_state_ci.scissorCount = 1;
6769 vp_state_ci.pScissors =
6770 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006771
6772 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6773 // Set scissor as dynamic to avoid that error
6774 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006775 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6776 dyn_state_ci.dynamicStateCount = 1;
6777 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006778
Cody Northropeb3a6c12015-10-05 14:44:45 -06006779 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006780 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006781
Karl Schultz6addd812016-02-02 17:17:23 -07006782 VkShaderObj vs(m_device, bindStateVertShaderText,
6783 VK_SHADER_STAGE_VERTEX_BIT, this);
6784 VkShaderObj fs(m_device, bindStateFragShaderText,
6785 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006786 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006787 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006788 shaderStages[0] = vs.GetStageCreateInfo();
6789 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006790
Cody Northropf6622dc2015-10-06 10:33:21 -06006791 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6792 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6793 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006794 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006795 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006796 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006797 vi_ci.pVertexAttributeDescriptions = nullptr;
6798
6799 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6800 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6801 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6802
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006803 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006804 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006805 rs_ci.pNext = nullptr;
6806
Mark Youngc89c6312016-03-31 16:03:20 -06006807 VkPipelineColorBlendAttachmentState att = {};
6808 att.blendEnable = VK_FALSE;
6809 att.colorWriteMask = 0xf;
6810
Cody Northropf6622dc2015-10-06 10:33:21 -06006811 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6812 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6813 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006814 cb_ci.attachmentCount = 1;
6815 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006816
Tobin Ehlise68360f2015-10-01 11:15:13 -06006817 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006818 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6819 gp_ci.stageCount = 2;
6820 gp_ci.pStages = shaderStages;
6821 gp_ci.pVertexInputState = &vi_ci;
6822 gp_ci.pInputAssemblyState = &ia_ci;
6823 gp_ci.pViewportState = &vp_state_ci;
6824 gp_ci.pRasterizationState = &rs_ci;
6825 gp_ci.pColorBlendState = &cb_ci;
6826 gp_ci.pDynamicState = &dyn_state_ci;
6827 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6828 gp_ci.layout = pipeline_layout;
6829 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006830
6831 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006832 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006833
6834 VkPipeline pipeline;
6835 VkPipelineCache pipelineCache;
6836
Karl Schultz6addd812016-02-02 17:17:23 -07006837 err =
6838 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006839 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006840 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6841 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006842
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006843 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006844
Tobin Ehlisd332f282015-10-02 11:00:56 -06006845 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006846 // First need to successfully create the PSO from above by setting
6847 // pViewports
6848 m_errorMonitor->SetDesiredFailureMsg(
6849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6850 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6851 "scissorCount is 1. These counts must match.");
6852
6853 VkViewport vp = {}; // Just need dummy vp to point to
6854 vp_state_ci.pViewports = &vp;
6855 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6856 &gp_ci, NULL, &pipeline);
6857 ASSERT_VK_SUCCESS(err);
6858 BeginCommandBuffer();
6859 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6860 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6861 VkRect2D scissors[2] = {}; // don't care about data
6862 // Count of 2 doesn't match PSO count of 1
6863 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6864 Draw(1, 0, 0, 0);
6865
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006866 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006867
6868 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6869 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006872 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006873}
6874// Create PSO w/o non-zero scissorCount but no scissor data
6875// Then run second test where dynamic viewportCount doesn't match PSO
6876// viewportCount
6877TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6878 VkResult err;
6879
6880 m_errorMonitor->SetDesiredFailureMsg(
6881 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6882 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6883
6884 ASSERT_NO_FATAL_FAILURE(InitState());
6885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6886
6887 VkDescriptorPoolSize ds_type_count = {};
6888 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6889 ds_type_count.descriptorCount = 1;
6890
6891 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6892 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6893 ds_pool_ci.maxSets = 1;
6894 ds_pool_ci.poolSizeCount = 1;
6895 ds_pool_ci.pPoolSizes = &ds_type_count;
6896
6897 VkDescriptorPool ds_pool;
6898 err =
6899 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6900 ASSERT_VK_SUCCESS(err);
6901
6902 VkDescriptorSetLayoutBinding dsl_binding = {};
6903 dsl_binding.binding = 0;
6904 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6905 dsl_binding.descriptorCount = 1;
6906 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6907
6908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6910 ds_layout_ci.bindingCount = 1;
6911 ds_layout_ci.pBindings = &dsl_binding;
6912
6913 VkDescriptorSetLayout ds_layout;
6914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6915 &ds_layout);
6916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSet descriptorSet;
6919 VkDescriptorSetAllocateInfo alloc_info = {};
6920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6921 alloc_info.descriptorSetCount = 1;
6922 alloc_info.descriptorPool = ds_pool;
6923 alloc_info.pSetLayouts = &ds_layout;
6924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6925 &descriptorSet);
6926 ASSERT_VK_SUCCESS(err);
6927
6928 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6929 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6930 pipeline_layout_ci.setLayoutCount = 1;
6931 pipeline_layout_ci.pSetLayouts = &ds_layout;
6932
6933 VkPipelineLayout pipeline_layout;
6934 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6935 &pipeline_layout);
6936 ASSERT_VK_SUCCESS(err);
6937
6938 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6939 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6940 vp_state_ci.scissorCount = 1;
6941 vp_state_ci.pScissors =
6942 NULL; // Null scissor w/ count of 1 should cause error
6943 vp_state_ci.viewportCount = 1;
6944 vp_state_ci.pViewports =
6945 NULL; // vp is dynamic (below) so this won't cause error
6946
6947 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6948 // Set scissor as dynamic to avoid that error
6949 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6950 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6951 dyn_state_ci.dynamicStateCount = 1;
6952 dyn_state_ci.pDynamicStates = &vp_state;
6953
6954 VkPipelineShaderStageCreateInfo shaderStages[2];
6955 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6956
6957 VkShaderObj vs(m_device, bindStateVertShaderText,
6958 VK_SHADER_STAGE_VERTEX_BIT, this);
6959 VkShaderObj fs(m_device, bindStateFragShaderText,
6960 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006961 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006962 // but add it to be able to run on more devices
6963 shaderStages[0] = vs.GetStageCreateInfo();
6964 shaderStages[1] = fs.GetStageCreateInfo();
6965
6966 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6967 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6968 vi_ci.pNext = nullptr;
6969 vi_ci.vertexBindingDescriptionCount = 0;
6970 vi_ci.pVertexBindingDescriptions = nullptr;
6971 vi_ci.vertexAttributeDescriptionCount = 0;
6972 vi_ci.pVertexAttributeDescriptions = nullptr;
6973
6974 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6975 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6976 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6977
6978 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6979 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6980 rs_ci.pNext = nullptr;
6981
Mark Youngc89c6312016-03-31 16:03:20 -06006982 VkPipelineColorBlendAttachmentState att = {};
6983 att.blendEnable = VK_FALSE;
6984 att.colorWriteMask = 0xf;
6985
Karl Schultz6addd812016-02-02 17:17:23 -07006986 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6987 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6988 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006989 cb_ci.attachmentCount = 1;
6990 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006991
6992 VkGraphicsPipelineCreateInfo gp_ci = {};
6993 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6994 gp_ci.stageCount = 2;
6995 gp_ci.pStages = shaderStages;
6996 gp_ci.pVertexInputState = &vi_ci;
6997 gp_ci.pInputAssemblyState = &ia_ci;
6998 gp_ci.pViewportState = &vp_state_ci;
6999 gp_ci.pRasterizationState = &rs_ci;
7000 gp_ci.pColorBlendState = &cb_ci;
7001 gp_ci.pDynamicState = &dyn_state_ci;
7002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7003 gp_ci.layout = pipeline_layout;
7004 gp_ci.renderPass = renderPass();
7005
7006 VkPipelineCacheCreateInfo pc_ci = {};
7007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7008
7009 VkPipeline pipeline;
7010 VkPipelineCache pipelineCache;
7011
7012 err =
7013 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7014 ASSERT_VK_SUCCESS(err);
7015 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7016 &gp_ci, NULL, &pipeline);
7017
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007018 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007019
7020 // Now hit second fail case where we set scissor w/ different count than PSO
7021 // First need to successfully create the PSO from above by setting
7022 // pViewports
7023 m_errorMonitor->SetDesiredFailureMsg(
7024 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7025 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
7026 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007027
Tobin Ehlisd332f282015-10-02 11:00:56 -06007028 VkRect2D sc = {}; // Just need dummy vp to point to
7029 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07007030 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7031 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007032 ASSERT_VK_SUCCESS(err);
7033 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007034 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7035 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007036 VkViewport viewports[2] = {}; // don't care about data
7037 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007038 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007039 Draw(1, 0, 0, 0);
7040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007041 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007042
Chia-I Wuf7458c52015-10-26 21:10:41 +08007043 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7044 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7045 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7046 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007047 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007048}
7049
Mark Young7394fdd2016-03-31 14:56:43 -06007050TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7051 VkResult err;
7052
7053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007054 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007055
7056 ASSERT_NO_FATAL_FAILURE(InitState());
7057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7058
7059 VkDescriptorPoolSize ds_type_count = {};
7060 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7061 ds_type_count.descriptorCount = 1;
7062
7063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7065 ds_pool_ci.maxSets = 1;
7066 ds_pool_ci.poolSizeCount = 1;
7067 ds_pool_ci.pPoolSizes = &ds_type_count;
7068
7069 VkDescriptorPool ds_pool;
7070 err =
7071 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7072 ASSERT_VK_SUCCESS(err);
7073
7074 VkDescriptorSetLayoutBinding dsl_binding = {};
7075 dsl_binding.binding = 0;
7076 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7077 dsl_binding.descriptorCount = 1;
7078 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7079
7080 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7081 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7082 ds_layout_ci.bindingCount = 1;
7083 ds_layout_ci.pBindings = &dsl_binding;
7084
7085 VkDescriptorSetLayout ds_layout;
7086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7087 &ds_layout);
7088 ASSERT_VK_SUCCESS(err);
7089
7090 VkDescriptorSet descriptorSet;
7091 VkDescriptorSetAllocateInfo alloc_info = {};
7092 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7093 alloc_info.descriptorSetCount = 1;
7094 alloc_info.descriptorPool = ds_pool;
7095 alloc_info.pSetLayouts = &ds_layout;
7096 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7097 &descriptorSet);
7098 ASSERT_VK_SUCCESS(err);
7099
7100 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7101 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7102 pipeline_layout_ci.setLayoutCount = 1;
7103 pipeline_layout_ci.pSetLayouts = &ds_layout;
7104
7105 VkPipelineLayout pipeline_layout;
7106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7107 &pipeline_layout);
7108 ASSERT_VK_SUCCESS(err);
7109
7110 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7111 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7112 vp_state_ci.scissorCount = 1;
7113 vp_state_ci.pScissors = NULL;
7114 vp_state_ci.viewportCount = 1;
7115 vp_state_ci.pViewports = NULL;
7116
7117 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7118 VK_DYNAMIC_STATE_SCISSOR,
7119 VK_DYNAMIC_STATE_LINE_WIDTH};
7120 // Set scissor as dynamic to avoid that error
7121 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7122 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7123 dyn_state_ci.dynamicStateCount = 2;
7124 dyn_state_ci.pDynamicStates = dynamic_states;
7125
7126 VkPipelineShaderStageCreateInfo shaderStages[2];
7127 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7128
7129 VkShaderObj vs(m_device, bindStateVertShaderText,
7130 VK_SHADER_STAGE_VERTEX_BIT, this);
7131 VkShaderObj fs(m_device, bindStateFragShaderText,
7132 VK_SHADER_STAGE_FRAGMENT_BIT,
7133 this); // TODO - We shouldn't need a fragment shader
7134 // but add it to be able to run on more devices
7135 shaderStages[0] = vs.GetStageCreateInfo();
7136 shaderStages[1] = fs.GetStageCreateInfo();
7137
7138 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7139 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7140 vi_ci.pNext = nullptr;
7141 vi_ci.vertexBindingDescriptionCount = 0;
7142 vi_ci.pVertexBindingDescriptions = nullptr;
7143 vi_ci.vertexAttributeDescriptionCount = 0;
7144 vi_ci.pVertexAttributeDescriptions = nullptr;
7145
7146 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7147 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7148 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7149
7150 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7151 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7152 rs_ci.pNext = nullptr;
7153
Mark Young47107952016-05-02 15:59:55 -06007154 // Check too low (line width of -1.0f).
7155 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007156
7157 VkPipelineColorBlendAttachmentState att = {};
7158 att.blendEnable = VK_FALSE;
7159 att.colorWriteMask = 0xf;
7160
7161 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7162 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7163 cb_ci.pNext = nullptr;
7164 cb_ci.attachmentCount = 1;
7165 cb_ci.pAttachments = &att;
7166
7167 VkGraphicsPipelineCreateInfo gp_ci = {};
7168 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7169 gp_ci.stageCount = 2;
7170 gp_ci.pStages = shaderStages;
7171 gp_ci.pVertexInputState = &vi_ci;
7172 gp_ci.pInputAssemblyState = &ia_ci;
7173 gp_ci.pViewportState = &vp_state_ci;
7174 gp_ci.pRasterizationState = &rs_ci;
7175 gp_ci.pColorBlendState = &cb_ci;
7176 gp_ci.pDynamicState = &dyn_state_ci;
7177 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7178 gp_ci.layout = pipeline_layout;
7179 gp_ci.renderPass = renderPass();
7180
7181 VkPipelineCacheCreateInfo pc_ci = {};
7182 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7183
7184 VkPipeline pipeline;
7185 VkPipelineCache pipelineCache;
7186
7187 err =
7188 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7189 ASSERT_VK_SUCCESS(err);
7190 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7191 &gp_ci, NULL, &pipeline);
7192
7193 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007194 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007195
7196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7197 "Attempt to set lineWidth to 65536");
7198
7199 // Check too high (line width of 65536.0f).
7200 rs_ci.lineWidth = 65536.0f;
7201
7202 err =
7203 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7204 ASSERT_VK_SUCCESS(err);
7205 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7206 &gp_ci, NULL, &pipeline);
7207
7208 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007209 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007210
7211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007212 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007213
7214 dyn_state_ci.dynamicStateCount = 3;
7215
7216 rs_ci.lineWidth = 1.0f;
7217
7218 err =
7219 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7220 ASSERT_VK_SUCCESS(err);
7221 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7222 &gp_ci, NULL, &pipeline);
7223 BeginCommandBuffer();
7224 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7225 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7226
7227 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007228 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007229 m_errorMonitor->VerifyFound();
7230
7231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7232 "Attempt to set lineWidth to 65536");
7233
7234 // Check too high with dynamic setting.
7235 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7236 m_errorMonitor->VerifyFound();
7237 EndCommandBuffer();
7238
7239 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007243 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007244}
7245
Karl Schultz6addd812016-02-02 17:17:23 -07007246TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007247 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007248 m_errorMonitor->SetDesiredFailureMsg(
7249 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007250 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007251
7252 ASSERT_NO_FATAL_FAILURE(InitState());
7253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007254
Tony Barbourfe3351b2015-07-28 10:17:20 -06007255 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007256 // Don't care about RenderPass handle b/c error should be flagged before
7257 // that
7258 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7259 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007260
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007262}
7263
Karl Schultz6addd812016-02-02 17:17:23 -07007264TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007265 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007266 m_errorMonitor->SetDesiredFailureMsg(
7267 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007268 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007269
7270 ASSERT_NO_FATAL_FAILURE(InitState());
7271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007272
Tony Barbourfe3351b2015-07-28 10:17:20 -06007273 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007274 // Just create a dummy Renderpass that's non-NULL so we can get to the
7275 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007276 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007277 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7278 rp_begin.pNext = NULL;
7279 rp_begin.renderPass = renderPass();
7280 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007281
Karl Schultz6addd812016-02-02 17:17:23 -07007282 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7283 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007285 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007286}
7287
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007288TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7289 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7290 "the number of renderPass attachments that use loadOp"
7291 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7292
7293 ASSERT_NO_FATAL_FAILURE(InitState());
7294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7295
7296 // Create a renderPass with a single attachment that uses loadOp CLEAR
7297 VkAttachmentReference attach = {};
7298 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7299 VkSubpassDescription subpass = {};
7300 subpass.inputAttachmentCount = 1;
7301 subpass.pInputAttachments = &attach;
7302 VkRenderPassCreateInfo rpci = {};
7303 rpci.subpassCount = 1;
7304 rpci.pSubpasses = &subpass;
7305 rpci.attachmentCount = 1;
7306 VkAttachmentDescription attach_desc = {};
7307 attach_desc.format = VK_FORMAT_UNDEFINED;
7308 // Set loadOp to CLEAR
7309 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7310 rpci.pAttachments = &attach_desc;
7311 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7312 VkRenderPass rp;
7313 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7314
7315 VkCommandBufferInheritanceInfo hinfo = {};
7316 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7317 hinfo.renderPass = VK_NULL_HANDLE;
7318 hinfo.subpass = 0;
7319 hinfo.framebuffer = VK_NULL_HANDLE;
7320 hinfo.occlusionQueryEnable = VK_FALSE;
7321 hinfo.queryFlags = 0;
7322 hinfo.pipelineStatistics = 0;
7323 VkCommandBufferBeginInfo info = {};
7324 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7325 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7326 info.pInheritanceInfo = &hinfo;
7327
7328 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7329 VkRenderPassBeginInfo rp_begin = {};
7330 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7331 rp_begin.pNext = NULL;
7332 rp_begin.renderPass = renderPass();
7333 rp_begin.framebuffer = framebuffer();
7334 rp_begin.clearValueCount = 0; // Should be 1
7335
7336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7337 " has a clearValueCount of 0 but the "
7338 "actual number of attachments in "
7339 "renderPass ");
7340
7341 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7342 VK_SUBPASS_CONTENTS_INLINE);
7343
7344 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007345
7346 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007347}
7348
Cody Northrop3bb4d962016-05-09 16:15:57 -06007349TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7350
7351 TEST_DESCRIPTION("End a command buffer with an active render pass");
7352
7353 m_errorMonitor->SetDesiredFailureMsg(
7354 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7355 "It is invalid to issue this call inside an active render pass");
7356
7357 ASSERT_NO_FATAL_FAILURE(InitState());
7358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7359
7360 // The framework's BeginCommandBuffer calls CreateRenderPass
7361 BeginCommandBuffer();
7362
7363 // Call directly into vkEndCommandBuffer instead of the
7364 // the framework's EndCommandBuffer, which inserts a
7365 // vkEndRenderPass
7366 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7367
7368 m_errorMonitor->VerifyFound();
7369
7370 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7371 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7372}
7373
Karl Schultz6addd812016-02-02 17:17:23 -07007374TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007375 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007376 m_errorMonitor->SetDesiredFailureMsg(
7377 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007378 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007379
7380 ASSERT_NO_FATAL_FAILURE(InitState());
7381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007382
7383 // Renderpass is started here
7384 BeginCommandBuffer();
7385
7386 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007387 vk_testing::Buffer dstBuffer;
7388 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007389
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007390 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007391
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007392 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007393}
7394
Karl Schultz6addd812016-02-02 17:17:23 -07007395TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007396 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007397 m_errorMonitor->SetDesiredFailureMsg(
7398 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007399 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007400
7401 ASSERT_NO_FATAL_FAILURE(InitState());
7402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007403
7404 // Renderpass is started here
7405 BeginCommandBuffer();
7406
7407 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007408 vk_testing::Buffer dstBuffer;
7409 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007410
Karl Schultz6addd812016-02-02 17:17:23 -07007411 VkDeviceSize dstOffset = 0;
7412 VkDeviceSize dataSize = 1024;
7413 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007414
Karl Schultz6addd812016-02-02 17:17:23 -07007415 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7416 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007418 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007419}
7420
Karl Schultz6addd812016-02-02 17:17:23 -07007421TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007422 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007423 m_errorMonitor->SetDesiredFailureMsg(
7424 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007425 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007426
7427 ASSERT_NO_FATAL_FAILURE(InitState());
7428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007429
7430 // Renderpass is started here
7431 BeginCommandBuffer();
7432
Michael Lentine0a369f62016-02-03 16:51:46 -06007433 VkClearColorValue clear_color;
7434 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007435 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7436 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7437 const int32_t tex_width = 32;
7438 const int32_t tex_height = 32;
7439 VkImageCreateInfo image_create_info = {};
7440 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7441 image_create_info.pNext = NULL;
7442 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7443 image_create_info.format = tex_format;
7444 image_create_info.extent.width = tex_width;
7445 image_create_info.extent.height = tex_height;
7446 image_create_info.extent.depth = 1;
7447 image_create_info.mipLevels = 1;
7448 image_create_info.arrayLayers = 1;
7449 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7450 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7451 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007452
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007453 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007454 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7455 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007456
Karl Schultz6addd812016-02-02 17:17:23 -07007457 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7458 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007459
Karl Schultz6addd812016-02-02 17:17:23 -07007460 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7461 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007462
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007463 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007464}
7465
Karl Schultz6addd812016-02-02 17:17:23 -07007466TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007467 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007468 m_errorMonitor->SetDesiredFailureMsg(
7469 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007470 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007471
7472 ASSERT_NO_FATAL_FAILURE(InitState());
7473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007474
7475 // Renderpass is started here
7476 BeginCommandBuffer();
7477
7478 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007479 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007480 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7481 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7482 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7483 image_create_info.extent.width = 64;
7484 image_create_info.extent.height = 64;
7485 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7486 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007487
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007488 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007489 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7490 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007491
Karl Schultz6addd812016-02-02 17:17:23 -07007492 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7493 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007494
Karl Schultz6addd812016-02-02 17:17:23 -07007495 vkCmdClearDepthStencilImage(
7496 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7497 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7498 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007499
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007500 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007501}
7502
Karl Schultz6addd812016-02-02 17:17:23 -07007503TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007504 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007505 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007506
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007508 "vkCmdClearAttachments: This call "
7509 "must be issued inside an active "
7510 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007511
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007512 ASSERT_NO_FATAL_FAILURE(InitState());
7513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007514
7515 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007516 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007517 ASSERT_VK_SUCCESS(err);
7518
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007519 VkClearAttachment color_attachment;
7520 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7521 color_attachment.clearValue.color.float32[0] = 0;
7522 color_attachment.clearValue.color.float32[1] = 0;
7523 color_attachment.clearValue.color.float32[2] = 0;
7524 color_attachment.clearValue.color.float32[3] = 0;
7525 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007526 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7527 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7528 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007530 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007531}
7532
Karl Schultz9e66a292016-04-21 15:57:51 -06007533TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7534 // Try to add a buffer memory barrier with no buffer.
7535 m_errorMonitor->SetDesiredFailureMsg(
7536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7537 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7538
7539 ASSERT_NO_FATAL_FAILURE(InitState());
7540 BeginCommandBuffer();
7541
7542 VkBufferMemoryBarrier buf_barrier = {};
7543 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7544 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7545 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7546 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7547 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7548 buf_barrier.buffer = VK_NULL_HANDLE;
7549 buf_barrier.offset = 0;
7550 buf_barrier.size = VK_WHOLE_SIZE;
7551 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7552 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7553 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7554
7555 m_errorMonitor->VerifyFound();
7556}
7557
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007558TEST_F(VkLayerTest, InvalidBarriers) {
7559 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7560
7561 m_errorMonitor->SetDesiredFailureMsg(
7562 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7563
7564 ASSERT_NO_FATAL_FAILURE(InitState());
7565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7566
7567 VkMemoryBarrier mem_barrier = {};
7568 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7569 mem_barrier.pNext = NULL;
7570 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7571 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7572 BeginCommandBuffer();
7573 // BeginCommandBuffer() starts a render pass
7574 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7575 VK_PIPELINE_STAGE_HOST_BIT,
7576 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7577 &mem_barrier, 0, nullptr, 0, nullptr);
7578 m_errorMonitor->VerifyFound();
7579
7580 m_errorMonitor->SetDesiredFailureMsg(
7581 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7582 "Image Layout cannot be transitioned to UNDEFINED");
7583 VkImageObj image(m_device);
7584 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7585 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7586 ASSERT_TRUE(image.initialized());
7587 VkImageMemoryBarrier img_barrier = {};
7588 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7589 img_barrier.pNext = NULL;
7590 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7591 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7592 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7593 // New layout can't be UNDEFINED
7594 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7595 img_barrier.image = image.handle();
7596 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7597 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7598 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7599 img_barrier.subresourceRange.baseArrayLayer = 0;
7600 img_barrier.subresourceRange.baseMipLevel = 0;
7601 img_barrier.subresourceRange.layerCount = 1;
7602 img_barrier.subresourceRange.levelCount = 1;
7603 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7604 VK_PIPELINE_STAGE_HOST_BIT,
7605 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7606 nullptr, 1, &img_barrier);
7607 m_errorMonitor->VerifyFound();
7608 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7609
7610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7611 "Subresource must have the sum of the "
7612 "baseArrayLayer");
7613 // baseArrayLayer + layerCount must be <= image's arrayLayers
7614 img_barrier.subresourceRange.baseArrayLayer = 1;
7615 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7616 VK_PIPELINE_STAGE_HOST_BIT,
7617 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7618 nullptr, 1, &img_barrier);
7619 m_errorMonitor->VerifyFound();
7620 img_barrier.subresourceRange.baseArrayLayer = 0;
7621
7622 m_errorMonitor->SetDesiredFailureMsg(
7623 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7624 "Subresource must have the sum of the baseMipLevel");
7625 // baseMipLevel + levelCount must be <= image's mipLevels
7626 img_barrier.subresourceRange.baseMipLevel = 1;
7627 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7628 VK_PIPELINE_STAGE_HOST_BIT,
7629 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7630 nullptr, 1, &img_barrier);
7631 m_errorMonitor->VerifyFound();
7632 img_barrier.subresourceRange.baseMipLevel = 0;
7633
7634 m_errorMonitor->SetDesiredFailureMsg(
7635 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7636 "Buffer Barriers cannot be used during a render pass");
7637 vk_testing::Buffer buffer;
7638 buffer.init(*m_device, 256);
7639 VkBufferMemoryBarrier buf_barrier = {};
7640 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7641 buf_barrier.pNext = NULL;
7642 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7643 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7644 buf_barrier.buffer = buffer.handle();
7645 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7646 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7647 buf_barrier.offset = 0;
7648 buf_barrier.size = VK_WHOLE_SIZE;
7649 // Can't send buffer barrier during a render pass
7650 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7651 VK_PIPELINE_STAGE_HOST_BIT,
7652 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7653 &buf_barrier, 0, nullptr);
7654 m_errorMonitor->VerifyFound();
7655 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7656
7657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7658 "which is not less than total size");
7659 buf_barrier.offset = 257;
7660 // Offset greater than total size
7661 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7662 VK_PIPELINE_STAGE_HOST_BIT,
7663 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7664 &buf_barrier, 0, nullptr);
7665 m_errorMonitor->VerifyFound();
7666 buf_barrier.offset = 0;
7667
7668 m_errorMonitor->SetDesiredFailureMsg(
7669 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7670 buf_barrier.size = 257;
7671 // Size greater than total size
7672 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7673 VK_PIPELINE_STAGE_HOST_BIT,
7674 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7675 &buf_barrier, 0, nullptr);
7676 m_errorMonitor->VerifyFound();
7677 buf_barrier.size = VK_WHOLE_SIZE;
7678
7679 m_errorMonitor->SetDesiredFailureMsg(
7680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7681 "Image is a depth and stencil format and thus must "
7682 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7683 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7684 VkDepthStencilObj ds_image(m_device);
7685 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7686 ASSERT_TRUE(ds_image.initialized());
7687 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7688 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7689 img_barrier.image = ds_image.handle();
7690 // Leave aspectMask at COLOR on purpose
7691 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7692 VK_PIPELINE_STAGE_HOST_BIT,
7693 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7694 nullptr, 1, &img_barrier);
7695 m_errorMonitor->VerifyFound();
7696}
7697
Karl Schultz6addd812016-02-02 17:17:23 -07007698TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007699 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007700 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007701
Karl Schultz6addd812016-02-02 17:17:23 -07007702 m_errorMonitor->SetDesiredFailureMsg(
7703 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007704 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7705
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007706 ASSERT_NO_FATAL_FAILURE(InitState());
7707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007708 uint32_t qfi = 0;
7709 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007710 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7711 buffCI.size = 1024;
7712 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7713 buffCI.queueFamilyIndexCount = 1;
7714 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007715
7716 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007717 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007718 ASSERT_VK_SUCCESS(err);
7719
7720 BeginCommandBuffer();
7721 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007722 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7723 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007724 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007725 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7726 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007727
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007728 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007729
Chia-I Wuf7458c52015-10-26 21:10:41 +08007730 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007731}
7732
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007733TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7734 // Create an out-of-range queueFamilyIndex
7735 m_errorMonitor->SetDesiredFailureMsg(
7736 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007737 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7738 "of the indices specified when the device was created, via the "
7739 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007740
7741 ASSERT_NO_FATAL_FAILURE(InitState());
7742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7743 VkBufferCreateInfo buffCI = {};
7744 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7745 buffCI.size = 1024;
7746 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7747 buffCI.queueFamilyIndexCount = 1;
7748 // Introduce failure by specifying invalid queue_family_index
7749 uint32_t qfi = 777;
7750 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007751 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007752
7753 VkBuffer ib;
7754 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007756 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007757 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007758}
7759
Karl Schultz6addd812016-02-02 17:17:23 -07007760TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7761 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7762 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007763
Karl Schultz6addd812016-02-02 17:17:23 -07007764 m_errorMonitor->SetDesiredFailureMsg(
7765 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007766 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007767
7768 ASSERT_NO_FATAL_FAILURE(InitState());
7769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007770
7771 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007772 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007773 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7774 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007775
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007776 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007777}
7778
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007779TEST_F(VkLayerTest, DSUsageBitsErrors) {
7780 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7781 "that do not have correct usage bits sets.");
7782 VkResult err;
7783
7784 ASSERT_NO_FATAL_FAILURE(InitState());
7785 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7786 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7787 ds_type_count[i].type = VkDescriptorType(i);
7788 ds_type_count[i].descriptorCount = 1;
7789 }
7790 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7791 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7792 ds_pool_ci.pNext = NULL;
7793 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7794 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7795 ds_pool_ci.pPoolSizes = ds_type_count;
7796
7797 VkDescriptorPool ds_pool;
7798 err =
7799 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7800 ASSERT_VK_SUCCESS(err);
7801
7802 // Create 10 layouts where each has a single descriptor of different type
7803 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7804 {};
7805 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7806 dsl_binding[i].binding = 0;
7807 dsl_binding[i].descriptorType = VkDescriptorType(i);
7808 dsl_binding[i].descriptorCount = 1;
7809 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7810 dsl_binding[i].pImmutableSamplers = NULL;
7811 }
7812
7813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7815 ds_layout_ci.pNext = NULL;
7816 ds_layout_ci.bindingCount = 1;
7817 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7818 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7819 ds_layout_ci.pBindings = dsl_binding + i;
7820 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7821 NULL, ds_layouts + i);
7822 ASSERT_VK_SUCCESS(err);
7823 }
7824 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7825 VkDescriptorSetAllocateInfo alloc_info = {};
7826 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7827 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7828 alloc_info.descriptorPool = ds_pool;
7829 alloc_info.pSetLayouts = ds_layouts;
7830 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7831 descriptor_sets);
7832 ASSERT_VK_SUCCESS(err);
7833
7834 // Create a buffer & bufferView to be used for invalid updates
7835 VkBufferCreateInfo buff_ci = {};
7836 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7837 // This usage is not valid for any descriptor type
7838 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7839 buff_ci.size = 256;
7840 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7841 VkBuffer buffer;
7842 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7843 ASSERT_VK_SUCCESS(err);
7844
7845 VkBufferViewCreateInfo buff_view_ci = {};
7846 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7847 buff_view_ci.buffer = buffer;
7848 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7849 buff_view_ci.range = VK_WHOLE_SIZE;
7850 VkBufferView buff_view;
7851 err =
7852 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7853 ASSERT_VK_SUCCESS(err);
7854
7855 // Create an image to be used for invalid updates
7856 VkImageCreateInfo image_ci = {};
7857 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7858 image_ci.imageType = VK_IMAGE_TYPE_2D;
7859 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7860 image_ci.extent.width = 64;
7861 image_ci.extent.height = 64;
7862 image_ci.extent.depth = 1;
7863 image_ci.mipLevels = 1;
7864 image_ci.arrayLayers = 1;
7865 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7866 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7867 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7868 // This usage is not valid for any descriptor type
7869 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7870 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7871 VkImage image;
7872 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7873 ASSERT_VK_SUCCESS(err);
7874 // Bind memory to image
7875 VkMemoryRequirements mem_reqs;
7876 VkDeviceMemory image_mem;
7877 bool pass;
7878 VkMemoryAllocateInfo mem_alloc = {};
7879 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7880 mem_alloc.pNext = NULL;
7881 mem_alloc.allocationSize = 0;
7882 mem_alloc.memoryTypeIndex = 0;
7883 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7884 mem_alloc.allocationSize = mem_reqs.size;
7885 pass =
7886 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7887 ASSERT_TRUE(pass);
7888 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7889 ASSERT_VK_SUCCESS(err);
7890 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7891 ASSERT_VK_SUCCESS(err);
7892 // Now create view for image
7893 VkImageViewCreateInfo image_view_ci = {};
7894 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7895 image_view_ci.image = image;
7896 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7897 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7898 image_view_ci.subresourceRange.layerCount = 1;
7899 image_view_ci.subresourceRange.baseArrayLayer = 0;
7900 image_view_ci.subresourceRange.levelCount = 1;
7901 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7902 VkImageView image_view;
7903 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7904 &image_view);
7905 ASSERT_VK_SUCCESS(err);
7906
7907 VkDescriptorBufferInfo buff_info = {};
7908 buff_info.buffer = buffer;
7909 VkDescriptorImageInfo img_info = {};
7910 img_info.imageView = image_view;
7911 VkWriteDescriptorSet descriptor_write = {};
7912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7913 descriptor_write.dstBinding = 0;
7914 descriptor_write.descriptorCount = 1;
7915 descriptor_write.pTexelBufferView = &buff_view;
7916 descriptor_write.pBufferInfo = &buff_info;
7917 descriptor_write.pImageInfo = &img_info;
7918
7919 // These error messages align with VkDescriptorType struct
7920 const char *error_msgs[] = {
7921 "", // placeholder, no error for SAMPLER descriptor
7922 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7923 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7924 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7925 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7926 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7927 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7928 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7929 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7930 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7931 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7932 // Start loop at 1 as SAMPLER desc type has no usage bit error
7933 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7934 descriptor_write.descriptorType = VkDescriptorType(i);
7935 descriptor_write.dstSet = descriptor_sets[i];
7936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7937 error_msgs[i]);
7938
7939 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7940 NULL);
7941
7942 m_errorMonitor->VerifyFound();
7943 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7944 }
7945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7946 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007947 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007948 vkDestroyImageView(m_device->device(), image_view, NULL);
7949 vkDestroyBuffer(m_device->device(), buffer, NULL);
7950 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7951 vkFreeDescriptorSets(m_device->device(), ds_pool,
7952 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7954}
7955
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06007956TEST_F(VkLayerTest, DSAspectBitsErrors) {
7957 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
7958 // are set, but could expand this test to hit more cases.
7959 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
7960 "that do not have correct aspect bits sets.");
7961 VkResult err;
7962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 VkDescriptorPoolSize ds_type_count = {};
7965 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7966 ds_type_count.descriptorCount = 1;
7967
7968 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7969 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7970 ds_pool_ci.pNext = NULL;
7971 ds_pool_ci.maxSets = 5;
7972 ds_pool_ci.poolSizeCount = 1;
7973 ds_pool_ci.pPoolSizes = &ds_type_count;
7974
7975 VkDescriptorPool ds_pool;
7976 err =
7977 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7978 ASSERT_VK_SUCCESS(err);
7979
7980 VkDescriptorSetLayoutBinding dsl_binding = {};
7981 dsl_binding.binding = 0;
7982 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7983 dsl_binding.descriptorCount = 1;
7984 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7985 dsl_binding.pImmutableSamplers = NULL;
7986
7987 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7988 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7989 ds_layout_ci.pNext = NULL;
7990 ds_layout_ci.bindingCount = 1;
7991 ds_layout_ci.pBindings = &dsl_binding;
7992 VkDescriptorSetLayout ds_layout;
7993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7994 &ds_layout);
7995 ASSERT_VK_SUCCESS(err);
7996
7997 VkDescriptorSet descriptor_set = {};
7998 VkDescriptorSetAllocateInfo alloc_info = {};
7999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8000 alloc_info.descriptorSetCount = 1;
8001 alloc_info.descriptorPool = ds_pool;
8002 alloc_info.pSetLayouts = &ds_layout;
8003 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8004 &descriptor_set);
8005 ASSERT_VK_SUCCESS(err);
8006
8007 // Create an image to be used for invalid updates
8008 VkImageCreateInfo image_ci = {};
8009 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8010 image_ci.imageType = VK_IMAGE_TYPE_2D;
8011 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8012 image_ci.extent.width = 64;
8013 image_ci.extent.height = 64;
8014 image_ci.extent.depth = 1;
8015 image_ci.mipLevels = 1;
8016 image_ci.arrayLayers = 1;
8017 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8018 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8019 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8020 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8021 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8022 VkImage image;
8023 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8024 ASSERT_VK_SUCCESS(err);
8025 // Bind memory to image
8026 VkMemoryRequirements mem_reqs;
8027 VkDeviceMemory image_mem;
8028 bool pass;
8029 VkMemoryAllocateInfo mem_alloc = {};
8030 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8031 mem_alloc.pNext = NULL;
8032 mem_alloc.allocationSize = 0;
8033 mem_alloc.memoryTypeIndex = 0;
8034 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8035 mem_alloc.allocationSize = mem_reqs.size;
8036 pass =
8037 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8038 ASSERT_TRUE(pass);
8039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8040 ASSERT_VK_SUCCESS(err);
8041 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8042 ASSERT_VK_SUCCESS(err);
8043 // Now create view for image
8044 VkImageViewCreateInfo image_view_ci = {};
8045 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8046 image_view_ci.image = image;
8047 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8048 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8049 image_view_ci.subresourceRange.layerCount = 1;
8050 image_view_ci.subresourceRange.baseArrayLayer = 0;
8051 image_view_ci.subresourceRange.levelCount = 1;
8052 // Setting both depth & stencil aspect bits is illegal for descriptor
8053 image_view_ci.subresourceRange.aspectMask =
8054 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8055
8056 VkImageView image_view;
8057 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8058 &image_view);
8059 ASSERT_VK_SUCCESS(err);
8060
8061 VkDescriptorImageInfo img_info = {};
8062 img_info.imageView = image_view;
8063 VkWriteDescriptorSet descriptor_write = {};
8064 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8065 descriptor_write.dstBinding = 0;
8066 descriptor_write.descriptorCount = 1;
8067 descriptor_write.pTexelBufferView = NULL;
8068 descriptor_write.pBufferInfo = NULL;
8069 descriptor_write.pImageInfo = &img_info;
8070 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8071 descriptor_write.dstSet = descriptor_set;
8072 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8073 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8075 error_msg);
8076
8077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8078
8079 m_errorMonitor->VerifyFound();
8080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8081 vkDestroyImage(m_device->device(), image, NULL);
8082 vkFreeMemory(m_device->device(), image_mem, NULL);
8083 vkDestroyImageView(m_device->device(), image_view, NULL);
8084 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8086}
8087
Karl Schultz6addd812016-02-02 17:17:23 -07008088TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008089 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008090 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008091
Karl Schultz6addd812016-02-02 17:17:23 -07008092 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008093 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8094 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8095 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008096
Tobin Ehlis3b780662015-05-28 12:11:26 -06008097 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008098 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008099 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008100 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8101 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008102
8103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8105 ds_pool_ci.pNext = NULL;
8106 ds_pool_ci.maxSets = 1;
8107 ds_pool_ci.poolSizeCount = 1;
8108 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008109
Tobin Ehlis3b780662015-05-28 12:11:26 -06008110 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008111 err =
8112 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008113 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008114 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008115 dsl_binding.binding = 0;
8116 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8117 dsl_binding.descriptorCount = 1;
8118 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8119 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008120
Tony Barboureb254902015-07-15 12:50:33 -06008121 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008122 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8123 ds_layout_ci.pNext = NULL;
8124 ds_layout_ci.bindingCount = 1;
8125 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008126
Tobin Ehlis3b780662015-05-28 12:11:26 -06008127 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8129 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008130 ASSERT_VK_SUCCESS(err);
8131
8132 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008135 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008136 alloc_info.descriptorPool = ds_pool;
8137 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8139 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008140 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008141
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008142 VkSamplerCreateInfo sampler_ci = {};
8143 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8144 sampler_ci.pNext = NULL;
8145 sampler_ci.magFilter = VK_FILTER_NEAREST;
8146 sampler_ci.minFilter = VK_FILTER_NEAREST;
8147 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8148 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8149 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8150 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8151 sampler_ci.mipLodBias = 1.0;
8152 sampler_ci.anisotropyEnable = VK_FALSE;
8153 sampler_ci.maxAnisotropy = 1;
8154 sampler_ci.compareEnable = VK_FALSE;
8155 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8156 sampler_ci.minLod = 1.0;
8157 sampler_ci.maxLod = 1.0;
8158 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8159 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8160 VkSampler sampler;
8161 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8162 ASSERT_VK_SUCCESS(err);
8163
8164 VkDescriptorImageInfo info = {};
8165 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008166
8167 VkWriteDescriptorSet descriptor_write;
8168 memset(&descriptor_write, 0, sizeof(descriptor_write));
8169 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008170 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008171 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008172 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008173 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008174 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008175
8176 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8177
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008178 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008179
Chia-I Wuf7458c52015-10-26 21:10:41 +08008180 vkDestroySampler(m_device->device(), sampler, NULL);
8181 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8182 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008183}
8184
Karl Schultz6addd812016-02-02 17:17:23 -07008185TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008186 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008187 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008188
Karl Schultz6addd812016-02-02 17:17:23 -07008189 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008190 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8191 " binding #0 with 1 total descriptors but update of 1 descriptors "
8192 "starting at binding offset of 0 combined with update array element "
8193 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008194
Tobin Ehlis3b780662015-05-28 12:11:26 -06008195 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008196 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008197 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008198 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8199 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008200
8201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8203 ds_pool_ci.pNext = NULL;
8204 ds_pool_ci.maxSets = 1;
8205 ds_pool_ci.poolSizeCount = 1;
8206 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008207
Tobin Ehlis3b780662015-05-28 12:11:26 -06008208 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008209 err =
8210 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008211 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008212
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;
Tony Barboureb254902015-07-15 12:50:33 -06008219
8220 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
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008241 // Correctly update descriptor to avoid "NOT_UPDATED" error
8242 VkDescriptorBufferInfo buff_info = {};
8243 buff_info.buffer =
8244 VkBuffer(0); // Don't care about buffer handle for this test
8245 buff_info.offset = 0;
8246 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008247
8248 VkWriteDescriptorSet descriptor_write;
8249 memset(&descriptor_write, 0, sizeof(descriptor_write));
8250 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008251 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008252 descriptor_write.dstArrayElement =
8253 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008254 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8256 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008257
8258 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8259
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008260 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008261
Chia-I Wuf7458c52015-10-26 21:10:41 +08008262 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8263 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008264}
8265
Karl Schultz6addd812016-02-02 17:17:23 -07008266TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8267 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8268 // index 2
8269 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008270
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8272 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008273
Tobin Ehlis3b780662015-05-28 12:11:26 -06008274 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008275 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008276 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008277 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8278 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008279
8280 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008281 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8282 ds_pool_ci.pNext = NULL;
8283 ds_pool_ci.maxSets = 1;
8284 ds_pool_ci.poolSizeCount = 1;
8285 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008286
Tobin Ehlis3b780662015-05-28 12:11:26 -06008287 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008288 err =
8289 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008290 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008291
Tony Barboureb254902015-07-15 12:50:33 -06008292 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008293 dsl_binding.binding = 0;
8294 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8295 dsl_binding.descriptorCount = 1;
8296 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8297 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008298
8299 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008300 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8301 ds_layout_ci.pNext = NULL;
8302 ds_layout_ci.bindingCount = 1;
8303 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008304 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8306 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008307 ASSERT_VK_SUCCESS(err);
8308
8309 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008310 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008311 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008312 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008313 alloc_info.descriptorPool = ds_pool;
8314 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008315 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8316 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008317 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008318
Tony Barboureb254902015-07-15 12:50:33 -06008319 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008320 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8321 sampler_ci.pNext = NULL;
8322 sampler_ci.magFilter = VK_FILTER_NEAREST;
8323 sampler_ci.minFilter = VK_FILTER_NEAREST;
8324 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8325 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8326 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8327 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8328 sampler_ci.mipLodBias = 1.0;
8329 sampler_ci.anisotropyEnable = VK_FALSE;
8330 sampler_ci.maxAnisotropy = 1;
8331 sampler_ci.compareEnable = VK_FALSE;
8332 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8333 sampler_ci.minLod = 1.0;
8334 sampler_ci.maxLod = 1.0;
8335 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8336 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008337
Tobin Ehlis3b780662015-05-28 12:11:26 -06008338 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008339 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008340 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008341
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008342 VkDescriptorImageInfo info = {};
8343 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008344
8345 VkWriteDescriptorSet descriptor_write;
8346 memset(&descriptor_write, 0, sizeof(descriptor_write));
8347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008348 descriptor_write.dstSet = descriptorSet;
8349 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008350 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008351 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008352 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008353 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008354
8355 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8356
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008357 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008358
Chia-I Wuf7458c52015-10-26 21:10:41 +08008359 vkDestroySampler(m_device->device(), sampler, NULL);
8360 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8361 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008362}
8363
Karl Schultz6addd812016-02-02 17:17:23 -07008364TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8365 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8366 // types
8367 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008368
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008370 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008371
Tobin Ehlis3b780662015-05-28 12:11:26 -06008372 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008373
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_UNIFORM_BUFFER;
8376 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -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;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008384
Tobin Ehlis3b780662015-05-28 12:11:26 -06008385 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008386 err =
8387 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008388 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008389 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008390 dsl_binding.binding = 0;
8391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8392 dsl_binding.descriptorCount = 1;
8393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8394 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008395
Tony Barboureb254902015-07-15 12:50:33 -06008396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8398 ds_layout_ci.pNext = NULL;
8399 ds_layout_ci.bindingCount = 1;
8400 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008401
Tobin Ehlis3b780662015-05-28 12:11:26 -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 Ehlis3b780662015-05-28 12:11:26 -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;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -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 Ehlis3b780662015-05-28 12:11:26 -06008415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008416
Tony Barboureb254902015-07-15 12:50:33 -06008417 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 Ehlis3b780662015-05-28 12:11:26 -06008435 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008436 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008437 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008438
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008439 VkDescriptorImageInfo info = {};
8440 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008441
8442 VkWriteDescriptorSet descriptor_write;
8443 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008444 descriptor_write.sType =
8445 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008446 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008447 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008448 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008449 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008450 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008451
8452 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8453
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008454 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008455
Chia-I Wuf7458c52015-10-26 21:10:41 +08008456 vkDestroySampler(m_device->device(), sampler, NULL);
8457 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8458 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008459}
8460
Karl Schultz6addd812016-02-02 17:17:23 -07008461TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008462 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008463 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008464
Karl Schultz6addd812016-02-02 17:17:23 -07008465 m_errorMonitor->SetDesiredFailureMsg(
8466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008467 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008468
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008469 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008470 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8471 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008472 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008473 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8474 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008475
8476 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008477 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8478 ds_pool_ci.pNext = NULL;
8479 ds_pool_ci.maxSets = 1;
8480 ds_pool_ci.poolSizeCount = 1;
8481 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008482
8483 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008484 err =
8485 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008486 ASSERT_VK_SUCCESS(err);
8487
8488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008489 dsl_binding.binding = 0;
8490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8491 dsl_binding.descriptorCount = 1;
8492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008494
8495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8497 ds_layout_ci.pNext = NULL;
8498 ds_layout_ci.bindingCount = 1;
8499 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008500 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8502 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008503 ASSERT_VK_SUCCESS(err);
8504
8505 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008508 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008509 alloc_info.descriptorPool = ds_pool;
8510 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8512 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008513 ASSERT_VK_SUCCESS(err);
8514
Karl Schultz6addd812016-02-02 17:17:23 -07008515 VkSampler sampler =
8516 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008517
8518 VkDescriptorImageInfo descriptor_info;
8519 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8520 descriptor_info.sampler = sampler;
8521
8522 VkWriteDescriptorSet descriptor_write;
8523 memset(&descriptor_write, 0, sizeof(descriptor_write));
8524 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008525 descriptor_write.dstSet = descriptorSet;
8526 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008527 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008528 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8529 descriptor_write.pImageInfo = &descriptor_info;
8530
8531 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8532
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008533 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008534
Chia-I Wuf7458c52015-10-26 21:10:41 +08008535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008537}
8538
Karl Schultz6addd812016-02-02 17:17:23 -07008539TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8540 // Create a single combined Image/Sampler descriptor and send it an invalid
8541 // imageView
8542 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008543
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8545 "Attempted write update to combined "
8546 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008547 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008548
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008549 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008550 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008551 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8552 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008553
8554 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008555 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8556 ds_pool_ci.pNext = NULL;
8557 ds_pool_ci.maxSets = 1;
8558 ds_pool_ci.poolSizeCount = 1;
8559 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008560
8561 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008562 err =
8563 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008564 ASSERT_VK_SUCCESS(err);
8565
8566 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008567 dsl_binding.binding = 0;
8568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8569 dsl_binding.descriptorCount = 1;
8570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8571 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008572
8573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8575 ds_layout_ci.pNext = NULL;
8576 ds_layout_ci.bindingCount = 1;
8577 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008578 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8580 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008581 ASSERT_VK_SUCCESS(err);
8582
8583 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008584 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008586 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008587 alloc_info.descriptorPool = ds_pool;
8588 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8590 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008591 ASSERT_VK_SUCCESS(err);
8592
8593 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008594 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8595 sampler_ci.pNext = NULL;
8596 sampler_ci.magFilter = VK_FILTER_NEAREST;
8597 sampler_ci.minFilter = VK_FILTER_NEAREST;
8598 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8599 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8600 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8601 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8602 sampler_ci.mipLodBias = 1.0;
8603 sampler_ci.anisotropyEnable = VK_FALSE;
8604 sampler_ci.maxAnisotropy = 1;
8605 sampler_ci.compareEnable = VK_FALSE;
8606 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8607 sampler_ci.minLod = 1.0;
8608 sampler_ci.maxLod = 1.0;
8609 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8610 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008611
8612 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008613 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008614 ASSERT_VK_SUCCESS(err);
8615
Karl Schultz6addd812016-02-02 17:17:23 -07008616 VkImageView view =
8617 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008618
8619 VkDescriptorImageInfo descriptor_info;
8620 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8621 descriptor_info.sampler = sampler;
8622 descriptor_info.imageView = view;
8623
8624 VkWriteDescriptorSet descriptor_write;
8625 memset(&descriptor_write, 0, sizeof(descriptor_write));
8626 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008627 descriptor_write.dstSet = descriptorSet;
8628 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008629 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8631 descriptor_write.pImageInfo = &descriptor_info;
8632
8633 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8634
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008635 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008636
Chia-I Wuf7458c52015-10-26 21:10:41 +08008637 vkDestroySampler(m_device->device(), sampler, NULL);
8638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8639 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008640}
8641
Karl Schultz6addd812016-02-02 17:17:23 -07008642TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8643 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8644 // into the other
8645 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008646
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8648 " binding #1 with type "
8649 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8650 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008651
Tobin Ehlis04356f92015-10-27 16:35:27 -06008652 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008653 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008654 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008655 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8656 ds_type_count[0].descriptorCount = 1;
8657 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8658 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008659
8660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8662 ds_pool_ci.pNext = NULL;
8663 ds_pool_ci.maxSets = 1;
8664 ds_pool_ci.poolSizeCount = 2;
8665 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008666
8667 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008668 err =
8669 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008670 ASSERT_VK_SUCCESS(err);
8671 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008672 dsl_binding[0].binding = 0;
8673 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8674 dsl_binding[0].descriptorCount = 1;
8675 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8676 dsl_binding[0].pImmutableSamplers = NULL;
8677 dsl_binding[1].binding = 1;
8678 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8679 dsl_binding[1].descriptorCount = 1;
8680 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8681 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008682
8683 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008684 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8685 ds_layout_ci.pNext = NULL;
8686 ds_layout_ci.bindingCount = 2;
8687 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008688
8689 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008690 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8691 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008692 ASSERT_VK_SUCCESS(err);
8693
8694 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008695 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008696 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008697 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008698 alloc_info.descriptorPool = ds_pool;
8699 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008700 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8701 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008702 ASSERT_VK_SUCCESS(err);
8703
8704 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008705 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8706 sampler_ci.pNext = NULL;
8707 sampler_ci.magFilter = VK_FILTER_NEAREST;
8708 sampler_ci.minFilter = VK_FILTER_NEAREST;
8709 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8710 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8711 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8712 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8713 sampler_ci.mipLodBias = 1.0;
8714 sampler_ci.anisotropyEnable = VK_FALSE;
8715 sampler_ci.maxAnisotropy = 1;
8716 sampler_ci.compareEnable = VK_FALSE;
8717 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8718 sampler_ci.minLod = 1.0;
8719 sampler_ci.maxLod = 1.0;
8720 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8721 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008722
8723 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008724 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008725 ASSERT_VK_SUCCESS(err);
8726
8727 VkDescriptorImageInfo info = {};
8728 info.sampler = sampler;
8729
8730 VkWriteDescriptorSet descriptor_write;
8731 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8732 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008733 descriptor_write.dstSet = descriptorSet;
8734 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008735 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008736 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8737 descriptor_write.pImageInfo = &info;
8738 // This write update should succeed
8739 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8740 // Now perform a copy update that fails due to type mismatch
8741 VkCopyDescriptorSet copy_ds_update;
8742 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8743 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8744 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008745 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008747 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008748 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008749 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8750
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008751 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008752 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008753 m_errorMonitor->SetDesiredFailureMsg(
8754 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008755 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008756 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8757 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8758 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008759 copy_ds_update.srcBinding =
8760 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008761 copy_ds_update.dstSet = descriptorSet;
8762 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008763 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008764 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008766 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008767
Tobin Ehlis04356f92015-10-27 16:35:27 -06008768 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008769 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008770 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8771 "update array offset of 0 and update of "
8772 "5 descriptors oversteps total number "
8773 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008774
Tobin Ehlis04356f92015-10-27 16:35:27 -06008775 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8776 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8777 copy_ds_update.srcSet = descriptorSet;
8778 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008779 copy_ds_update.dstSet = descriptorSet;
8780 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008781 copy_ds_update.descriptorCount =
8782 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008783 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008785 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008786
Chia-I Wuf7458c52015-10-26 21:10:41 +08008787 vkDestroySampler(m_device->device(), sampler, NULL);
8788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8789 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008790}
8791
Karl Schultz6addd812016-02-02 17:17:23 -07008792TEST_F(VkLayerTest, NumSamplesMismatch) {
8793 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8794 // sampleCount
8795 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008796
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008798 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008799
Tobin Ehlis3b780662015-05-28 12:11:26 -06008800 ASSERT_NO_FATAL_FAILURE(InitState());
8801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008802 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008803 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008804 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008805
8806 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008807 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8808 ds_pool_ci.pNext = NULL;
8809 ds_pool_ci.maxSets = 1;
8810 ds_pool_ci.poolSizeCount = 1;
8811 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008812
Tobin Ehlis3b780662015-05-28 12:11:26 -06008813 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008814 err =
8815 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008816 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008817
Tony Barboureb254902015-07-15 12:50:33 -06008818 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008819 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008820 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008821 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008822 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8823 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824
Tony Barboureb254902015-07-15 12:50:33 -06008825 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8826 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8827 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008828 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008829 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008830
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008832 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8833 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008834 ASSERT_VK_SUCCESS(err);
8835
8836 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008837 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008838 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008839 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008840 alloc_info.descriptorPool = ds_pool;
8841 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008842 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8843 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844 ASSERT_VK_SUCCESS(err);
8845
Tony Barboureb254902015-07-15 12:50:33 -06008846 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008847 pipe_ms_state_ci.sType =
8848 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8849 pipe_ms_state_ci.pNext = NULL;
8850 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8851 pipe_ms_state_ci.sampleShadingEnable = 0;
8852 pipe_ms_state_ci.minSampleShading = 1.0;
8853 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008854
Tony Barboureb254902015-07-15 12:50:33 -06008855 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008856 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8857 pipeline_layout_ci.pNext = NULL;
8858 pipeline_layout_ci.setLayoutCount = 1;
8859 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860
8861 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008862 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8863 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008864 ASSERT_VK_SUCCESS(err);
8865
Karl Schultz6addd812016-02-02 17:17:23 -07008866 VkShaderObj vs(m_device, bindStateVertShaderText,
8867 VK_SHADER_STAGE_VERTEX_BIT, this);
8868 VkShaderObj fs(m_device, bindStateFragShaderText,
8869 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008870 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008871 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008872 VkPipelineObj pipe(m_device);
8873 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008874 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008875 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008876 pipe.SetMSAA(&pipe_ms_state_ci);
8877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008878
Tony Barbourfe3351b2015-07-28 10:17:20 -06008879 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008880 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8881 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008882
Mark Young29927482016-05-04 14:38:51 -06008883 // Render triangle (the error should trigger on the attempt to draw).
8884 Draw(3, 1, 0, 0);
8885
8886 // Finalize recording of the command buffer
8887 EndCommandBuffer();
8888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008889 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008890
Chia-I Wuf7458c52015-10-26 21:10:41 +08008891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008894}
Mark Young29927482016-05-04 14:38:51 -06008895
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008896TEST_F(VkLayerTest, RenderPassIncompatible) {
8897 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8898 "Initial case is drawing with an active renderpass that's "
8899 "not compatible with the bound PSO's creation renderpass");
8900 VkResult err;
8901
8902 ASSERT_NO_FATAL_FAILURE(InitState());
8903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8904
8905 VkDescriptorSetLayoutBinding dsl_binding = {};
8906 dsl_binding.binding = 0;
8907 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8908 dsl_binding.descriptorCount = 1;
8909 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8910 dsl_binding.pImmutableSamplers = NULL;
8911
8912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8914 ds_layout_ci.pNext = NULL;
8915 ds_layout_ci.bindingCount = 1;
8916 ds_layout_ci.pBindings = &dsl_binding;
8917
8918 VkDescriptorSetLayout ds_layout;
8919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8920 &ds_layout);
8921 ASSERT_VK_SUCCESS(err);
8922
8923 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8924 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8925 pipeline_layout_ci.pNext = NULL;
8926 pipeline_layout_ci.setLayoutCount = 1;
8927 pipeline_layout_ci.pSetLayouts = &ds_layout;
8928
8929 VkPipelineLayout pipeline_layout;
8930 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8931 &pipeline_layout);
8932 ASSERT_VK_SUCCESS(err);
8933
8934 VkShaderObj vs(m_device, bindStateVertShaderText,
8935 VK_SHADER_STAGE_VERTEX_BIT, this);
8936 VkShaderObj fs(m_device, bindStateFragShaderText,
8937 VK_SHADER_STAGE_FRAGMENT_BIT,
8938 this); // We shouldn't need a fragment shader
8939 // but add it to be able to run on more devices
8940 // Create a renderpass that will be incompatible with default renderpass
8941 VkAttachmentReference attach = {};
8942 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8943 VkAttachmentReference color_att = {};
8944 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8945 VkSubpassDescription subpass = {};
8946 subpass.inputAttachmentCount = 1;
8947 subpass.pInputAttachments = &attach;
8948 subpass.colorAttachmentCount = 1;
8949 subpass.pColorAttachments = &color_att;
8950 VkRenderPassCreateInfo rpci = {};
8951 rpci.subpassCount = 1;
8952 rpci.pSubpasses = &subpass;
8953 rpci.attachmentCount = 1;
8954 VkAttachmentDescription attach_desc = {};
8955 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8956 // Format incompatible with PSO RP color attach format RGBA8_UNORM
8957 attach_desc.format = VK_FORMAT_UNDEFINED;
8958 rpci.pAttachments = &attach_desc;
8959 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8960 VkRenderPass rp;
8961 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8962 VkPipelineObj pipe(m_device);
8963 pipe.AddShader(&vs);
8964 pipe.AddShader(&fs);
8965 pipe.AddColorAttachment();
8966 VkViewport view_port = {};
8967 m_viewports.push_back(view_port);
8968 pipe.SetViewport(m_viewports);
8969 VkRect2D rect = {};
8970 m_scissors.push_back(rect);
8971 pipe.SetScissor(m_scissors);
8972 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8973
8974 VkCommandBufferInheritanceInfo cbii = {};
8975 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8976 cbii.renderPass = rp;
8977 cbii.subpass = 0;
8978 VkCommandBufferBeginInfo cbbi = {};
8979 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8980 cbbi.pInheritanceInfo = &cbii;
8981 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
8982 VkRenderPassBeginInfo rpbi = {};
8983 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8984 rpbi.framebuffer = m_framebuffer;
8985 rpbi.renderPass = rp;
8986 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
8987 VK_SUBPASS_CONTENTS_INLINE);
8988 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8989 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8990
8991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8992 " is incompatible w/ gfx pipeline ");
8993 // Render triangle (the error should trigger on the attempt to draw).
8994 Draw(3, 1, 0, 0);
8995
8996 // Finalize recording of the command buffer
8997 EndCommandBuffer();
8998
8999 m_errorMonitor->VerifyFound();
9000
9001 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9002 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9003 vkDestroyRenderPass(m_device->device(), rp, NULL);
9004}
9005
Mark Youngc89c6312016-03-31 16:03:20 -06009006TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9007 // Create Pipeline where the number of blend attachments doesn't match the
9008 // number of color attachments. In this case, we don't add any color
9009 // blend attachments even though we have a color attachment.
9010 VkResult err;
9011
9012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06009013 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009014
9015 ASSERT_NO_FATAL_FAILURE(InitState());
9016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9017 VkDescriptorPoolSize ds_type_count = {};
9018 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9019 ds_type_count.descriptorCount = 1;
9020
9021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9023 ds_pool_ci.pNext = NULL;
9024 ds_pool_ci.maxSets = 1;
9025 ds_pool_ci.poolSizeCount = 1;
9026 ds_pool_ci.pPoolSizes = &ds_type_count;
9027
9028 VkDescriptorPool ds_pool;
9029 err =
9030 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9031 ASSERT_VK_SUCCESS(err);
9032
9033 VkDescriptorSetLayoutBinding dsl_binding = {};
9034 dsl_binding.binding = 0;
9035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9036 dsl_binding.descriptorCount = 1;
9037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9038 dsl_binding.pImmutableSamplers = NULL;
9039
9040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9042 ds_layout_ci.pNext = NULL;
9043 ds_layout_ci.bindingCount = 1;
9044 ds_layout_ci.pBindings = &dsl_binding;
9045
9046 VkDescriptorSetLayout ds_layout;
9047 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9048 &ds_layout);
9049 ASSERT_VK_SUCCESS(err);
9050
9051 VkDescriptorSet descriptorSet;
9052 VkDescriptorSetAllocateInfo alloc_info = {};
9053 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9054 alloc_info.descriptorSetCount = 1;
9055 alloc_info.descriptorPool = ds_pool;
9056 alloc_info.pSetLayouts = &ds_layout;
9057 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9058 &descriptorSet);
9059 ASSERT_VK_SUCCESS(err);
9060
9061 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9062 pipe_ms_state_ci.sType =
9063 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9064 pipe_ms_state_ci.pNext = NULL;
9065 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9066 pipe_ms_state_ci.sampleShadingEnable = 0;
9067 pipe_ms_state_ci.minSampleShading = 1.0;
9068 pipe_ms_state_ci.pSampleMask = NULL;
9069
9070 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9071 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9072 pipeline_layout_ci.pNext = NULL;
9073 pipeline_layout_ci.setLayoutCount = 1;
9074 pipeline_layout_ci.pSetLayouts = &ds_layout;
9075
9076 VkPipelineLayout pipeline_layout;
9077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9078 &pipeline_layout);
9079 ASSERT_VK_SUCCESS(err);
9080
9081 VkShaderObj vs(m_device, bindStateVertShaderText,
9082 VK_SHADER_STAGE_VERTEX_BIT, this);
9083 VkShaderObj fs(m_device, bindStateFragShaderText,
9084 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009085 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009086 // but add it to be able to run on more devices
9087 VkPipelineObj pipe(m_device);
9088 pipe.AddShader(&vs);
9089 pipe.AddShader(&fs);
9090 pipe.SetMSAA(&pipe_ms_state_ci);
9091 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9092
9093 BeginCommandBuffer();
9094 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9095 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9096
Mark Young29927482016-05-04 14:38:51 -06009097 // Render triangle (the error should trigger on the attempt to draw).
9098 Draw(3, 1, 0, 0);
9099
9100 // Finalize recording of the command buffer
9101 EndCommandBuffer();
9102
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009103 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009104
9105 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9106 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9107 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9108}
Mark Young29927482016-05-04 14:38:51 -06009109
Mark Muellerd4914412016-06-13 17:52:06 -06009110TEST_F(VkLayerTest, MissingClearAttachment) {
9111 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9112 "structure passed to vkCmdClearAttachments");
9113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9114 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9115 "reference array of active subpass 0");
9116
9117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9118 m_errorMonitor->VerifyFound();
9119}
9120
Karl Schultz6addd812016-02-02 17:17:23 -07009121TEST_F(VkLayerTest, ClearCmdNoDraw) {
9122 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9123 // to issuing a Draw
9124 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009125
Karl Schultz6addd812016-02-02 17:17:23 -07009126 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009127 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009128 "vkCmdClearAttachments() issued on CB object ");
9129
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009130 ASSERT_NO_FATAL_FAILURE(InitState());
9131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009132
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009133 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009134 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9135 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009136
9137 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009138 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9139 ds_pool_ci.pNext = NULL;
9140 ds_pool_ci.maxSets = 1;
9141 ds_pool_ci.poolSizeCount = 1;
9142 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009143
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009144 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009145 err =
9146 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009147 ASSERT_VK_SUCCESS(err);
9148
Tony Barboureb254902015-07-15 12:50:33 -06009149 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009150 dsl_binding.binding = 0;
9151 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9152 dsl_binding.descriptorCount = 1;
9153 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9154 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009155
Tony Barboureb254902015-07-15 12:50:33 -06009156 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009157 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9158 ds_layout_ci.pNext = NULL;
9159 ds_layout_ci.bindingCount = 1;
9160 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009161
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009162 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9164 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009165 ASSERT_VK_SUCCESS(err);
9166
9167 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009170 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009171 alloc_info.descriptorPool = ds_pool;
9172 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9174 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009175 ASSERT_VK_SUCCESS(err);
9176
Tony Barboureb254902015-07-15 12:50:33 -06009177 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009178 pipe_ms_state_ci.sType =
9179 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9180 pipe_ms_state_ci.pNext = NULL;
9181 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9182 pipe_ms_state_ci.sampleShadingEnable = 0;
9183 pipe_ms_state_ci.minSampleShading = 1.0;
9184 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009185
Tony Barboureb254902015-07-15 12:50:33 -06009186 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009187 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9188 pipeline_layout_ci.pNext = NULL;
9189 pipeline_layout_ci.setLayoutCount = 1;
9190 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009191
9192 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9194 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009195 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009196
Karl Schultz6addd812016-02-02 17:17:23 -07009197 VkShaderObj vs(m_device, bindStateVertShaderText,
9198 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009199 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009200 // on more devices
9201 VkShaderObj fs(m_device, bindStateFragShaderText,
9202 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009203
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009204 VkPipelineObj pipe(m_device);
9205 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009206 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009207 pipe.SetMSAA(&pipe_ms_state_ci);
9208 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009209
9210 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009211
Karl Schultz6addd812016-02-02 17:17:23 -07009212 // Main thing we care about for this test is that the VkImage obj we're
9213 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009214 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009215 VkClearAttachment color_attachment;
9216 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9217 color_attachment.clearValue.color.float32[0] = 1.0;
9218 color_attachment.clearValue.color.float32[1] = 1.0;
9219 color_attachment.clearValue.color.float32[2] = 1.0;
9220 color_attachment.clearValue.color.float32[3] = 1.0;
9221 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009222 VkClearRect clear_rect = {
9223 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009224
Karl Schultz6addd812016-02-02 17:17:23 -07009225 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9226 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009227
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009228 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009229
Chia-I Wuf7458c52015-10-26 21:10:41 +08009230 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9231 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9232 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009233}
9234
Karl Schultz6addd812016-02-02 17:17:23 -07009235TEST_F(VkLayerTest, VtxBufferBadIndex) {
9236 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009237
Karl Schultz6addd812016-02-02 17:17:23 -07009238 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009239 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009240 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009241
Tobin Ehlis502480b2015-06-24 15:53:07 -06009242 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009243 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009245
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009246 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009247 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9248 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009249
9250 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009251 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9252 ds_pool_ci.pNext = NULL;
9253 ds_pool_ci.maxSets = 1;
9254 ds_pool_ci.poolSizeCount = 1;
9255 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009256
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009257 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009258 err =
9259 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009260 ASSERT_VK_SUCCESS(err);
9261
Tony Barboureb254902015-07-15 12:50:33 -06009262 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009263 dsl_binding.binding = 0;
9264 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9265 dsl_binding.descriptorCount = 1;
9266 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9267 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009268
Tony Barboureb254902015-07-15 12:50:33 -06009269 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009270 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9271 ds_layout_ci.pNext = NULL;
9272 ds_layout_ci.bindingCount = 1;
9273 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009274
Tobin Ehlis502480b2015-06-24 15:53:07 -06009275 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009276 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9277 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009278 ASSERT_VK_SUCCESS(err);
9279
9280 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009281 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009282 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009283 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009284 alloc_info.descriptorPool = ds_pool;
9285 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009286 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9287 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009288 ASSERT_VK_SUCCESS(err);
9289
Tony Barboureb254902015-07-15 12:50:33 -06009290 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009291 pipe_ms_state_ci.sType =
9292 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9293 pipe_ms_state_ci.pNext = NULL;
9294 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9295 pipe_ms_state_ci.sampleShadingEnable = 0;
9296 pipe_ms_state_ci.minSampleShading = 1.0;
9297 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009298
Tony Barboureb254902015-07-15 12:50:33 -06009299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9301 pipeline_layout_ci.pNext = NULL;
9302 pipeline_layout_ci.setLayoutCount = 1;
9303 pipeline_layout_ci.pSetLayouts = &ds_layout;
9304 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009305
Karl Schultz6addd812016-02-02 17:17:23 -07009306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9307 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009308 ASSERT_VK_SUCCESS(err);
9309
Karl Schultz6addd812016-02-02 17:17:23 -07009310 VkShaderObj vs(m_device, bindStateVertShaderText,
9311 VK_SHADER_STAGE_VERTEX_BIT, this);
9312 VkShaderObj fs(m_device, bindStateFragShaderText,
9313 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009314 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009315 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009316 VkPipelineObj pipe(m_device);
9317 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009318 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009319 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009320 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009321 pipe.SetViewport(m_viewports);
9322 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009323 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009324
9325 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009326 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9327 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009328 // Don't care about actual data, just need to get to draw to flag error
9329 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009330 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9331 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009332 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009333 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009334
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009335 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009336
Chia-I Wuf7458c52015-10-26 21:10:41 +08009337 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9338 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9339 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009340}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009341// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9342TEST_F(VkLayerTest, InvalidImageLayout) {
9343 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9344 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9345 "images in the wrong layout when they're copied or transitioned.");
9346 // 3 in ValidateCmdBufImageLayouts
9347 // * -1 Attempt to submit cmd buf w/ deleted image
9348 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9349 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9350 m_errorMonitor->SetDesiredFailureMsg(
9351 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9352 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9353
9354 ASSERT_NO_FATAL_FAILURE(InitState());
9355 // Create src & dst images to use for copy operations
9356 VkImage src_image;
9357 VkImage dst_image;
9358
9359 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9360 const int32_t tex_width = 32;
9361 const int32_t tex_height = 32;
9362
9363 VkImageCreateInfo image_create_info = {};
9364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9365 image_create_info.pNext = NULL;
9366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9367 image_create_info.format = tex_format;
9368 image_create_info.extent.width = tex_width;
9369 image_create_info.extent.height = tex_height;
9370 image_create_info.extent.depth = 1;
9371 image_create_info.mipLevels = 1;
9372 image_create_info.arrayLayers = 4;
9373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9374 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9375 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9376 image_create_info.flags = 0;
9377
9378 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9379 ASSERT_VK_SUCCESS(err);
9380 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9381 ASSERT_VK_SUCCESS(err);
9382
9383 BeginCommandBuffer();
9384 VkImageCopy copyRegion;
9385 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9386 copyRegion.srcSubresource.mipLevel = 0;
9387 copyRegion.srcSubresource.baseArrayLayer = 0;
9388 copyRegion.srcSubresource.layerCount = 1;
9389 copyRegion.srcOffset.x = 0;
9390 copyRegion.srcOffset.y = 0;
9391 copyRegion.srcOffset.z = 0;
9392 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9393 copyRegion.dstSubresource.mipLevel = 0;
9394 copyRegion.dstSubresource.baseArrayLayer = 0;
9395 copyRegion.dstSubresource.layerCount = 1;
9396 copyRegion.dstOffset.x = 0;
9397 copyRegion.dstOffset.y = 0;
9398 copyRegion.dstOffset.z = 0;
9399 copyRegion.extent.width = 1;
9400 copyRegion.extent.height = 1;
9401 copyRegion.extent.depth = 1;
9402 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9403 m_errorMonitor->VerifyFound();
9404 // Now cause error due to src image layout changing
9405 m_errorMonitor->SetDesiredFailureMsg(
9406 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9407 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9408 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9409 m_errorMonitor->VerifyFound();
9410 // Final src error is due to bad layout type
9411 m_errorMonitor->SetDesiredFailureMsg(
9412 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9413 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9414 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9415 m_errorMonitor->VerifyFound();
9416 // Now verify same checks for dst
9417 m_errorMonitor->SetDesiredFailureMsg(
9418 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9419 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9420 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9421 m_errorMonitor->VerifyFound();
9422 // Now cause error due to src image layout changing
9423 m_errorMonitor->SetDesiredFailureMsg(
9424 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9425 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9426 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9427 m_errorMonitor->VerifyFound();
9428 m_errorMonitor->SetDesiredFailureMsg(
9429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9430 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9431 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9432 m_errorMonitor->VerifyFound();
9433 // Now cause error due to bad image layout transition in PipelineBarrier
9434 VkImageMemoryBarrier image_barrier[1] = {};
9435 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9436 image_barrier[0].image = src_image;
9437 image_barrier[0].subresourceRange.layerCount = 2;
9438 image_barrier[0].subresourceRange.levelCount = 2;
9439 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9440 m_errorMonitor->SetDesiredFailureMsg(
9441 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9442 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9443 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9444 m_errorMonitor->VerifyFound();
9445
9446 // Finally some layout errors at RenderPass create time
9447 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9448 VkAttachmentReference attach = {};
9449 // perf warning for GENERAL layout w/ non-DS input attachment
9450 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9451 VkSubpassDescription subpass = {};
9452 subpass.inputAttachmentCount = 1;
9453 subpass.pInputAttachments = &attach;
9454 VkRenderPassCreateInfo rpci = {};
9455 rpci.subpassCount = 1;
9456 rpci.pSubpasses = &subpass;
9457 rpci.attachmentCount = 1;
9458 VkAttachmentDescription attach_desc = {};
9459 attach_desc.format = VK_FORMAT_UNDEFINED;
9460 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009461 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009462 VkRenderPass rp;
9463 m_errorMonitor->SetDesiredFailureMsg(
9464 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9465 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9466 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9467 m_errorMonitor->VerifyFound();
9468 // error w/ non-general layout
9469 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9470
9471 m_errorMonitor->SetDesiredFailureMsg(
9472 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9473 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9474 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9475 m_errorMonitor->VerifyFound();
9476 subpass.inputAttachmentCount = 0;
9477 subpass.colorAttachmentCount = 1;
9478 subpass.pColorAttachments = &attach;
9479 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9480 // perf warning for GENERAL layout on color attachment
9481 m_errorMonitor->SetDesiredFailureMsg(
9482 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9483 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9484 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9485 m_errorMonitor->VerifyFound();
9486 // error w/ non-color opt or GENERAL layout for color attachment
9487 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9488 m_errorMonitor->SetDesiredFailureMsg(
9489 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9490 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9491 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9492 m_errorMonitor->VerifyFound();
9493 subpass.colorAttachmentCount = 0;
9494 subpass.pDepthStencilAttachment = &attach;
9495 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9496 // perf warning for GENERAL layout on DS attachment
9497 m_errorMonitor->SetDesiredFailureMsg(
9498 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9499 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9500 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9501 m_errorMonitor->VerifyFound();
9502 // error w/ non-ds opt or GENERAL layout for color attachment
9503 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9504 m_errorMonitor->SetDesiredFailureMsg(
9505 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9506 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9507 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9508 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009509 // For this error we need a valid renderpass so create default one
9510 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9511 attach.attachment = 0;
9512 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9513 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9514 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9515 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9516 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9517 // Can't do a CLEAR load on READ_ONLY initialLayout
9518 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9519 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9520 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9522 " with invalid first layout "
9523 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9524 "ONLY_OPTIMAL");
9525 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9526 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009527
9528 vkDestroyImage(m_device->device(), src_image, NULL);
9529 vkDestroyImage(m_device->device(), dst_image, NULL);
9530}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009531#endif // DRAW_STATE_TESTS
9532
Tobin Ehlis0788f522015-05-26 16:11:58 -06009533#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009534#if GTEST_IS_THREADSAFE
9535struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009536 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009537 VkEvent event;
9538 bool bailout;
9539};
9540
Karl Schultz6addd812016-02-02 17:17:23 -07009541extern "C" void *AddToCommandBuffer(void *arg) {
9542 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009543
Karl Schultz6addd812016-02-02 17:17:23 -07009544 for (int i = 0; i < 10000; i++) {
9545 vkCmdSetEvent(data->commandBuffer, data->event,
9546 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009547 if (data->bailout) {
9548 break;
9549 }
9550 }
9551 return NULL;
9552}
9553
Karl Schultz6addd812016-02-02 17:17:23 -07009554TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009555 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009556
Karl Schultz6addd812016-02-02 17:17:23 -07009557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9558 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009559
Mike Stroyanaccf7692015-05-12 16:00:45 -06009560 ASSERT_NO_FATAL_FAILURE(InitState());
9561 ASSERT_NO_FATAL_FAILURE(InitViewport());
9562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9563
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009564 // Calls AllocateCommandBuffers
9565 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009566
9567 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009568 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009569
9570 VkEventCreateInfo event_info;
9571 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009572 VkResult err;
9573
9574 memset(&event_info, 0, sizeof(event_info));
9575 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9576
Chia-I Wuf7458c52015-10-26 21:10:41 +08009577 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009578 ASSERT_VK_SUCCESS(err);
9579
Mike Stroyanaccf7692015-05-12 16:00:45 -06009580 err = vkResetEvent(device(), event);
9581 ASSERT_VK_SUCCESS(err);
9582
9583 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009584 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009585 data.event = event;
9586 data.bailout = false;
9587 m_errorMonitor->SetBailout(&data.bailout);
9588 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009589 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009590 // Add many entries to command buffer from this thread at the same time.
9591 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009592
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009593 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009594 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009595
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009596 m_errorMonitor->SetBailout(NULL);
9597
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009598 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009599
Chia-I Wuf7458c52015-10-26 21:10:41 +08009600 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009601}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009602#endif // GTEST_IS_THREADSAFE
9603#endif // THREADING_TESTS
9604
Chris Forbes9f7ff632015-05-25 11:13:08 +12009605#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009606TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009608 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009609
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009610 ASSERT_NO_FATAL_FAILURE(InitState());
9611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9612
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009613 VkShaderModule module;
9614 VkShaderModuleCreateInfo moduleCreateInfo;
9615 struct icd_spv_header spv;
9616
9617 spv.magic = ICD_SPV_MAGIC;
9618 spv.version = ICD_SPV_VERSION;
9619 spv.gen_magic = 0;
9620
9621 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9622 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009623 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009624 moduleCreateInfo.codeSize = 4;
9625 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009626 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009627
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009628 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009629}
9630
Karl Schultz6addd812016-02-02 17:17:23 -07009631TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009633 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009634
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009635 ASSERT_NO_FATAL_FAILURE(InitState());
9636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9637
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009638 VkShaderModule module;
9639 VkShaderModuleCreateInfo moduleCreateInfo;
9640 struct icd_spv_header spv;
9641
9642 spv.magic = ~ICD_SPV_MAGIC;
9643 spv.version = ICD_SPV_VERSION;
9644 spv.gen_magic = 0;
9645
9646 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9647 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009648 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009649 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9650 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009651 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009652
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009653 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009654}
9655
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009656#if 0
9657// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009658TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009660 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009661
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009662 ASSERT_NO_FATAL_FAILURE(InitState());
9663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9664
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009665 VkShaderModule module;
9666 VkShaderModuleCreateInfo moduleCreateInfo;
9667 struct icd_spv_header spv;
9668
9669 spv.magic = ICD_SPV_MAGIC;
9670 spv.version = ~ICD_SPV_VERSION;
9671 spv.gen_magic = 0;
9672
9673 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9674 moduleCreateInfo.pNext = NULL;
9675
Karl Schultz6addd812016-02-02 17:17:23 -07009676 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009677 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9678 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009679 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009680
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009681 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009682}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009683#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009684
Karl Schultz6addd812016-02-02 17:17:23 -07009685TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009687 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009688
Chris Forbes9f7ff632015-05-25 11:13:08 +12009689 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009691
9692 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009693 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009694 "\n"
9695 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009696 "out gl_PerVertex {\n"
9697 " vec4 gl_Position;\n"
9698 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009699 "void main(){\n"
9700 " gl_Position = vec4(1);\n"
9701 " x = 0;\n"
9702 "}\n";
9703 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009704 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009705 "\n"
9706 "layout(location=0) out vec4 color;\n"
9707 "void main(){\n"
9708 " color = vec4(1);\n"
9709 "}\n";
9710
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009711 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9712 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009713
9714 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009715 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009716 pipe.AddShader(&vs);
9717 pipe.AddShader(&fs);
9718
Chris Forbes9f7ff632015-05-25 11:13:08 +12009719 VkDescriptorSetObj descriptorSet(m_device);
9720 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009721 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009722
Tony Barbour5781e8f2015-08-04 16:23:11 -06009723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009724
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009725 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009726}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009727
Karl Schultz6addd812016-02-02 17:17:23 -07009728TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009730 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009731
Chris Forbes59cb88d2015-05-25 11:13:13 +12009732 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009734
9735 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009736 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009737 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009738 "out gl_PerVertex {\n"
9739 " vec4 gl_Position;\n"
9740 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009741 "void main(){\n"
9742 " gl_Position = vec4(1);\n"
9743 "}\n";
9744 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009745 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009746 "\n"
9747 "layout(location=0) in float x;\n"
9748 "layout(location=0) out vec4 color;\n"
9749 "void main(){\n"
9750 " color = vec4(x);\n"
9751 "}\n";
9752
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009755
9756 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009757 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009758 pipe.AddShader(&vs);
9759 pipe.AddShader(&fs);
9760
Chris Forbes59cb88d2015-05-25 11:13:13 +12009761 VkDescriptorSetObj descriptorSet(m_device);
9762 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009764
Tony Barbour5781e8f2015-08-04 16:23:11 -06009765 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009766
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009767 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009768}
9769
Karl Schultz6addd812016-02-02 17:17:23 -07009770TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009772 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009773
9774 ASSERT_NO_FATAL_FAILURE(InitState());
9775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9776
9777 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009778 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009779 "\n"
9780 "out gl_PerVertex {\n"
9781 " vec4 gl_Position;\n"
9782 "};\n"
9783 "void main(){\n"
9784 " gl_Position = vec4(1);\n"
9785 "}\n";
9786 char const *fsSource =
9787 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009788 "\n"
9789 "in block { layout(location=0) float x; } ins;\n"
9790 "layout(location=0) out vec4 color;\n"
9791 "void main(){\n"
9792 " color = vec4(ins.x);\n"
9793 "}\n";
9794
9795 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9796 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9797
9798 VkPipelineObj pipe(m_device);
9799 pipe.AddColorAttachment();
9800 pipe.AddShader(&vs);
9801 pipe.AddShader(&fs);
9802
9803 VkDescriptorSetObj descriptorSet(m_device);
9804 descriptorSet.AppendDummy();
9805 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9806
9807 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9808
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009809 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009810}
9811
Karl Schultz6addd812016-02-02 17:17:23 -07009812TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009814 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009815 "output arr[2] of float32' vs 'ptr to "
9816 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009817
9818 ASSERT_NO_FATAL_FAILURE(InitState());
9819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9820
9821 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009822 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009823 "\n"
9824 "layout(location=0) out float x[2];\n"
9825 "out gl_PerVertex {\n"
9826 " vec4 gl_Position;\n"
9827 "};\n"
9828 "void main(){\n"
9829 " x[0] = 0; x[1] = 0;\n"
9830 " gl_Position = vec4(1);\n"
9831 "}\n";
9832 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009833 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009834 "\n"
9835 "layout(location=0) in float x[3];\n"
9836 "layout(location=0) out vec4 color;\n"
9837 "void main(){\n"
9838 " color = vec4(x[0] + x[1] + x[2]);\n"
9839 "}\n";
9840
9841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9843
9844 VkPipelineObj pipe(m_device);
9845 pipe.AddColorAttachment();
9846 pipe.AddShader(&vs);
9847 pipe.AddShader(&fs);
9848
9849 VkDescriptorSetObj descriptorSet(m_device);
9850 descriptorSet.AppendDummy();
9851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9852
9853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9854
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009855 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009856}
9857
Karl Schultz6addd812016-02-02 17:17:23 -07009858TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009860 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009861
Chris Forbesb56af562015-05-25 11:13:17 +12009862 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009864
9865 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009866 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009867 "\n"
9868 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009869 "out gl_PerVertex {\n"
9870 " vec4 gl_Position;\n"
9871 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009872 "void main(){\n"
9873 " x = 0;\n"
9874 " gl_Position = vec4(1);\n"
9875 "}\n";
9876 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009877 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009878 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009879 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009880 "layout(location=0) out vec4 color;\n"
9881 "void main(){\n"
9882 " color = vec4(x);\n"
9883 "}\n";
9884
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009887
9888 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009889 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009890 pipe.AddShader(&vs);
9891 pipe.AddShader(&fs);
9892
Chris Forbesb56af562015-05-25 11:13:17 +12009893 VkDescriptorSetObj descriptorSet(m_device);
9894 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009896
Tony Barbour5781e8f2015-08-04 16:23:11 -06009897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009898
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009899 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009900}
9901
Karl Schultz6addd812016-02-02 17:17:23 -07009902TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009904 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009905
9906 ASSERT_NO_FATAL_FAILURE(InitState());
9907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9908
9909 char const *vsSource =
9910 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009911 "\n"
9912 "out block { layout(location=0) int x; } outs;\n"
9913 "out gl_PerVertex {\n"
9914 " vec4 gl_Position;\n"
9915 "};\n"
9916 "void main(){\n"
9917 " outs.x = 0;\n"
9918 " gl_Position = vec4(1);\n"
9919 "}\n";
9920 char const *fsSource =
9921 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009922 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009923 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009924 "layout(location=0) out vec4 color;\n"
9925 "void main(){\n"
9926 " color = vec4(ins.x);\n"
9927 "}\n";
9928
9929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9931
9932 VkPipelineObj pipe(m_device);
9933 pipe.AddColorAttachment();
9934 pipe.AddShader(&vs);
9935 pipe.AddShader(&fs);
9936
9937 VkDescriptorSetObj descriptorSet(m_device);
9938 descriptorSet.AppendDummy();
9939 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9940
9941 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9942
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009943 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009944}
9945
9946TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9948 "location 0.0 which is not written by vertex shader");
9949
9950 ASSERT_NO_FATAL_FAILURE(InitState());
9951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9952
9953 char const *vsSource =
9954 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009955 "\n"
9956 "out block { layout(location=1) float x; } outs;\n"
9957 "out gl_PerVertex {\n"
9958 " vec4 gl_Position;\n"
9959 "};\n"
9960 "void main(){\n"
9961 " outs.x = 0;\n"
9962 " gl_Position = vec4(1);\n"
9963 "}\n";
9964 char const *fsSource =
9965 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009966 "\n"
9967 "in block { layout(location=0) float x; } ins;\n"
9968 "layout(location=0) out vec4 color;\n"
9969 "void main(){\n"
9970 " color = vec4(ins.x);\n"
9971 "}\n";
9972
9973 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9974 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9975
9976 VkPipelineObj pipe(m_device);
9977 pipe.AddColorAttachment();
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 Forbese9928822016-02-17 14:44:52 +13009988}
9989
9990TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9992 "location 0.1 which is not written by vertex shader");
9993
9994 ASSERT_NO_FATAL_FAILURE(InitState());
9995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9996
9997 char const *vsSource =
9998 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009999 "\n"
10000 "out block { layout(location=0, component=0) float x; } outs;\n"
10001 "out gl_PerVertex {\n"
10002 " vec4 gl_Position;\n"
10003 "};\n"
10004 "void main(){\n"
10005 " outs.x = 0;\n"
10006 " gl_Position = vec4(1);\n"
10007 "}\n";
10008 char const *fsSource =
10009 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010010 "\n"
10011 "in block { layout(location=0, component=1) float x; } ins;\n"
10012 "layout(location=0) out vec4 color;\n"
10013 "void main(){\n"
10014 " color = vec4(ins.x);\n"
10015 "}\n";
10016
10017 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10018 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10019
10020 VkPipelineObj pipe(m_device);
10021 pipe.AddColorAttachment();
10022 pipe.AddShader(&vs);
10023 pipe.AddShader(&fs);
10024
10025 VkDescriptorSetObj descriptorSet(m_device);
10026 descriptorSet.AppendDummy();
10027 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10028
10029 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010031 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130010032}
10033
Karl Schultz6addd812016-02-02 17:17:23 -070010034TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010036 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010037
Chris Forbesde136e02015-05-25 11:13:28 +120010038 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010040
10041 VkVertexInputBindingDescription input_binding;
10042 memset(&input_binding, 0, sizeof(input_binding));
10043
10044 VkVertexInputAttributeDescription input_attrib;
10045 memset(&input_attrib, 0, sizeof(input_attrib));
10046 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10047
10048 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010049 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010050 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010051 "out gl_PerVertex {\n"
10052 " vec4 gl_Position;\n"
10053 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010054 "void main(){\n"
10055 " gl_Position = vec4(1);\n"
10056 "}\n";
10057 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010058 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010059 "\n"
10060 "layout(location=0) out vec4 color;\n"
10061 "void main(){\n"
10062 " color = vec4(1);\n"
10063 "}\n";
10064
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010065 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10066 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010067
10068 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010069 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010070 pipe.AddShader(&vs);
10071 pipe.AddShader(&fs);
10072
10073 pipe.AddVertexInputBindings(&input_binding, 1);
10074 pipe.AddVertexInputAttribs(&input_attrib, 1);
10075
Chris Forbesde136e02015-05-25 11:13:28 +120010076 VkDescriptorSetObj descriptorSet(m_device);
10077 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010078 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010079
Tony Barbour5781e8f2015-08-04 16:23:11 -060010080 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010081
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010082 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010083}
10084
Karl Schultz6addd812016-02-02 17:17:23 -070010085TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010087 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010088
10089 ASSERT_NO_FATAL_FAILURE(InitState());
10090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10091
10092 VkVertexInputBindingDescription input_binding;
10093 memset(&input_binding, 0, sizeof(input_binding));
10094
10095 VkVertexInputAttributeDescription input_attrib;
10096 memset(&input_attrib, 0, sizeof(input_attrib));
10097 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10098
10099 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010100 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010101 "\n"
10102 "layout(location=1) in float x;\n"
10103 "out gl_PerVertex {\n"
10104 " vec4 gl_Position;\n"
10105 "};\n"
10106 "void main(){\n"
10107 " gl_Position = vec4(x);\n"
10108 "}\n";
10109 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010110 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010111 "\n"
10112 "layout(location=0) out vec4 color;\n"
10113 "void main(){\n"
10114 " color = vec4(1);\n"
10115 "}\n";
10116
10117 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10118 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10119
10120 VkPipelineObj pipe(m_device);
10121 pipe.AddColorAttachment();
10122 pipe.AddShader(&vs);
10123 pipe.AddShader(&fs);
10124
10125 pipe.AddVertexInputBindings(&input_binding, 1);
10126 pipe.AddVertexInputAttribs(&input_attrib, 1);
10127
10128 VkDescriptorSetObj descriptorSet(m_device);
10129 descriptorSet.AppendDummy();
10130 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10131
10132 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10133
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010134 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010135}
10136
Karl Schultz6addd812016-02-02 17:17:23 -070010137TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10138 m_errorMonitor->SetDesiredFailureMsg(
10139 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010140 "VS consumes input at location 0 but not provided");
10141
Chris Forbes62e8e502015-05-25 11:13:29 +120010142 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010144
10145 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010146 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010147 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010148 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010149 "out gl_PerVertex {\n"
10150 " vec4 gl_Position;\n"
10151 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010152 "void main(){\n"
10153 " gl_Position = x;\n"
10154 "}\n";
10155 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010156 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010157 "\n"
10158 "layout(location=0) out vec4 color;\n"
10159 "void main(){\n"
10160 " color = vec4(1);\n"
10161 "}\n";
10162
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010163 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10164 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010165
10166 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010167 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010168 pipe.AddShader(&vs);
10169 pipe.AddShader(&fs);
10170
Chris Forbes62e8e502015-05-25 11:13:29 +120010171 VkDescriptorSetObj descriptorSet(m_device);
10172 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010173 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010174
Tony Barbour5781e8f2015-08-04 16:23:11 -060010175 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010176
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010177 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010178}
10179
Karl Schultz6addd812016-02-02 17:17:23 -070010180TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10181 m_errorMonitor->SetDesiredFailureMsg(
10182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010183 "location 0 does not match VS input type");
10184
Chris Forbesc97d98e2015-05-25 11:13:31 +120010185 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010187
10188 VkVertexInputBindingDescription input_binding;
10189 memset(&input_binding, 0, sizeof(input_binding));
10190
10191 VkVertexInputAttributeDescription input_attrib;
10192 memset(&input_attrib, 0, sizeof(input_attrib));
10193 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10194
10195 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010196 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010197 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010198 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010199 "out gl_PerVertex {\n"
10200 " vec4 gl_Position;\n"
10201 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010202 "void main(){\n"
10203 " gl_Position = vec4(x);\n"
10204 "}\n";
10205 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010206 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010207 "\n"
10208 "layout(location=0) out vec4 color;\n"
10209 "void main(){\n"
10210 " color = vec4(1);\n"
10211 "}\n";
10212
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010215
10216 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010217 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010218 pipe.AddShader(&vs);
10219 pipe.AddShader(&fs);
10220
10221 pipe.AddVertexInputBindings(&input_binding, 1);
10222 pipe.AddVertexInputAttribs(&input_attrib, 1);
10223
Chris Forbesc97d98e2015-05-25 11:13:31 +120010224 VkDescriptorSetObj descriptorSet(m_device);
10225 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010227
Tony Barbour5781e8f2015-08-04 16:23:11 -060010228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010230 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010231}
10232
Chris Forbesc68b43c2016-04-06 11:18:47 +120010233TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10234 m_errorMonitor->SetDesiredFailureMsg(
10235 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10236 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10237
10238 ASSERT_NO_FATAL_FAILURE(InitState());
10239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10240
10241 char const *vsSource =
10242 "#version 450\n"
10243 "\n"
10244 "out gl_PerVertex {\n"
10245 " vec4 gl_Position;\n"
10246 "};\n"
10247 "void main(){\n"
10248 " gl_Position = vec4(1);\n"
10249 "}\n";
10250 char const *fsSource =
10251 "#version 450\n"
10252 "\n"
10253 "layout(location=0) out vec4 color;\n"
10254 "void main(){\n"
10255 " color = vec4(1);\n"
10256 "}\n";
10257
10258 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10259 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10260
10261 VkPipelineObj pipe(m_device);
10262 pipe.AddColorAttachment();
10263 pipe.AddShader(&vs);
10264 pipe.AddShader(&vs);
10265 pipe.AddShader(&fs);
10266
10267 VkDescriptorSetObj descriptorSet(m_device);
10268 descriptorSet.AppendDummy();
10269 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10270
10271 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10272
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010273 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010274}
10275
Karl Schultz6addd812016-02-02 17:17:23 -070010276TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010277 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010278
10279 ASSERT_NO_FATAL_FAILURE(InitState());
10280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10281
10282 VkVertexInputBindingDescription input_binding;
10283 memset(&input_binding, 0, sizeof(input_binding));
10284
10285 VkVertexInputAttributeDescription input_attribs[2];
10286 memset(input_attribs, 0, sizeof(input_attribs));
10287
10288 for (int i = 0; i < 2; i++) {
10289 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10290 input_attribs[i].location = i;
10291 }
10292
10293 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010294 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010295 "\n"
10296 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010297 "out gl_PerVertex {\n"
10298 " vec4 gl_Position;\n"
10299 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010300 "void main(){\n"
10301 " gl_Position = x[0] + x[1];\n"
10302 "}\n";
10303 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010304 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010305 "\n"
10306 "layout(location=0) out vec4 color;\n"
10307 "void main(){\n"
10308 " color = vec4(1);\n"
10309 "}\n";
10310
10311 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10312 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10313
10314 VkPipelineObj pipe(m_device);
10315 pipe.AddColorAttachment();
10316 pipe.AddShader(&vs);
10317 pipe.AddShader(&fs);
10318
10319 pipe.AddVertexInputBindings(&input_binding, 1);
10320 pipe.AddVertexInputAttribs(input_attribs, 2);
10321
10322 VkDescriptorSetObj descriptorSet(m_device);
10323 descriptorSet.AppendDummy();
10324 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10325
10326 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10327
10328 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010329 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010330}
10331
Chris Forbes2682b242015-11-24 11:13:14 +130010332TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10333{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010334 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010335
10336 ASSERT_NO_FATAL_FAILURE(InitState());
10337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10338
10339 VkVertexInputBindingDescription input_binding;
10340 memset(&input_binding, 0, sizeof(input_binding));
10341
10342 VkVertexInputAttributeDescription input_attribs[2];
10343 memset(input_attribs, 0, sizeof(input_attribs));
10344
10345 for (int i = 0; i < 2; i++) {
10346 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10347 input_attribs[i].location = i;
10348 }
10349
10350 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010351 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010352 "\n"
10353 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010354 "out gl_PerVertex {\n"
10355 " vec4 gl_Position;\n"
10356 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010357 "void main(){\n"
10358 " gl_Position = x[0] + x[1];\n"
10359 "}\n";
10360 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010361 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010362 "\n"
10363 "layout(location=0) out vec4 color;\n"
10364 "void main(){\n"
10365 " color = vec4(1);\n"
10366 "}\n";
10367
10368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10370
10371 VkPipelineObj pipe(m_device);
10372 pipe.AddColorAttachment();
10373 pipe.AddShader(&vs);
10374 pipe.AddShader(&fs);
10375
10376 pipe.AddVertexInputBindings(&input_binding, 1);
10377 pipe.AddVertexInputAttribs(input_attribs, 2);
10378
10379 VkDescriptorSetObj descriptorSet(m_device);
10380 descriptorSet.AppendDummy();
10381 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10382
10383 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010385 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010386}
Chris Forbes2682b242015-11-24 11:13:14 +130010387
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010388TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10389{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010390 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010391
10392 ASSERT_NO_FATAL_FAILURE(InitState());
10393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10394
10395 char const *vsSource =
10396 "#version 450\n"
10397 "out gl_PerVertex {\n"
10398 " vec4 gl_Position;\n"
10399 "};\n"
10400 "void main(){\n"
10401 " gl_Position = vec4(0);\n"
10402 "}\n";
10403 char const *fsSource =
10404 "#version 450\n"
10405 "\n"
10406 "layout(location=0) out vec4 color;\n"
10407 "void main(){\n"
10408 " color = vec4(1);\n"
10409 "}\n";
10410
10411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10413
10414 VkPipelineObj pipe(m_device);
10415 pipe.AddColorAttachment();
10416 pipe.AddShader(&vs);
10417 pipe.AddShader(&fs);
10418
10419 VkDescriptorSetObj descriptorSet(m_device);
10420 descriptorSet.AppendDummy();
10421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10422
10423 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010425 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010426}
10427
Chris Forbes912c9192016-04-05 17:50:35 +120010428TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10429{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010430 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010431
10432 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10433
10434 ASSERT_NO_FATAL_FAILURE(InitState());
10435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10436
10437 char const *vsSource =
10438 "#version 450\n"
10439 "out gl_PerVertex {\n"
10440 " vec4 gl_Position;\n"
10441 "};\n"
10442 "layout(location=0) out vec3 x;\n"
10443 "layout(location=1) out ivec3 y;\n"
10444 "layout(location=2) out vec3 z;\n"
10445 "void main(){\n"
10446 " gl_Position = vec4(0);\n"
10447 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10448 "}\n";
10449 char const *fsSource =
10450 "#version 450\n"
10451 "\n"
10452 "layout(location=0) out vec4 color;\n"
10453 "layout(location=0) in float x;\n"
10454 "layout(location=1) flat in int y;\n"
10455 "layout(location=2) in vec2 z;\n"
10456 "void main(){\n"
10457 " color = vec4(1 + x + y + z.x);\n"
10458 "}\n";
10459
10460 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10461 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10462
10463 VkPipelineObj pipe(m_device);
10464 pipe.AddColorAttachment();
10465 pipe.AddShader(&vs);
10466 pipe.AddShader(&fs);
10467
10468 VkDescriptorSetObj descriptorSet(m_device);
10469 descriptorSet.AppendDummy();
10470 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10471
10472 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010474 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010475}
10476
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010477TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10478{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010479 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010480
10481 ASSERT_NO_FATAL_FAILURE(InitState());
10482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10483
Chris Forbesc1e852d2016-04-04 19:26:42 +120010484 if (!m_device->phy().features().tessellationShader) {
10485 printf("Device does not support tessellation shaders; skipped.\n");
10486 return;
10487 }
10488
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010489 char const *vsSource =
10490 "#version 450\n"
10491 "void main(){}\n";
10492 char const *tcsSource =
10493 "#version 450\n"
10494 "layout(location=0) out int x[];\n"
10495 "layout(vertices=3) out;\n"
10496 "void main(){\n"
10497 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10498 " gl_TessLevelInner[0] = 1;\n"
10499 " x[gl_InvocationID] = gl_InvocationID;\n"
10500 "}\n";
10501 char const *tesSource =
10502 "#version 450\n"
10503 "layout(triangles, equal_spacing, cw) in;\n"
10504 "layout(location=0) in int x[];\n"
10505 "out gl_PerVertex { vec4 gl_Position; };\n"
10506 "void main(){\n"
10507 " gl_Position.xyz = gl_TessCoord;\n"
10508 " gl_Position.w = x[0] + x[1] + x[2];\n"
10509 "}\n";
10510 char const *fsSource =
10511 "#version 450\n"
10512 "layout(location=0) out vec4 color;\n"
10513 "void main(){\n"
10514 " color = vec4(1);\n"
10515 "}\n";
10516
10517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10518 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10519 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10521
10522 VkPipelineInputAssemblyStateCreateInfo iasci{
10523 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10524 nullptr,
10525 0,
10526 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10527 VK_FALSE};
10528
Chris Forbesb4cacb62016-04-04 19:15:00 +120010529 VkPipelineTessellationStateCreateInfo tsci{
10530 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10531 nullptr,
10532 0,
10533 3};
10534
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010535 VkPipelineObj pipe(m_device);
10536 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010537 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010538 pipe.AddColorAttachment();
10539 pipe.AddShader(&vs);
10540 pipe.AddShader(&tcs);
10541 pipe.AddShader(&tes);
10542 pipe.AddShader(&fs);
10543
10544 VkDescriptorSetObj descriptorSet(m_device);
10545 descriptorSet.AppendDummy();
10546 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10547
10548 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010550 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010551}
10552
Chris Forbesa0ab8152016-04-20 13:34:27 +120010553TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10554{
10555 m_errorMonitor->ExpectSuccess();
10556
10557 ASSERT_NO_FATAL_FAILURE(InitState());
10558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10559
10560 if (!m_device->phy().features().geometryShader) {
10561 printf("Device does not support geometry shaders; skipped.\n");
10562 return;
10563 }
10564
10565 char const *vsSource =
10566 "#version 450\n"
10567 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10568 "void main(){\n"
10569 " vs_out.x = vec4(1);\n"
10570 "}\n";
10571 char const *gsSource =
10572 "#version 450\n"
10573 "layout(triangles) in;\n"
10574 "layout(triangle_strip, max_vertices=3) out;\n"
10575 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10576 "out gl_PerVertex { vec4 gl_Position; };\n"
10577 "void main() {\n"
10578 " gl_Position = gs_in[0].x;\n"
10579 " EmitVertex();\n"
10580 "}\n";
10581 char const *fsSource =
10582 "#version 450\n"
10583 "layout(location=0) out vec4 color;\n"
10584 "void main(){\n"
10585 " color = vec4(1);\n"
10586 "}\n";
10587
10588 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10589 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10590 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10591
10592 VkPipelineObj pipe(m_device);
10593 pipe.AddColorAttachment();
10594 pipe.AddShader(&vs);
10595 pipe.AddShader(&gs);
10596 pipe.AddShader(&fs);
10597
10598 VkDescriptorSetObj descriptorSet(m_device);
10599 descriptorSet.AppendDummy();
10600 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10601
10602 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10603
10604 m_errorMonitor->VerifyNotFound();
10605}
10606
Chris Forbesa0193bc2016-04-04 19:19:47 +120010607TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10608{
10609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10610 "is per-vertex in tessellation control shader stage "
10611 "but per-patch in tessellation evaluation shader stage");
10612
10613 ASSERT_NO_FATAL_FAILURE(InitState());
10614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10615
Chris Forbesc1e852d2016-04-04 19:26:42 +120010616 if (!m_device->phy().features().tessellationShader) {
10617 printf("Device does not support tessellation shaders; skipped.\n");
10618 return;
10619 }
10620
Chris Forbesa0193bc2016-04-04 19:19:47 +120010621 char const *vsSource =
10622 "#version 450\n"
10623 "void main(){}\n";
10624 char const *tcsSource =
10625 "#version 450\n"
10626 "layout(location=0) out int x[];\n"
10627 "layout(vertices=3) out;\n"
10628 "void main(){\n"
10629 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10630 " gl_TessLevelInner[0] = 1;\n"
10631 " x[gl_InvocationID] = gl_InvocationID;\n"
10632 "}\n";
10633 char const *tesSource =
10634 "#version 450\n"
10635 "layout(triangles, equal_spacing, cw) in;\n"
10636 "layout(location=0) patch in int x;\n"
10637 "out gl_PerVertex { vec4 gl_Position; };\n"
10638 "void main(){\n"
10639 " gl_Position.xyz = gl_TessCoord;\n"
10640 " gl_Position.w = x;\n"
10641 "}\n";
10642 char const *fsSource =
10643 "#version 450\n"
10644 "layout(location=0) out vec4 color;\n"
10645 "void main(){\n"
10646 " color = vec4(1);\n"
10647 "}\n";
10648
10649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10650 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10651 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10653
10654 VkPipelineInputAssemblyStateCreateInfo iasci{
10655 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10656 nullptr,
10657 0,
10658 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10659 VK_FALSE};
10660
10661 VkPipelineTessellationStateCreateInfo tsci{
10662 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10663 nullptr,
10664 0,
10665 3};
10666
10667 VkPipelineObj pipe(m_device);
10668 pipe.SetInputAssembly(&iasci);
10669 pipe.SetTessellation(&tsci);
10670 pipe.AddColorAttachment();
10671 pipe.AddShader(&vs);
10672 pipe.AddShader(&tcs);
10673 pipe.AddShader(&tes);
10674 pipe.AddShader(&fs);
10675
10676 VkDescriptorSetObj descriptorSet(m_device);
10677 descriptorSet.AppendDummy();
10678 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10679
10680 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10681
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010682 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010683}
10684
Karl Schultz6addd812016-02-02 17:17:23 -070010685TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10686 m_errorMonitor->SetDesiredFailureMsg(
10687 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010688 "Duplicate vertex input binding descriptions for binding 0");
10689
Chris Forbes280ba2c2015-06-12 11:16:41 +120010690 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010692
10693 /* Two binding descriptions for binding 0 */
10694 VkVertexInputBindingDescription input_bindings[2];
10695 memset(input_bindings, 0, sizeof(input_bindings));
10696
10697 VkVertexInputAttributeDescription input_attrib;
10698 memset(&input_attrib, 0, sizeof(input_attrib));
10699 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10700
10701 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010702 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010703 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010704 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010705 "out gl_PerVertex {\n"
10706 " vec4 gl_Position;\n"
10707 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010708 "void main(){\n"
10709 " gl_Position = vec4(x);\n"
10710 "}\n";
10711 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010712 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010713 "\n"
10714 "layout(location=0) out vec4 color;\n"
10715 "void main(){\n"
10716 " color = vec4(1);\n"
10717 "}\n";
10718
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010719 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10720 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010721
10722 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010723 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010724 pipe.AddShader(&vs);
10725 pipe.AddShader(&fs);
10726
10727 pipe.AddVertexInputBindings(input_bindings, 2);
10728 pipe.AddVertexInputAttribs(&input_attrib, 1);
10729
Chris Forbes280ba2c2015-06-12 11:16:41 +120010730 VkDescriptorSetObj descriptorSet(m_device);
10731 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010732 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010733
Tony Barbour5781e8f2015-08-04 16:23:11 -060010734 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010736 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010737}
Chris Forbes8f68b562015-05-25 11:13:32 +120010738
Chris Forbes35efec72016-04-21 14:32:08 +120010739TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10740 m_errorMonitor->ExpectSuccess();
10741
10742 ASSERT_NO_FATAL_FAILURE(InitState());
10743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10744
10745 if (!m_device->phy().features().tessellationShader) {
10746 printf("Device does not support 64bit vertex attributes; skipped.\n");
10747 return;
10748 }
10749
10750 VkVertexInputBindingDescription input_bindings[1];
10751 memset(input_bindings, 0, sizeof(input_bindings));
10752
10753 VkVertexInputAttributeDescription input_attribs[4];
10754 memset(input_attribs, 0, sizeof(input_attribs));
10755 input_attribs[0].location = 0;
10756 input_attribs[0].offset = 0;
10757 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10758 input_attribs[1].location = 2;
10759 input_attribs[1].offset = 32;
10760 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10761 input_attribs[2].location = 4;
10762 input_attribs[2].offset = 64;
10763 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10764 input_attribs[3].location = 6;
10765 input_attribs[3].offset = 96;
10766 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10767
10768 char const *vsSource =
10769 "#version 450\n"
10770 "\n"
10771 "layout(location=0) in dmat4 x;\n"
10772 "out gl_PerVertex {\n"
10773 " vec4 gl_Position;\n"
10774 "};\n"
10775 "void main(){\n"
10776 " gl_Position = vec4(x[0][0]);\n"
10777 "}\n";
10778 char const *fsSource =
10779 "#version 450\n"
10780 "\n"
10781 "layout(location=0) out vec4 color;\n"
10782 "void main(){\n"
10783 " color = vec4(1);\n"
10784 "}\n";
10785
10786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10788
10789 VkPipelineObj pipe(m_device);
10790 pipe.AddColorAttachment();
10791 pipe.AddShader(&vs);
10792 pipe.AddShader(&fs);
10793
10794 pipe.AddVertexInputBindings(input_bindings, 1);
10795 pipe.AddVertexInputAttribs(input_attribs, 4);
10796
10797 VkDescriptorSetObj descriptorSet(m_device);
10798 descriptorSet.AppendDummy();
10799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10800
10801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10802
10803 m_errorMonitor->VerifyNotFound();
10804}
10805
Karl Schultz6addd812016-02-02 17:17:23 -070010806TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010808 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010809
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010810 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010811
10812 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010813 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010814 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010815 "out gl_PerVertex {\n"
10816 " vec4 gl_Position;\n"
10817 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010818 "void main(){\n"
10819 " gl_Position = vec4(1);\n"
10820 "}\n";
10821 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010822 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010823 "\n"
10824 "void main(){\n"
10825 "}\n";
10826
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010827 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10828 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010829
10830 VkPipelineObj pipe(m_device);
10831 pipe.AddShader(&vs);
10832 pipe.AddShader(&fs);
10833
Chia-I Wu08accc62015-07-07 11:50:03 +080010834 /* set up CB 0, not written */
10835 pipe.AddColorAttachment();
10836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010837
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010838 VkDescriptorSetObj descriptorSet(m_device);
10839 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010841
Tony Barbour5781e8f2015-08-04 16:23:11 -060010842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010844 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010845}
10846
Karl Schultz6addd812016-02-02 17:17:23 -070010847TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010848 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010849 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010850 "FS writes to output location 1 with no matching attachment");
10851
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010852 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010853
10854 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010855 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010856 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010857 "out gl_PerVertex {\n"
10858 " vec4 gl_Position;\n"
10859 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010860 "void main(){\n"
10861 " gl_Position = vec4(1);\n"
10862 "}\n";
10863 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010864 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010865 "\n"
10866 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010867 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010868 "void main(){\n"
10869 " x = vec4(1);\n"
10870 " y = vec4(1);\n"
10871 "}\n";
10872
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010875
10876 VkPipelineObj pipe(m_device);
10877 pipe.AddShader(&vs);
10878 pipe.AddShader(&fs);
10879
Chia-I Wu08accc62015-07-07 11:50:03 +080010880 /* set up CB 0, not written */
10881 pipe.AddColorAttachment();
10882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010883 /* FS writes CB 1, but we don't configure it */
10884
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010885 VkDescriptorSetObj descriptorSet(m_device);
10886 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010888
Tony Barbour5781e8f2015-08-04 16:23:11 -060010889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010890
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010891 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010892}
10893
Karl Schultz6addd812016-02-02 17:17:23 -070010894TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010896 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010897
Chris Forbesa36d69e2015-05-25 11:13:44 +120010898 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010899
10900 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010901 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010902 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010903 "out gl_PerVertex {\n"
10904 " vec4 gl_Position;\n"
10905 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010906 "void main(){\n"
10907 " gl_Position = vec4(1);\n"
10908 "}\n";
10909 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010910 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010911 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010912 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010913 "void main(){\n"
10914 " x = ivec4(1);\n"
10915 "}\n";
10916
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010919
10920 VkPipelineObj pipe(m_device);
10921 pipe.AddShader(&vs);
10922 pipe.AddShader(&fs);
10923
Chia-I Wu08accc62015-07-07 11:50:03 +080010924 /* set up CB 0; type is UNORM by default */
10925 pipe.AddColorAttachment();
10926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010927
Chris Forbesa36d69e2015-05-25 11:13:44 +120010928 VkDescriptorSetObj descriptorSet(m_device);
10929 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010931
Tony Barbour5781e8f2015-08-04 16:23:11 -060010932 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010933
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010934 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010935}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010936
Karl Schultz6addd812016-02-02 17:17:23 -070010937TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010939 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010940
Chris Forbes556c76c2015-08-14 12:04:59 +120010941 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010942
10943 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010944 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010945 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010946 "out gl_PerVertex {\n"
10947 " vec4 gl_Position;\n"
10948 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010949 "void main(){\n"
10950 " gl_Position = vec4(1);\n"
10951 "}\n";
10952 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010953 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010954 "\n"
10955 "layout(location=0) out vec4 x;\n"
10956 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10957 "void main(){\n"
10958 " x = vec4(bar.y);\n"
10959 "}\n";
10960
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010961 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10962 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010963
Chris Forbes556c76c2015-08-14 12:04:59 +120010964 VkPipelineObj pipe(m_device);
10965 pipe.AddShader(&vs);
10966 pipe.AddShader(&fs);
10967
10968 /* set up CB 0; type is UNORM by default */
10969 pipe.AddColorAttachment();
10970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10971
10972 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010973 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010974
10975 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10976
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010977 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010978}
10979
Chris Forbes5c59e902016-02-26 16:56:09 +130010980TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10982 "not declared in layout");
10983
10984 ASSERT_NO_FATAL_FAILURE(InitState());
10985
10986 char const *vsSource =
10987 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010988 "\n"
10989 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10990 "out gl_PerVertex {\n"
10991 " vec4 gl_Position;\n"
10992 "};\n"
10993 "void main(){\n"
10994 " gl_Position = vec4(consts.x);\n"
10995 "}\n";
10996 char const *fsSource =
10997 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010998 "\n"
10999 "layout(location=0) out vec4 x;\n"
11000 "void main(){\n"
11001 " x = vec4(1);\n"
11002 "}\n";
11003
11004 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11005 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11006
11007 VkPipelineObj pipe(m_device);
11008 pipe.AddShader(&vs);
11009 pipe.AddShader(&fs);
11010
11011 /* set up CB 0; type is UNORM by default */
11012 pipe.AddColorAttachment();
11013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11014
11015 VkDescriptorSetObj descriptorSet(m_device);
11016 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11017
11018 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11019
11020 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011021 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130011022}
11023
Chris Forbes10eb9ae2016-05-31 16:09:42 +120011024TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
11025 m_errorMonitor->SetDesiredFailureMsg(
11026 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11027 "Shader uses descriptor slot 0.0");
11028
11029 ASSERT_NO_FATAL_FAILURE(InitState());
11030
11031 char const *csSource =
11032 "#version 450\n"
11033 "\n"
11034 "layout(local_size_x=1) in;\n"
11035 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11036 "void main(){\n"
11037 " x = vec4(1);\n"
11038 "}\n";
11039
11040 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11041
11042 VkDescriptorSetObj descriptorSet(m_device);
11043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11044
11045 VkComputePipelineCreateInfo cpci = {
11046 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11047 nullptr, 0, {
11048 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11049 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11050 cs.handle(), "main", nullptr
11051 },
11052 descriptorSet.GetPipelineLayout(),
11053 VK_NULL_HANDLE, -1
11054 };
11055
11056 VkPipeline pipe;
11057 VkResult err = vkCreateComputePipelines(
11058 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11059
11060 m_errorMonitor->VerifyFound();
11061
11062 if (err == VK_SUCCESS) {
11063 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11064 }
11065}
11066
11067TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11068 m_errorMonitor->ExpectSuccess();
11069
11070 ASSERT_NO_FATAL_FAILURE(InitState());
11071
11072 char const *csSource =
11073 "#version 450\n"
11074 "\n"
11075 "layout(local_size_x=1) in;\n"
11076 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11077 "void main(){\n"
11078 " // x is not used.\n"
11079 "}\n";
11080
11081 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11082
11083 VkDescriptorSetObj descriptorSet(m_device);
11084 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11085
11086 VkComputePipelineCreateInfo cpci = {
11087 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11088 nullptr, 0, {
11089 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11090 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11091 cs.handle(), "main", nullptr
11092 },
11093 descriptorSet.GetPipelineLayout(),
11094 VK_NULL_HANDLE, -1
11095 };
11096
11097 VkPipeline pipe;
11098 VkResult err = vkCreateComputePipelines(
11099 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11100
11101 m_errorMonitor->VerifyNotFound();
11102
11103 if (err == VK_SUCCESS) {
11104 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11105 }
11106}
11107
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011108#endif // SHADER_CHECKER_TESTS
11109
11110#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011111TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011112 m_errorMonitor->SetDesiredFailureMsg(
11113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011114 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011115
11116 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011117
11118 // Create an image
11119 VkImage image;
11120
Karl Schultz6addd812016-02-02 17:17:23 -070011121 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11122 const int32_t tex_width = 32;
11123 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011124
11125 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011126 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11127 image_create_info.pNext = NULL;
11128 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11129 image_create_info.format = tex_format;
11130 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011131 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011132 image_create_info.extent.depth = 1;
11133 image_create_info.mipLevels = 1;
11134 image_create_info.arrayLayers = 1;
11135 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11136 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11137 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11138 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011139
11140 // Introduce error by sending down a bogus width extent
11141 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011142 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011143
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011144 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011145}
11146
Mark Youngc48c4c12016-04-11 14:26:49 -060011147TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11148 m_errorMonitor->SetDesiredFailureMsg(
11149 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11150 "CreateImage extents is 0 for at least one required dimension");
11151
11152 ASSERT_NO_FATAL_FAILURE(InitState());
11153
11154 // Create an image
11155 VkImage image;
11156
11157 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11158 const int32_t tex_width = 32;
11159 const int32_t tex_height = 32;
11160
11161 VkImageCreateInfo image_create_info = {};
11162 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11163 image_create_info.pNext = NULL;
11164 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11165 image_create_info.format = tex_format;
11166 image_create_info.extent.width = tex_width;
11167 image_create_info.extent.height = tex_height;
11168 image_create_info.extent.depth = 1;
11169 image_create_info.mipLevels = 1;
11170 image_create_info.arrayLayers = 1;
11171 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11172 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11173 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11174 image_create_info.flags = 0;
11175
11176 // Introduce error by sending down a bogus width extent
11177 image_create_info.extent.width = 0;
11178 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11179
11180 m_errorMonitor->VerifyFound();
11181}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011182#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011183
Tobin Ehliscde08892015-09-22 10:11:37 -060011184#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011185TEST_F(VkLayerTest, InvalidImageView) {
11186 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011187
Karl Schultz6addd812016-02-02 17:17:23 -070011188 m_errorMonitor->SetDesiredFailureMsg(
11189 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011190 "vkCreateImageView called with baseMipLevel 10 ");
11191
Tobin Ehliscde08892015-09-22 10:11:37 -060011192 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011193
Mike Stroyana3082432015-09-25 13:39:21 -060011194 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011195 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011196
Karl Schultz6addd812016-02-02 17:17:23 -070011197 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11198 const int32_t tex_width = 32;
11199 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011200
11201 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11203 image_create_info.pNext = NULL;
11204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11205 image_create_info.format = tex_format;
11206 image_create_info.extent.width = tex_width;
11207 image_create_info.extent.height = tex_height;
11208 image_create_info.extent.depth = 1;
11209 image_create_info.mipLevels = 1;
11210 image_create_info.arrayLayers = 1;
11211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11212 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11213 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11214 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011215
Chia-I Wuf7458c52015-10-26 21:10:41 +080011216 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011217 ASSERT_VK_SUCCESS(err);
11218
11219 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011220 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11221 image_view_create_info.image = image;
11222 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11223 image_view_create_info.format = tex_format;
11224 image_view_create_info.subresourceRange.layerCount = 1;
11225 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11226 image_view_create_info.subresourceRange.levelCount = 1;
11227 image_view_create_info.subresourceRange.aspectMask =
11228 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011229
11230 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011231 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11232 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011233
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011234 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011235 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011236}
Mike Stroyana3082432015-09-25 13:39:21 -060011237
Karl Schultz6addd812016-02-02 17:17:23 -070011238TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011239 TEST_DESCRIPTION(
11240 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011242 "vkCreateImageView: Color image "
11243 "formats must have ONLY the "
11244 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011245
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011246 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011247
Karl Schultz6addd812016-02-02 17:17:23 -070011248 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011249 VkImageObj image(m_device);
11250 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11251 VK_IMAGE_TILING_LINEAR, 0);
11252 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011253
11254 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011255 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011256 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011257 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11258 image_view_create_info.format = tex_format;
11259 image_view_create_info.subresourceRange.baseMipLevel = 0;
11260 image_view_create_info.subresourceRange.levelCount = 1;
11261 // Cause an error by setting an invalid image aspect
11262 image_view_create_info.subresourceRange.aspectMask =
11263 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011264
11265 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011266 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011267
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011268 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011269}
11270
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011271TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011272 VkResult err;
11273 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011274
Karl Schultz6addd812016-02-02 17:17:23 -070011275 m_errorMonitor->SetDesiredFailureMsg(
11276 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011277 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011278
Mike Stroyana3082432015-09-25 13:39:21 -060011279 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011280
11281 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011282 VkImage srcImage;
11283 VkImage dstImage;
11284 VkDeviceMemory srcMem;
11285 VkDeviceMemory destMem;
11286 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011287
11288 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011289 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11290 image_create_info.pNext = NULL;
11291 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11292 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11293 image_create_info.extent.width = 32;
11294 image_create_info.extent.height = 32;
11295 image_create_info.extent.depth = 1;
11296 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011297 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011298 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11299 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11300 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11301 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011302
Karl Schultz6addd812016-02-02 17:17:23 -070011303 err =
11304 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011305 ASSERT_VK_SUCCESS(err);
11306
Karl Schultz6addd812016-02-02 17:17:23 -070011307 err =
11308 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011309 ASSERT_VK_SUCCESS(err);
11310
11311 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011312 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011313 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11314 memAlloc.pNext = NULL;
11315 memAlloc.allocationSize = 0;
11316 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011317
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011318 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011319 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011320 pass =
11321 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011322 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011323 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011324 ASSERT_VK_SUCCESS(err);
11325
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011326 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011327 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011328 pass =
11329 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011330 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011331 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011332 ASSERT_VK_SUCCESS(err);
11333
11334 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11335 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011336 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011337 ASSERT_VK_SUCCESS(err);
11338
11339 BeginCommandBuffer();
11340 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011341 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011342 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011343 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011344 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011345 copyRegion.srcOffset.x = 0;
11346 copyRegion.srcOffset.y = 0;
11347 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011348 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011349 copyRegion.dstSubresource.mipLevel = 0;
11350 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011351 // Introduce failure by forcing the dst layerCount to differ from src
11352 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011353 copyRegion.dstOffset.x = 0;
11354 copyRegion.dstOffset.y = 0;
11355 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011356 copyRegion.extent.width = 1;
11357 copyRegion.extent.height = 1;
11358 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011359 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11360 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011361 EndCommandBuffer();
11362
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011363 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011364
Chia-I Wuf7458c52015-10-26 21:10:41 +080011365 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011366 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011367 vkFreeMemory(m_device->device(), srcMem, NULL);
11368 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011369}
11370
Tony Barbourd6673642016-05-05 14:46:39 -060011371TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11372
11373 TEST_DESCRIPTION("Creating images with unsuported formats ");
11374
11375 ASSERT_NO_FATAL_FAILURE(InitState());
11376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11377 VkImageObj image(m_device);
11378 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11379 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11380 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11381 VK_IMAGE_TILING_OPTIMAL, 0);
11382 ASSERT_TRUE(image.initialized());
11383
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011384 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11385 VkImageCreateInfo image_create_info;
11386 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11387 image_create_info.pNext = NULL;
11388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11389 image_create_info.format = VK_FORMAT_UNDEFINED;
11390 image_create_info.extent.width = 32;
11391 image_create_info.extent.height = 32;
11392 image_create_info.extent.depth = 1;
11393 image_create_info.mipLevels = 1;
11394 image_create_info.arrayLayers = 1;
11395 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11396 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11397 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11398 image_create_info.flags = 0;
11399
11400 m_errorMonitor->SetDesiredFailureMsg(
11401 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11402 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11403
11404 VkImage localImage;
11405 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11406 m_errorMonitor->VerifyFound();
11407
Tony Barbourd6673642016-05-05 14:46:39 -060011408 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011409 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011410 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11411 VkFormat format = static_cast<VkFormat>(f);
11412 VkFormatProperties fProps = m_device->format_properties(format);
11413 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11414 fProps.optimalTilingFeatures == 0) {
11415 unsupported = format;
11416 break;
11417 }
11418 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011419
Tony Barbourd6673642016-05-05 14:46:39 -060011420 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011421 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011423 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011424
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011425 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011426 m_errorMonitor->VerifyFound();
11427 }
11428}
11429
11430TEST_F(VkLayerTest, ImageLayerViewTests) {
11431 VkResult ret;
11432 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11433
11434 ASSERT_NO_FATAL_FAILURE(InitState());
11435
11436 VkImageObj image(m_device);
11437 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11438 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11439 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11440 VK_IMAGE_TILING_OPTIMAL, 0);
11441 ASSERT_TRUE(image.initialized());
11442
11443 VkImageView imgView;
11444 VkImageViewCreateInfo imgViewInfo = {};
11445 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11446 imgViewInfo.image = image.handle();
11447 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11448 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11449 imgViewInfo.subresourceRange.layerCount = 1;
11450 imgViewInfo.subresourceRange.baseMipLevel = 0;
11451 imgViewInfo.subresourceRange.levelCount = 1;
11452 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11453
11454 m_errorMonitor->SetDesiredFailureMsg(
11455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11456 "vkCreateImageView called with baseMipLevel");
11457 // View can't have baseMipLevel >= image's mipLevels - Expect
11458 // VIEW_CREATE_ERROR
11459 imgViewInfo.subresourceRange.baseMipLevel = 1;
11460 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11461 m_errorMonitor->VerifyFound();
11462 imgViewInfo.subresourceRange.baseMipLevel = 0;
11463
11464 m_errorMonitor->SetDesiredFailureMsg(
11465 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11466 "vkCreateImageView called with baseArrayLayer");
11467 // View can't have baseArrayLayer >= image's arraySize - Expect
11468 // VIEW_CREATE_ERROR
11469 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11470 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11471 m_errorMonitor->VerifyFound();
11472 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11473
11474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11475 "vkCreateImageView called with 0 in "
11476 "pCreateInfo->subresourceRange."
11477 "levelCount");
11478 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11479 imgViewInfo.subresourceRange.levelCount = 0;
11480 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11481 m_errorMonitor->VerifyFound();
11482 imgViewInfo.subresourceRange.levelCount = 1;
11483
11484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11485 "vkCreateImageView called with 0 in "
11486 "pCreateInfo->subresourceRange."
11487 "layerCount");
11488 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11489 imgViewInfo.subresourceRange.layerCount = 0;
11490 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11491 m_errorMonitor->VerifyFound();
11492 imgViewInfo.subresourceRange.layerCount = 1;
11493
11494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11495 "but both must be color formats");
11496 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11497 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11498 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11499 m_errorMonitor->VerifyFound();
11500 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11501
11502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11503 "Formats MUST be IDENTICAL unless "
11504 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11505 "was set on image creation.");
11506 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11507 // VIEW_CREATE_ERROR
11508 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11509 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11510 m_errorMonitor->VerifyFound();
11511 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11512
11513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11514 "can support ImageViews with "
11515 "differing formats but they must be "
11516 "in the same compatibility class.");
11517 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11518 // VIEW_CREATE_ERROR
11519 VkImageCreateInfo mutImgInfo = image.create_info();
11520 VkImage mutImage;
11521 mutImgInfo.format = VK_FORMAT_R8_UINT;
11522 assert(
11523 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11524 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11525 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11526 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11527 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11528 ASSERT_VK_SUCCESS(ret);
11529 imgViewInfo.image = mutImage;
11530 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11531 m_errorMonitor->VerifyFound();
11532 imgViewInfo.image = image.handle();
11533 vkDestroyImage(m_device->handle(), mutImage, NULL);
11534}
11535
11536TEST_F(VkLayerTest, MiscImageLayerTests) {
11537
11538 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11539
11540 ASSERT_NO_FATAL_FAILURE(InitState());
11541
11542 VkImageObj image(m_device);
11543 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11544 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11545 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11546 VK_IMAGE_TILING_OPTIMAL, 0);
11547 ASSERT_TRUE(image.initialized());
11548
11549 m_errorMonitor->SetDesiredFailureMsg(
11550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11551 "number of layers in image subresource is zero");
11552 vk_testing::Buffer buffer;
11553 VkMemoryPropertyFlags reqs = 0;
11554 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11555 VkBufferImageCopy region = {};
11556 region.bufferRowLength = 128;
11557 region.bufferImageHeight = 128;
11558 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11559 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11560 region.imageSubresource.layerCount = 0;
11561 region.imageExtent.height = 4;
11562 region.imageExtent.width = 4;
11563 region.imageExtent.depth = 1;
11564 m_commandBuffer->BeginCommandBuffer();
11565 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11566 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11567 1, &region);
11568 m_errorMonitor->VerifyFound();
11569 region.imageSubresource.layerCount = 1;
11570
11571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11572 "aspectMasks for each region must "
11573 "specify only COLOR or DEPTH or "
11574 "STENCIL");
11575 // Expect MISMATCHED_IMAGE_ASPECT
11576 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11577 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11578 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11579 1, &region);
11580 m_errorMonitor->VerifyFound();
11581 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11582
11583 m_errorMonitor->SetDesiredFailureMsg(
11584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11585 "If the format of srcImage is a depth, stencil, depth stencil or "
11586 "integer-based format then filter must be VK_FILTER_NEAREST");
11587 // Expect INVALID_FILTER
11588 VkImageObj intImage1(m_device);
11589 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11590 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11591 0);
11592 VkImageObj intImage2(m_device);
11593 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11594 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11595 0);
11596 VkImageBlit blitRegion = {};
11597 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11598 blitRegion.srcSubresource.baseArrayLayer = 0;
11599 blitRegion.srcSubresource.layerCount = 1;
11600 blitRegion.srcSubresource.mipLevel = 0;
11601 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11602 blitRegion.dstSubresource.baseArrayLayer = 0;
11603 blitRegion.dstSubresource.layerCount = 1;
11604 blitRegion.dstSubresource.mipLevel = 0;
11605
11606 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11607 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11608 16, &blitRegion, VK_FILTER_LINEAR);
11609 m_errorMonitor->VerifyFound();
11610
11611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11612 "called with 0 in ppMemoryBarriers");
11613 VkImageMemoryBarrier img_barrier;
11614 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11615 img_barrier.pNext = NULL;
11616 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11617 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11618 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11619 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11620 img_barrier.image = image.handle();
11621 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11622 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11623 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11624 img_barrier.subresourceRange.baseArrayLayer = 0;
11625 img_barrier.subresourceRange.baseMipLevel = 0;
11626 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11627 img_barrier.subresourceRange.layerCount = 0;
11628 img_barrier.subresourceRange.levelCount = 1;
11629 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11630 VK_PIPELINE_STAGE_HOST_BIT,
11631 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11632 nullptr, 1, &img_barrier);
11633 m_errorMonitor->VerifyFound();
11634 img_barrier.subresourceRange.layerCount = 1;
11635}
11636
11637TEST_F(VkLayerTest, ImageFormatLimits) {
11638
11639 TEST_DESCRIPTION("Exceed the limits of image format ");
11640
11641 m_errorMonitor->SetDesiredFailureMsg(
11642 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11643 "CreateImage extents exceed allowable limits for format");
11644 VkImageCreateInfo image_create_info = {};
11645 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11646 image_create_info.pNext = NULL;
11647 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11648 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11649 image_create_info.extent.width = 32;
11650 image_create_info.extent.height = 32;
11651 image_create_info.extent.depth = 1;
11652 image_create_info.mipLevels = 1;
11653 image_create_info.arrayLayers = 1;
11654 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11655 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11656 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11657 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11658 image_create_info.flags = 0;
11659
11660 VkImage nullImg;
11661 VkImageFormatProperties imgFmtProps;
11662 vkGetPhysicalDeviceImageFormatProperties(
11663 gpu(), image_create_info.format, image_create_info.imageType,
11664 image_create_info.tiling, image_create_info.usage,
11665 image_create_info.flags, &imgFmtProps);
11666 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11667 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11668 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11669 m_errorMonitor->VerifyFound();
11670 image_create_info.extent.depth = 1;
11671
11672 m_errorMonitor->SetDesiredFailureMsg(
11673 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11674 "exceeds allowable maximum supported by format of");
11675 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11676 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11677 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11678 m_errorMonitor->VerifyFound();
11679 image_create_info.mipLevels = 1;
11680
11681 m_errorMonitor->SetDesiredFailureMsg(
11682 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11683 "exceeds allowable maximum supported by format of");
11684 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11685 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11686 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11687 m_errorMonitor->VerifyFound();
11688 image_create_info.arrayLayers = 1;
11689
11690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11691 "is not supported by format");
11692 int samples = imgFmtProps.sampleCounts >> 1;
11693 image_create_info.samples = (VkSampleCountFlagBits)samples;
11694 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11695 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11696 m_errorMonitor->VerifyFound();
11697 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11698
11699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11700 "pCreateInfo->initialLayout, must be "
11701 "VK_IMAGE_LAYOUT_UNDEFINED or "
11702 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11703 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11704 // Expect INVALID_LAYOUT
11705 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11706 m_errorMonitor->VerifyFound();
11707 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11708}
11709
Karl Schultz6addd812016-02-02 17:17:23 -070011710TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011711 VkResult err;
11712 bool pass;
11713
11714 // Create color images with different format sizes and try to copy between them
11715 m_errorMonitor->SetDesiredFailureMsg(
11716 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11717 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11718
11719 ASSERT_NO_FATAL_FAILURE(InitState());
11720
11721 // Create two images of different types and try to copy between them
11722 VkImage srcImage;
11723 VkImage dstImage;
11724 VkDeviceMemory srcMem;
11725 VkDeviceMemory destMem;
11726 VkMemoryRequirements memReqs;
11727
11728 VkImageCreateInfo image_create_info = {};
11729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11730 image_create_info.pNext = NULL;
11731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11732 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11733 image_create_info.extent.width = 32;
11734 image_create_info.extent.height = 32;
11735 image_create_info.extent.depth = 1;
11736 image_create_info.mipLevels = 1;
11737 image_create_info.arrayLayers = 1;
11738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11739 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11741 image_create_info.flags = 0;
11742
11743 err =
11744 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11745 ASSERT_VK_SUCCESS(err);
11746
11747 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11748 // Introduce failure by creating second image with a different-sized format.
11749 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11750
11751 err =
11752 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11753 ASSERT_VK_SUCCESS(err);
11754
11755 // Allocate memory
11756 VkMemoryAllocateInfo memAlloc = {};
11757 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11758 memAlloc.pNext = NULL;
11759 memAlloc.allocationSize = 0;
11760 memAlloc.memoryTypeIndex = 0;
11761
11762 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11763 memAlloc.allocationSize = memReqs.size;
11764 pass =
11765 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11766 ASSERT_TRUE(pass);
11767 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11768 ASSERT_VK_SUCCESS(err);
11769
11770 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11771 memAlloc.allocationSize = memReqs.size;
11772 pass =
11773 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11774 ASSERT_TRUE(pass);
11775 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11776 ASSERT_VK_SUCCESS(err);
11777
11778 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11779 ASSERT_VK_SUCCESS(err);
11780 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11781 ASSERT_VK_SUCCESS(err);
11782
11783 BeginCommandBuffer();
11784 VkImageCopy copyRegion;
11785 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11786 copyRegion.srcSubresource.mipLevel = 0;
11787 copyRegion.srcSubresource.baseArrayLayer = 0;
11788 copyRegion.srcSubresource.layerCount = 0;
11789 copyRegion.srcOffset.x = 0;
11790 copyRegion.srcOffset.y = 0;
11791 copyRegion.srcOffset.z = 0;
11792 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11793 copyRegion.dstSubresource.mipLevel = 0;
11794 copyRegion.dstSubresource.baseArrayLayer = 0;
11795 copyRegion.dstSubresource.layerCount = 0;
11796 copyRegion.dstOffset.x = 0;
11797 copyRegion.dstOffset.y = 0;
11798 copyRegion.dstOffset.z = 0;
11799 copyRegion.extent.width = 1;
11800 copyRegion.extent.height = 1;
11801 copyRegion.extent.depth = 1;
11802 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11803 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11804 EndCommandBuffer();
11805
11806 m_errorMonitor->VerifyFound();
11807
11808 vkDestroyImage(m_device->device(), srcImage, NULL);
11809 vkDestroyImage(m_device->device(), dstImage, NULL);
11810 vkFreeMemory(m_device->device(), srcMem, NULL);
11811 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011812}
11813
Karl Schultz6addd812016-02-02 17:17:23 -070011814TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11815 VkResult err;
11816 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011817
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011818 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011819 m_errorMonitor->SetDesiredFailureMsg(
11820 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011821 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011822
Mike Stroyana3082432015-09-25 13:39:21 -060011823 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011824
11825 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011826 VkImage srcImage;
11827 VkImage dstImage;
11828 VkDeviceMemory srcMem;
11829 VkDeviceMemory destMem;
11830 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011831
11832 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011833 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11834 image_create_info.pNext = NULL;
11835 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11836 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11837 image_create_info.extent.width = 32;
11838 image_create_info.extent.height = 32;
11839 image_create_info.extent.depth = 1;
11840 image_create_info.mipLevels = 1;
11841 image_create_info.arrayLayers = 1;
11842 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11843 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11844 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11845 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011846
Karl Schultz6addd812016-02-02 17:17:23 -070011847 err =
11848 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011849 ASSERT_VK_SUCCESS(err);
11850
Karl Schultzbdb75952016-04-19 11:36:49 -060011851 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11852
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011853 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011854 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011855 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11856 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011857
Karl Schultz6addd812016-02-02 17:17:23 -070011858 err =
11859 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011860 ASSERT_VK_SUCCESS(err);
11861
11862 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011863 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011864 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11865 memAlloc.pNext = NULL;
11866 memAlloc.allocationSize = 0;
11867 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011868
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011869 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011870 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011871 pass =
11872 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011873 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011874 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011875 ASSERT_VK_SUCCESS(err);
11876
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011877 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011878 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011879 pass =
11880 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011881 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011882 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011883 ASSERT_VK_SUCCESS(err);
11884
11885 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11886 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011887 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011888 ASSERT_VK_SUCCESS(err);
11889
11890 BeginCommandBuffer();
11891 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011892 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011893 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011894 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011895 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011896 copyRegion.srcOffset.x = 0;
11897 copyRegion.srcOffset.y = 0;
11898 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011899 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011900 copyRegion.dstSubresource.mipLevel = 0;
11901 copyRegion.dstSubresource.baseArrayLayer = 0;
11902 copyRegion.dstSubresource.layerCount = 0;
11903 copyRegion.dstOffset.x = 0;
11904 copyRegion.dstOffset.y = 0;
11905 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011906 copyRegion.extent.width = 1;
11907 copyRegion.extent.height = 1;
11908 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011909 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11910 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011911 EndCommandBuffer();
11912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011913 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011914
Chia-I Wuf7458c52015-10-26 21:10:41 +080011915 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011916 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011917 vkFreeMemory(m_device->device(), srcMem, NULL);
11918 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011919}
11920
Karl Schultz6addd812016-02-02 17:17:23 -070011921TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11922 VkResult err;
11923 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011924
Karl Schultz6addd812016-02-02 17:17:23 -070011925 m_errorMonitor->SetDesiredFailureMsg(
11926 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011927 "vkCmdResolveImage called with source sample count less than 2.");
11928
Mike Stroyana3082432015-09-25 13:39:21 -060011929 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011930
11931 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011932 VkImage srcImage;
11933 VkImage dstImage;
11934 VkDeviceMemory srcMem;
11935 VkDeviceMemory destMem;
11936 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011937
11938 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011939 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11940 image_create_info.pNext = NULL;
11941 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11942 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11943 image_create_info.extent.width = 32;
11944 image_create_info.extent.height = 1;
11945 image_create_info.extent.depth = 1;
11946 image_create_info.mipLevels = 1;
11947 image_create_info.arrayLayers = 1;
11948 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11949 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11950 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11951 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011952
Karl Schultz6addd812016-02-02 17:17:23 -070011953 err =
11954 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011955 ASSERT_VK_SUCCESS(err);
11956
Karl Schultz6addd812016-02-02 17:17:23 -070011957 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011958
Karl Schultz6addd812016-02-02 17:17:23 -070011959 err =
11960 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011961 ASSERT_VK_SUCCESS(err);
11962
11963 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011964 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011965 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11966 memAlloc.pNext = NULL;
11967 memAlloc.allocationSize = 0;
11968 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011969
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011970 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011971 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011972 pass =
11973 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011974 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011975 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011976 ASSERT_VK_SUCCESS(err);
11977
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011978 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011979 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011980 pass =
11981 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011982 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011983 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011984 ASSERT_VK_SUCCESS(err);
11985
11986 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11987 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011988 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011989 ASSERT_VK_SUCCESS(err);
11990
11991 BeginCommandBuffer();
11992 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011993 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11994 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011995 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011996 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011997 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011998 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011999 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012000 resolveRegion.srcOffset.x = 0;
12001 resolveRegion.srcOffset.y = 0;
12002 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012003 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012004 resolveRegion.dstSubresource.mipLevel = 0;
12005 resolveRegion.dstSubresource.baseArrayLayer = 0;
12006 resolveRegion.dstSubresource.layerCount = 0;
12007 resolveRegion.dstOffset.x = 0;
12008 resolveRegion.dstOffset.y = 0;
12009 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012010 resolveRegion.extent.width = 1;
12011 resolveRegion.extent.height = 1;
12012 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012013 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12014 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012015 EndCommandBuffer();
12016
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012017 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012018
Chia-I Wuf7458c52015-10-26 21:10:41 +080012019 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012020 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012021 vkFreeMemory(m_device->device(), srcMem, NULL);
12022 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012023}
12024
Karl Schultz6addd812016-02-02 17:17:23 -070012025TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
12026 VkResult err;
12027 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012028
Karl Schultz6addd812016-02-02 17:17:23 -070012029 m_errorMonitor->SetDesiredFailureMsg(
12030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012031 "vkCmdResolveImage called with dest sample count greater than 1.");
12032
Mike Stroyana3082432015-09-25 13:39:21 -060012033 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012034
Chris Forbesa7530692016-05-08 12:35:39 +120012035 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070012036 VkImage srcImage;
12037 VkImage dstImage;
12038 VkDeviceMemory srcMem;
12039 VkDeviceMemory destMem;
12040 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012041
12042 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12044 image_create_info.pNext = NULL;
12045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12046 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12047 image_create_info.extent.width = 32;
12048 image_create_info.extent.height = 1;
12049 image_create_info.extent.depth = 1;
12050 image_create_info.mipLevels = 1;
12051 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012052 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012053 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12054 // Note: Some implementations expect color attachment usage for any
12055 // multisample surface
12056 image_create_info.usage =
12057 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12058 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012059
Karl Schultz6addd812016-02-02 17:17:23 -070012060 err =
12061 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012062 ASSERT_VK_SUCCESS(err);
12063
Karl Schultz6addd812016-02-02 17:17:23 -070012064 // Note: Some implementations expect color attachment usage for any
12065 // multisample surface
12066 image_create_info.usage =
12067 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012068
Karl Schultz6addd812016-02-02 17:17:23 -070012069 err =
12070 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012071 ASSERT_VK_SUCCESS(err);
12072
12073 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012074 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012075 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12076 memAlloc.pNext = NULL;
12077 memAlloc.allocationSize = 0;
12078 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012079
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012080 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012081 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012082 pass =
12083 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012084 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012085 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012086 ASSERT_VK_SUCCESS(err);
12087
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012088 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012089 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012090 pass =
12091 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012092 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012094 ASSERT_VK_SUCCESS(err);
12095
12096 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12097 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012098 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012099 ASSERT_VK_SUCCESS(err);
12100
12101 BeginCommandBuffer();
12102 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012103 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12104 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012105 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012106 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012107 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012108 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012109 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012110 resolveRegion.srcOffset.x = 0;
12111 resolveRegion.srcOffset.y = 0;
12112 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012113 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012114 resolveRegion.dstSubresource.mipLevel = 0;
12115 resolveRegion.dstSubresource.baseArrayLayer = 0;
12116 resolveRegion.dstSubresource.layerCount = 0;
12117 resolveRegion.dstOffset.x = 0;
12118 resolveRegion.dstOffset.y = 0;
12119 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012120 resolveRegion.extent.width = 1;
12121 resolveRegion.extent.height = 1;
12122 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012123 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12124 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012125 EndCommandBuffer();
12126
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012127 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012128
Chia-I Wuf7458c52015-10-26 21:10:41 +080012129 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012130 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012131 vkFreeMemory(m_device->device(), srcMem, NULL);
12132 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012133}
12134
Karl Schultz6addd812016-02-02 17:17:23 -070012135TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12136 VkResult err;
12137 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012138
Karl Schultz6addd812016-02-02 17:17:23 -070012139 m_errorMonitor->SetDesiredFailureMsg(
12140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012141 "vkCmdResolveImage called with unmatched source and dest formats.");
12142
Mike Stroyana3082432015-09-25 13:39:21 -060012143 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012144
12145 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012146 VkImage srcImage;
12147 VkImage dstImage;
12148 VkDeviceMemory srcMem;
12149 VkDeviceMemory destMem;
12150 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012151
12152 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012153 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12154 image_create_info.pNext = NULL;
12155 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12156 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12157 image_create_info.extent.width = 32;
12158 image_create_info.extent.height = 1;
12159 image_create_info.extent.depth = 1;
12160 image_create_info.mipLevels = 1;
12161 image_create_info.arrayLayers = 1;
12162 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12163 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12164 // Note: Some implementations expect color attachment usage for any
12165 // multisample surface
12166 image_create_info.usage =
12167 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12168 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012169
Karl Schultz6addd812016-02-02 17:17:23 -070012170 err =
12171 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012172 ASSERT_VK_SUCCESS(err);
12173
Karl Schultz6addd812016-02-02 17:17:23 -070012174 // Set format to something other than source image
12175 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12176 // Note: Some implementations expect color attachment usage for any
12177 // multisample surface
12178 image_create_info.usage =
12179 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012181
Karl Schultz6addd812016-02-02 17:17:23 -070012182 err =
12183 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012184 ASSERT_VK_SUCCESS(err);
12185
12186 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012187 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012188 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12189 memAlloc.pNext = NULL;
12190 memAlloc.allocationSize = 0;
12191 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012192
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012193 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012194 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012195 pass =
12196 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012197 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012198 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012199 ASSERT_VK_SUCCESS(err);
12200
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012201 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012202 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012203 pass =
12204 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012205 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012206 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012207 ASSERT_VK_SUCCESS(err);
12208
12209 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12210 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012211 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012212 ASSERT_VK_SUCCESS(err);
12213
12214 BeginCommandBuffer();
12215 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012216 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12217 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012218 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012219 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012220 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012221 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012222 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012223 resolveRegion.srcOffset.x = 0;
12224 resolveRegion.srcOffset.y = 0;
12225 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012226 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012227 resolveRegion.dstSubresource.mipLevel = 0;
12228 resolveRegion.dstSubresource.baseArrayLayer = 0;
12229 resolveRegion.dstSubresource.layerCount = 0;
12230 resolveRegion.dstOffset.x = 0;
12231 resolveRegion.dstOffset.y = 0;
12232 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012233 resolveRegion.extent.width = 1;
12234 resolveRegion.extent.height = 1;
12235 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012236 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12237 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012238 EndCommandBuffer();
12239
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012240 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012241
Chia-I Wuf7458c52015-10-26 21:10:41 +080012242 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012243 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012244 vkFreeMemory(m_device->device(), srcMem, NULL);
12245 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012246}
12247
Karl Schultz6addd812016-02-02 17:17:23 -070012248TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12249 VkResult err;
12250 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012251
Karl Schultz6addd812016-02-02 17:17:23 -070012252 m_errorMonitor->SetDesiredFailureMsg(
12253 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012254 "vkCmdResolveImage called with unmatched source and dest image types.");
12255
Mike Stroyana3082432015-09-25 13:39:21 -060012256 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012257
12258 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012259 VkImage srcImage;
12260 VkImage dstImage;
12261 VkDeviceMemory srcMem;
12262 VkDeviceMemory destMem;
12263 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012264
12265 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012266 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12267 image_create_info.pNext = NULL;
12268 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12269 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12270 image_create_info.extent.width = 32;
12271 image_create_info.extent.height = 1;
12272 image_create_info.extent.depth = 1;
12273 image_create_info.mipLevels = 1;
12274 image_create_info.arrayLayers = 1;
12275 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12276 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12277 // Note: Some implementations expect color attachment usage for any
12278 // multisample surface
12279 image_create_info.usage =
12280 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12281 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012282
Karl Schultz6addd812016-02-02 17:17:23 -070012283 err =
12284 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012285 ASSERT_VK_SUCCESS(err);
12286
Karl Schultz6addd812016-02-02 17:17:23 -070012287 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12288 // Note: Some implementations expect color attachment usage for any
12289 // multisample surface
12290 image_create_info.usage =
12291 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12292 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012293
Karl Schultz6addd812016-02-02 17:17:23 -070012294 err =
12295 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012296 ASSERT_VK_SUCCESS(err);
12297
12298 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012299 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012300 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12301 memAlloc.pNext = NULL;
12302 memAlloc.allocationSize = 0;
12303 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012304
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012305 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012306 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012307 pass =
12308 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012309 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012310 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012311 ASSERT_VK_SUCCESS(err);
12312
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012313 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012314 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012315 pass =
12316 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012317 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012318 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012319 ASSERT_VK_SUCCESS(err);
12320
12321 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12322 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012323 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012324 ASSERT_VK_SUCCESS(err);
12325
12326 BeginCommandBuffer();
12327 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012328 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12329 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012330 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012331 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012332 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012333 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012334 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012335 resolveRegion.srcOffset.x = 0;
12336 resolveRegion.srcOffset.y = 0;
12337 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012338 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012339 resolveRegion.dstSubresource.mipLevel = 0;
12340 resolveRegion.dstSubresource.baseArrayLayer = 0;
12341 resolveRegion.dstSubresource.layerCount = 0;
12342 resolveRegion.dstOffset.x = 0;
12343 resolveRegion.dstOffset.y = 0;
12344 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012345 resolveRegion.extent.width = 1;
12346 resolveRegion.extent.height = 1;
12347 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012348 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12349 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012350 EndCommandBuffer();
12351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012352 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012353
Chia-I Wuf7458c52015-10-26 21:10:41 +080012354 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012355 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012356 vkFreeMemory(m_device->device(), srcMem, NULL);
12357 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012358}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012359
Karl Schultz6addd812016-02-02 17:17:23 -070012360TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012361 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012362 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12363 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012364 // The image format check comes 2nd in validation so we trigger it first,
12365 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012366 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012367
Karl Schultz6addd812016-02-02 17:17:23 -070012368 m_errorMonitor->SetDesiredFailureMsg(
12369 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012370 "Combination depth/stencil image formats can have only the ");
12371
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012372 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012373
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012374 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012375 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12376 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012377
12378 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012379 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12380 ds_pool_ci.pNext = NULL;
12381 ds_pool_ci.maxSets = 1;
12382 ds_pool_ci.poolSizeCount = 1;
12383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012384
12385 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012386 err =
12387 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012388 ASSERT_VK_SUCCESS(err);
12389
12390 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012391 dsl_binding.binding = 0;
12392 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12393 dsl_binding.descriptorCount = 1;
12394 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12395 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012396
12397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12399 ds_layout_ci.pNext = NULL;
12400 ds_layout_ci.bindingCount = 1;
12401 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012402 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12404 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012405 ASSERT_VK_SUCCESS(err);
12406
12407 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012408 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012410 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012411 alloc_info.descriptorPool = ds_pool;
12412 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12414 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012415 ASSERT_VK_SUCCESS(err);
12416
Karl Schultz6addd812016-02-02 17:17:23 -070012417 VkImage image_bad;
12418 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012419 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012420 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012421 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012422 const int32_t tex_width = 32;
12423 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012424
12425 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12427 image_create_info.pNext = NULL;
12428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12429 image_create_info.format = tex_format_bad;
12430 image_create_info.extent.width = tex_width;
12431 image_create_info.extent.height = tex_height;
12432 image_create_info.extent.depth = 1;
12433 image_create_info.mipLevels = 1;
12434 image_create_info.arrayLayers = 1;
12435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12436 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12437 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12438 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12439 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012440
Karl Schultz6addd812016-02-02 17:17:23 -070012441 err =
12442 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012443 ASSERT_VK_SUCCESS(err);
12444 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012445 image_create_info.usage =
12446 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12447 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12448 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012449 ASSERT_VK_SUCCESS(err);
12450
12451 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012452 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12453 image_view_create_info.image = image_bad;
12454 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12455 image_view_create_info.format = tex_format_bad;
12456 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12457 image_view_create_info.subresourceRange.baseMipLevel = 0;
12458 image_view_create_info.subresourceRange.layerCount = 1;
12459 image_view_create_info.subresourceRange.levelCount = 1;
12460 image_view_create_info.subresourceRange.aspectMask =
12461 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012462
12463 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012464 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12465 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012466
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012467 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012468
Chia-I Wuf7458c52015-10-26 21:10:41 +080012469 vkDestroyImage(m_device->device(), image_bad, NULL);
12470 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012471 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12472 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012473}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012474
12475TEST_F(VkLayerTest, ClearImageErrors) {
12476 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12477 "ClearDepthStencilImage with a color image.");
12478
12479 ASSERT_NO_FATAL_FAILURE(InitState());
12480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12481
12482 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12483 BeginCommandBuffer();
12484 m_commandBuffer->EndRenderPass();
12485
12486 // Color image
12487 VkClearColorValue clear_color;
12488 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12489 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12490 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12491 const int32_t img_width = 32;
12492 const int32_t img_height = 32;
12493 VkImageCreateInfo image_create_info = {};
12494 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12495 image_create_info.pNext = NULL;
12496 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12497 image_create_info.format = color_format;
12498 image_create_info.extent.width = img_width;
12499 image_create_info.extent.height = img_height;
12500 image_create_info.extent.depth = 1;
12501 image_create_info.mipLevels = 1;
12502 image_create_info.arrayLayers = 1;
12503 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12504 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12505 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12506
12507 vk_testing::Image color_image;
12508 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12509 reqs);
12510
12511 const VkImageSubresourceRange color_range =
12512 vk_testing::Image::subresource_range(image_create_info,
12513 VK_IMAGE_ASPECT_COLOR_BIT);
12514
12515 // Depth/Stencil image
12516 VkClearDepthStencilValue clear_value = {0};
12517 reqs = 0; // don't need HOST_VISIBLE DS image
12518 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12519 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12520 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12521 ds_image_create_info.extent.width = 64;
12522 ds_image_create_info.extent.height = 64;
12523 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12524 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12525
12526 vk_testing::Image ds_image;
12527 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12528 reqs);
12529
12530 const VkImageSubresourceRange ds_range =
12531 vk_testing::Image::subresource_range(ds_image_create_info,
12532 VK_IMAGE_ASPECT_DEPTH_BIT);
12533
12534 m_errorMonitor->SetDesiredFailureMsg(
12535 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12536 "vkCmdClearColorImage called with depth/stencil image.");
12537
12538 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12539 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12540 &color_range);
12541
12542 m_errorMonitor->VerifyFound();
12543
Tony Barbour26434b92016-06-02 09:43:50 -060012544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12545 "vkCmdClearColorImage called with "
12546 "image created without "
12547 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12548
12549 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12550 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12551 &color_range);
12552
12553 m_errorMonitor->VerifyFound();
12554
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012555 // Call CmdClearDepthStencilImage with color image
12556 m_errorMonitor->SetDesiredFailureMsg(
12557 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12558 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12559
12560 vkCmdClearDepthStencilImage(
12561 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12562 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12563 &ds_range);
12564
12565 m_errorMonitor->VerifyFound();
12566}
Tobin Ehliscde08892015-09-22 10:11:37 -060012567#endif // IMAGE_TESTS
12568
Tony Barbour300a6082015-04-07 13:44:53 -060012569int main(int argc, char **argv) {
12570 int result;
12571
Cody Northrop8e54a402016-03-08 22:25:52 -070012572#ifdef ANDROID
12573 int vulkanSupport = InitVulkan();
12574 if (vulkanSupport == 0)
12575 return 1;
12576#endif
12577
Tony Barbour300a6082015-04-07 13:44:53 -060012578 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012579 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012580
12581 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12582
12583 result = RUN_ALL_TESTS();
12584
Tony Barbour6918cd52015-04-09 12:58:51 -060012585 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012586 return result;
12587}