blob: 5ea4733bc3a9e0c8b35e3f6c75410a0f6300806d [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
Chris Forbes4e44c912016-06-16 10:20:00 +12002414TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling)
2415{
2416 m_errorMonitor->ExpectSuccess();
2417
2418 ASSERT_NO_FATAL_FAILURE(InitState());
2419 VkResult err;
2420
2421 // A fence created signaled
2422 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
2423 VkFence f1;
2424 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
2425 ASSERT_VK_SUCCESS(err);
2426
2427 // A fence created not
2428 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2429 VkFence f2;
2430 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
2431 ASSERT_VK_SUCCESS(err);
2432
2433 // Submit the unsignaled fence
2434 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2435 0, nullptr, 0, nullptr };
2436 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
2437
2438 // Wait on both fences, with signaled first.
2439 VkFence fences[] = { f1, f2 };
2440 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
2441
2442 // Should have both retired!
2443 vkDestroyFence(m_device->device(), f1, nullptr);
2444 vkDestroyFence(m_device->device(), f2, nullptr);
2445
2446 m_errorMonitor->VerifyNotFound();
2447}
2448
Tobin Ehlis41376e12015-07-03 08:45:14 -06002449TEST_F(VkLayerTest, InvalidUsageBits)
2450{
Tony Barbourf92621a2016-05-02 14:28:12 -06002451 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002452 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002453 "Initialize buffer with wrong usage then perform copy expecting errors "
2454 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002456 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002459 VkImageObj image(m_device);
2460 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002461 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002462 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2463 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002464
Tony Barbourf92621a2016-05-02 14:28:12 -06002465 VkImageView dsv;
2466 VkImageViewCreateInfo dsvci = {};
2467 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2468 dsvci.image = image.handle();
2469 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2470 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2471 dsvci.subresourceRange.layerCount = 1;
2472 dsvci.subresourceRange.baseMipLevel = 0;
2473 dsvci.subresourceRange.levelCount = 1;
2474 dsvci.subresourceRange.aspectMask =
2475 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002476
Tony Barbourf92621a2016-05-02 14:28:12 -06002477 // Create a view with depth / stencil aspect for image with different usage
2478 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002479
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002480 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002481
2482 // Initialize buffer with TRANSFER_DST usage
2483 vk_testing::Buffer buffer;
2484 VkMemoryPropertyFlags reqs = 0;
2485 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2486 VkBufferImageCopy region = {};
2487 region.bufferRowLength = 128;
2488 region.bufferImageHeight = 128;
2489 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2490 region.imageSubresource.layerCount = 1;
2491 region.imageExtent.height = 16;
2492 region.imageExtent.width = 16;
2493 region.imageExtent.depth = 1;
2494
2495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2496 "Invalid usage flag for buffer ");
2497 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2498 // TRANSFER_DST
2499 BeginCommandBuffer();
2500 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2501 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2502 1, &region);
2503 m_errorMonitor->VerifyFound();
2504
2505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2506 "Invalid usage flag for image ");
2507 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2508 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2509 1, &region);
2510 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002511}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002512#endif // MEM_TRACKER_TESTS
2513
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002514#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002515
2516TEST_F(VkLayerTest, LeakAnObject) {
2517 VkResult err;
2518
2519 TEST_DESCRIPTION(
2520 "Create a fence and destroy its device without first destroying the fence.");
2521
2522 // Note that we have to create a new device since destroying the
2523 // framework's device causes Teardown() to fail and just calling Teardown
2524 // will destroy the errorMonitor.
2525
2526 m_errorMonitor->SetDesiredFailureMsg(
2527 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2528 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2529
2530 ASSERT_NO_FATAL_FAILURE(InitState());
2531
2532 const std::vector<VkQueueFamilyProperties> queue_props =
2533 m_device->queue_props;
2534 std::vector<VkDeviceQueueCreateInfo> queue_info;
2535 queue_info.reserve(queue_props.size());
2536 std::vector<std::vector<float>> queue_priorities;
2537 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2538 VkDeviceQueueCreateInfo qi = {};
2539 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2540 qi.pNext = NULL;
2541 qi.queueFamilyIndex = i;
2542 qi.queueCount = queue_props[i].queueCount;
2543 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2544 qi.pQueuePriorities = queue_priorities[i].data();
2545 queue_info.push_back(qi);
2546 }
2547
2548 std::vector<const char *> device_layer_names;
2549 std::vector<const char *> device_extension_names;
2550 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2551 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2552 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2553 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2554 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2555 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2556 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2557
2558 // The sacrificial device object
2559 VkDevice testDevice;
2560 VkDeviceCreateInfo device_create_info = {};
2561 auto features = m_device->phy().features();
2562 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2563 device_create_info.pNext = NULL;
2564 device_create_info.queueCreateInfoCount = queue_info.size();
2565 device_create_info.pQueueCreateInfos = queue_info.data();
2566 device_create_info.enabledLayerCount = device_layer_names.size();
2567 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2568 device_create_info.pEnabledFeatures = &features;
2569 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2570 ASSERT_VK_SUCCESS(err);
2571
2572 VkFence fence;
2573 VkFenceCreateInfo fence_create_info = {};
2574 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2575 fence_create_info.pNext = NULL;
2576 fence_create_info.flags = 0;
2577 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2578 ASSERT_VK_SUCCESS(err);
2579
2580 // Induce failure by not calling vkDestroyFence
2581 vkDestroyDevice(testDevice, NULL);
2582 m_errorMonitor->VerifyFound();
2583}
2584
2585TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2586
2587 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2588 "attempt to delete them from another.");
2589
2590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2591 "FreeCommandBuffers is attempting to free Command Buffer");
2592
2593 VkCommandPool command_pool_one;
2594 VkCommandPool command_pool_two;
2595
2596 VkCommandPoolCreateInfo pool_create_info{};
2597 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2598 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2599 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2600
2601 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2602 &command_pool_one);
2603
2604 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2605 &command_pool_two);
2606
2607 VkCommandBuffer command_buffer[9];
2608 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2609 command_buffer_allocate_info.sType =
2610 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2611 command_buffer_allocate_info.commandPool = command_pool_one;
2612 command_buffer_allocate_info.commandBufferCount = 9;
2613 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2614 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2615 command_buffer);
2616
2617 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2618 &command_buffer[3]);
2619
2620 m_errorMonitor->VerifyFound();
2621
2622 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2623 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2624}
2625
2626TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2627 VkResult err;
2628
2629 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2630 "attempt to delete them from another.");
2631
2632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2633 "FreeDescriptorSets is attempting to free descriptorSet");
2634
2635 ASSERT_NO_FATAL_FAILURE(InitState());
2636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2637
2638 VkDescriptorPoolSize ds_type_count = {};
2639 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2640 ds_type_count.descriptorCount = 1;
2641
2642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2644 ds_pool_ci.pNext = NULL;
2645 ds_pool_ci.flags = 0;
2646 ds_pool_ci.maxSets = 1;
2647 ds_pool_ci.poolSizeCount = 1;
2648 ds_pool_ci.pPoolSizes = &ds_type_count;
2649
2650 VkDescriptorPool ds_pool_one;
2651 err =
2652 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2653 ASSERT_VK_SUCCESS(err);
2654
2655 // Create a second descriptor pool
2656 VkDescriptorPool ds_pool_two;
2657 err =
2658 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2659 ASSERT_VK_SUCCESS(err);
2660
2661 VkDescriptorSetLayoutBinding dsl_binding = {};
2662 dsl_binding.binding = 0;
2663 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2664 dsl_binding.descriptorCount = 1;
2665 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2666 dsl_binding.pImmutableSamplers = NULL;
2667
2668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2670 ds_layout_ci.pNext = NULL;
2671 ds_layout_ci.bindingCount = 1;
2672 ds_layout_ci.pBindings = &dsl_binding;
2673
2674 VkDescriptorSetLayout ds_layout;
2675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2676 &ds_layout);
2677 ASSERT_VK_SUCCESS(err);
2678
2679 VkDescriptorSet descriptorSet;
2680 VkDescriptorSetAllocateInfo alloc_info = {};
2681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2682 alloc_info.descriptorSetCount = 1;
2683 alloc_info.descriptorPool = ds_pool_one;
2684 alloc_info.pSetLayouts = &ds_layout;
2685 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2686 &descriptorSet);
2687 ASSERT_VK_SUCCESS(err);
2688
2689 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2690
2691 m_errorMonitor->VerifyFound();
2692
2693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2694 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2695 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2696}
2697
2698TEST_F(VkLayerTest, CreateUnknownObject) {
2699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2700 "Invalid VkImage Object ");
2701
2702 TEST_DESCRIPTION(
2703 "Pass an invalid image object handle into a Vulkan API call.");
2704
2705 ASSERT_NO_FATAL_FAILURE(InitState());
2706
2707 // Pass bogus handle into GetImageMemoryRequirements
2708 VkMemoryRequirements mem_reqs;
2709 uint64_t fakeImageHandle = 0xCADECADE;
2710 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2711
2712 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2713
2714 m_errorMonitor->VerifyFound();
2715}
2716
Karl Schultz6addd812016-02-02 17:17:23 -07002717TEST_F(VkLayerTest, PipelineNotBound) {
2718 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002719
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002720 TEST_DESCRIPTION(
2721 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2722
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002724 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002725
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002726 ASSERT_NO_FATAL_FAILURE(InitState());
2727 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002728
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002729 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002730 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2731 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002732
2733 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002734 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2735 ds_pool_ci.pNext = NULL;
2736 ds_pool_ci.maxSets = 1;
2737 ds_pool_ci.poolSizeCount = 1;
2738 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002739
2740 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002741 err =
2742 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002743 ASSERT_VK_SUCCESS(err);
2744
2745 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002746 dsl_binding.binding = 0;
2747 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2748 dsl_binding.descriptorCount = 1;
2749 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2750 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002751
2752 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002753 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2754 ds_layout_ci.pNext = NULL;
2755 ds_layout_ci.bindingCount = 1;
2756 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002757
2758 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2760 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002761 ASSERT_VK_SUCCESS(err);
2762
2763 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002764 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002765 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002766 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002767 alloc_info.descriptorPool = ds_pool;
2768 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2770 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002771 ASSERT_VK_SUCCESS(err);
2772
2773 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002774 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2775 pipeline_layout_ci.pNext = NULL;
2776 pipeline_layout_ci.setLayoutCount = 1;
2777 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002778
2779 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2781 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002782 ASSERT_VK_SUCCESS(err);
2783
Mark Youngad779052016-01-06 14:26:04 -07002784 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002785
2786 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002787 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2788 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002789
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002790 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002791
Chia-I Wuf7458c52015-10-26 21:10:41 +08002792 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2794 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002795}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002796#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002797TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2798 VkResult err;
2799
2800 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2801 "during bind[Buffer|Image]Memory time");
2802
2803 m_errorMonitor->SetDesiredFailureMsg(
2804 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2805 "for this object type are not compatible with the memory");
2806
2807 ASSERT_NO_FATAL_FAILURE(InitState());
2808
2809 // Create an image, allocate memory, set a bad typeIndex and then try to
2810 // bind it
2811 VkImage image;
2812 VkDeviceMemory mem;
2813 VkMemoryRequirements mem_reqs;
2814 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2815 const int32_t tex_width = 32;
2816 const int32_t tex_height = 32;
2817
2818 VkImageCreateInfo image_create_info = {};
2819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2820 image_create_info.pNext = NULL;
2821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2822 image_create_info.format = tex_format;
2823 image_create_info.extent.width = tex_width;
2824 image_create_info.extent.height = tex_height;
2825 image_create_info.extent.depth = 1;
2826 image_create_info.mipLevels = 1;
2827 image_create_info.arrayLayers = 1;
2828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2830 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2831 image_create_info.flags = 0;
2832
2833 VkMemoryAllocateInfo mem_alloc = {};
2834 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2835 mem_alloc.pNext = NULL;
2836 mem_alloc.allocationSize = 0;
2837 mem_alloc.memoryTypeIndex = 0;
2838
2839 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2840 ASSERT_VK_SUCCESS(err);
2841
2842 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2843 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002844 // TODO : This is not an ideal way to cause the error and triggers a segF
2845 // on at least one android driver when attempting to Allocate the memory.
2846 // That segF may or may not be a driver bug, but really what we want to do
2847 // here is find a device-supported memory type that is also not supported
2848 // for the particular image we're binding the memory too. If no such
2849 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002850 // Introduce Failure, select likely invalid TypeIndex
2851 mem_alloc.memoryTypeIndex = 31;
2852
2853 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2854 ASSERT_VK_SUCCESS(err);
2855
2856 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2857 (void)err;
2858
2859 m_errorMonitor->VerifyFound();
2860
2861 vkDestroyImage(m_device->device(), image, NULL);
2862 vkFreeMemory(m_device->device(), mem, NULL);
2863}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002864#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002865TEST_F(VkLayerTest, BindInvalidMemory) {
2866 VkResult err;
2867 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002868
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002870 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002871
Tobin Ehlisec598302015-09-15 15:02:17 -06002872 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002873
2874 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002875 VkImage image;
2876 VkDeviceMemory mem;
2877 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002878
Karl Schultz6addd812016-02-02 17:17:23 -07002879 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2880 const int32_t tex_width = 32;
2881 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002882
2883 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2885 image_create_info.pNext = NULL;
2886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2887 image_create_info.format = tex_format;
2888 image_create_info.extent.width = tex_width;
2889 image_create_info.extent.height = tex_height;
2890 image_create_info.extent.depth = 1;
2891 image_create_info.mipLevels = 1;
2892 image_create_info.arrayLayers = 1;
2893 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2894 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2895 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2896 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002897
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002898 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002899 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2900 mem_alloc.pNext = NULL;
2901 mem_alloc.allocationSize = 0;
2902 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002903
Chia-I Wuf7458c52015-10-26 21:10:41 +08002904 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002905 ASSERT_VK_SUCCESS(err);
2906
Karl Schultz6addd812016-02-02 17:17:23 -07002907 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002908
2909 mem_alloc.allocationSize = mem_reqs.size;
2910
Karl Schultz6addd812016-02-02 17:17:23 -07002911 pass =
2912 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002913 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002914
2915 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002916 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002917 ASSERT_VK_SUCCESS(err);
2918
2919 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002920 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002921
2922 // Try to bind free memory that has been freed
2923 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2924 // This may very well return an error.
2925 (void)err;
2926
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002927 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002928
Chia-I Wuf7458c52015-10-26 21:10:41 +08002929 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002930}
2931
Karl Schultz6addd812016-02-02 17:17:23 -07002932TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2933 VkResult err;
2934 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002935
Karl Schultz6addd812016-02-02 17:17:23 -07002936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2937 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002938
Tobin Ehlisec598302015-09-15 15:02:17 -06002939 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002940
Karl Schultz6addd812016-02-02 17:17:23 -07002941 // Create an image object, allocate memory, destroy the object and then try
2942 // to bind it
2943 VkImage image;
2944 VkDeviceMemory mem;
2945 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002946
Karl Schultz6addd812016-02-02 17:17:23 -07002947 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2948 const int32_t tex_width = 32;
2949 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002950
2951 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002952 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2953 image_create_info.pNext = NULL;
2954 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2955 image_create_info.format = tex_format;
2956 image_create_info.extent.width = tex_width;
2957 image_create_info.extent.height = tex_height;
2958 image_create_info.extent.depth = 1;
2959 image_create_info.mipLevels = 1;
2960 image_create_info.arrayLayers = 1;
2961 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2962 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2963 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2964 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002965
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002966 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002967 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2968 mem_alloc.pNext = NULL;
2969 mem_alloc.allocationSize = 0;
2970 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002971
Chia-I Wuf7458c52015-10-26 21:10:41 +08002972 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973 ASSERT_VK_SUCCESS(err);
2974
Karl Schultz6addd812016-02-02 17:17:23 -07002975 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002976
2977 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002978 pass =
2979 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002980 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002981
2982 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002983 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002984 ASSERT_VK_SUCCESS(err);
2985
2986 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002987 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002988 ASSERT_VK_SUCCESS(err);
2989
2990 // Now Try to bind memory to this destroyed object
2991 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2992 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002993 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002995 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002996
Chia-I Wuf7458c52015-10-26 21:10:41 +08002997 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002998}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002999
Mark Lobodzinski209b5292015-09-17 09:44:05 -06003000#endif // OBJ_TRACKER_TESTS
3001
Tobin Ehlis0788f522015-05-26 16:11:58 -06003002#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003003
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003004// This is a positive test. No errors are expected.
3005TEST_F(VkLayerTest, StencilLoadOp) {
3006 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
3007 "CLEAR. stencil[Load|Store]Op used to be ignored.");
3008 VkResult result = VK_SUCCESS;
3009 VkImageFormatProperties formatProps;
3010 vkGetPhysicalDeviceImageFormatProperties(
3011 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
3012 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3013 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
3014 0, &formatProps);
3015 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
3016 return;
3017 }
3018
3019 ASSERT_NO_FATAL_FAILURE(InitState());
3020 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
3021 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
3022 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3023 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
3024 VkAttachmentDescription att = {};
3025 VkAttachmentReference ref = {};
3026 att.format = depth_stencil_fmt;
3027 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3028 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
3029 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3030 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
3031 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3032 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3033
3034 VkClearValue clear;
3035 clear.depthStencil.depth = 1.0;
3036 clear.depthStencil.stencil = 0;
3037 ref.attachment = 0;
3038 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3039
3040 VkSubpassDescription subpass = {};
3041 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
3042 subpass.flags = 0;
3043 subpass.inputAttachmentCount = 0;
3044 subpass.pInputAttachments = NULL;
3045 subpass.colorAttachmentCount = 0;
3046 subpass.pColorAttachments = NULL;
3047 subpass.pResolveAttachments = NULL;
3048 subpass.pDepthStencilAttachment = &ref;
3049 subpass.preserveAttachmentCount = 0;
3050 subpass.pPreserveAttachments = NULL;
3051
3052 VkRenderPass rp;
3053 VkRenderPassCreateInfo rp_info = {};
3054 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3055 rp_info.attachmentCount = 1;
3056 rp_info.pAttachments = &att;
3057 rp_info.subpassCount = 1;
3058 rp_info.pSubpasses = &subpass;
3059 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
3060 ASSERT_VK_SUCCESS(result);
3061
3062 VkImageView *depthView = m_depthStencil->BindInfo();
3063 VkFramebufferCreateInfo fb_info = {};
3064 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3065 fb_info.pNext = NULL;
3066 fb_info.renderPass = rp;
3067 fb_info.attachmentCount = 1;
3068 fb_info.pAttachments = depthView;
3069 fb_info.width = 100;
3070 fb_info.height = 100;
3071 fb_info.layers = 1;
3072 VkFramebuffer fb;
3073 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3074 ASSERT_VK_SUCCESS(result);
3075
3076
3077 VkRenderPassBeginInfo rpbinfo = {};
3078 rpbinfo.clearValueCount = 1;
3079 rpbinfo.pClearValues = &clear;
3080 rpbinfo.pNext = NULL;
3081 rpbinfo.renderPass = rp;
3082 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3083 rpbinfo.renderArea.extent.width = 100;
3084 rpbinfo.renderArea.extent.height = 100;
3085 rpbinfo.renderArea.offset.x = 0;
3086 rpbinfo.renderArea.offset.y = 0;
3087 rpbinfo.framebuffer = fb;
3088
3089 VkFence fence = {};
3090 VkFenceCreateInfo fence_ci = {};
3091 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3092 fence_ci.pNext = nullptr;
3093 fence_ci.flags = 0;
3094 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3095 ASSERT_VK_SUCCESS(result);
3096
3097
3098 m_commandBuffer->BeginCommandBuffer();
3099 m_commandBuffer->BeginRenderPass(rpbinfo);
3100 m_commandBuffer->EndRenderPass();
3101 m_commandBuffer->EndCommandBuffer();
3102 m_commandBuffer->QueueCommandBuffer(fence);
3103
3104 VkImageObj destImage(m_device);
3105 destImage.init(100, 100, depth_stencil_fmt,
3106 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3107 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3108 VK_IMAGE_TILING_OPTIMAL, 0);
3109 VkImageMemoryBarrier barrier = {};
3110 VkImageSubresourceRange range;
3111 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3112 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3113 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3114 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3115 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3116 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3117 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3118 barrier.image = m_depthStencil->handle();
3119 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3120 range.baseMipLevel = 0;
3121 range.levelCount = 1;
3122 range.baseArrayLayer = 0;
3123 range.layerCount = 1;
3124 barrier.subresourceRange = range;
3125 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3126 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3127 cmdbuf.BeginCommandBuffer();
3128 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3129 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3130 nullptr, 1, &barrier);
3131 barrier.srcAccessMask = 0;
3132 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3133 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3134 barrier.image = destImage.handle();
3135 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3136 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3137 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3138 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3139 nullptr, 1, &barrier);
3140 VkImageCopy cregion;
3141 cregion.srcSubresource.aspectMask =
3142 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3143 cregion.srcSubresource.mipLevel = 0;
3144 cregion.srcSubresource.baseArrayLayer = 0;
3145 cregion.srcSubresource.layerCount = 1;
3146 cregion.srcOffset.x = 0;
3147 cregion.srcOffset.y = 0;
3148 cregion.srcOffset.z = 0;
3149 cregion.dstSubresource.aspectMask =
3150 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3151 cregion.dstSubresource.mipLevel = 0;
3152 cregion.dstSubresource.baseArrayLayer = 0;
3153 cregion.dstSubresource.layerCount = 1;
3154 cregion.dstOffset.x = 0;
3155 cregion.dstOffset.y = 0;
3156 cregion.dstOffset.z = 0;
3157 cregion.extent.width = 100;
3158 cregion.extent.height = 100;
3159 cregion.extent.depth = 1;
3160 cmdbuf.CopyImage(m_depthStencil->handle(),
3161 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3162 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3163 cmdbuf.EndCommandBuffer();
3164
3165 VkSubmitInfo submit_info;
3166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3167 submit_info.pNext = NULL;
3168 submit_info.waitSemaphoreCount = 0;
3169 submit_info.pWaitSemaphores = NULL;
3170 submit_info.pWaitDstStageMask = NULL;
3171 submit_info.commandBufferCount = 1;
3172 submit_info.pCommandBuffers = &cmdbuf.handle();
3173 submit_info.signalSemaphoreCount = 0;
3174 submit_info.pSignalSemaphores = NULL;
3175
3176 m_errorMonitor->ExpectSuccess();
3177 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3178 m_errorMonitor->VerifyNotFound();
3179
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003180 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003181 vkDestroyFence(m_device->device(), fence, nullptr);
3182 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3183 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3184}
3185
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003186TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3187 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3188 "attachment reference of VK_ATTACHMENT_UNUSED");
3189
3190 ASSERT_NO_FATAL_FAILURE(InitState());
3191 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3192
3193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3194 "must not be VK_ATTACHMENT_UNUSED");
3195
3196 VkAttachmentReference color_attach = {};
3197 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3198 color_attach.attachment = 0;
3199 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3200 VkSubpassDescription subpass = {};
3201 subpass.colorAttachmentCount = 1;
3202 subpass.pColorAttachments = &color_attach;
3203 subpass.preserveAttachmentCount = 1;
3204 subpass.pPreserveAttachments = &preserve_attachment;
3205
3206 VkRenderPassCreateInfo rpci = {};
3207 rpci.subpassCount = 1;
3208 rpci.pSubpasses = &subpass;
3209 rpci.attachmentCount = 1;
3210 VkAttachmentDescription attach_desc = {};
3211 attach_desc.format = VK_FORMAT_UNDEFINED;
3212 rpci.pAttachments = &attach_desc;
3213 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3214 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003215 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003216
3217 m_errorMonitor->VerifyFound();
3218
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003219 if (result == VK_SUCCESS) {
3220 vkDestroyRenderPass(m_device->device(), rp, NULL);
3221 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003222}
3223
3224TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3225 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3226 "in the depthStencil attachment point");
3227
3228 ASSERT_NO_FATAL_FAILURE(InitState());
3229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3230
3231 m_errorMonitor->SetDesiredFailureMsg(
3232 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3233 "conflicts with the image's IMAGE_USAGE flags");
3234
3235 // Create a renderPass with a depth-stencil attachment created with
3236 // IMAGE_USAGE_COLOR_ATTACHMENT
3237 VkAttachmentReference attach = {};
3238 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3239 VkSubpassDescription subpass = {};
3240 // Add our color attachment to pDepthStencilAttachment
3241 subpass.pDepthStencilAttachment = &attach;
3242 VkRenderPassCreateInfo rpci = {};
3243 rpci.subpassCount = 1;
3244 rpci.pSubpasses = &subpass;
3245 rpci.attachmentCount = 1;
3246 VkAttachmentDescription attach_desc = {};
3247 attach_desc.format = VK_FORMAT_UNDEFINED;
3248 rpci.pAttachments = &attach_desc;
3249 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3250 VkRenderPass rp;
3251 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3252 ASSERT_VK_SUCCESS(err);
3253
3254 VkImageView imageView =
3255 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3256 VkFramebufferCreateInfo fb_info = {};
3257 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3258 fb_info.pNext = NULL;
3259 fb_info.renderPass = rp;
3260 fb_info.attachmentCount = 1;
3261 fb_info.pAttachments = &imageView;
3262 fb_info.width = 100;
3263 fb_info.height = 100;
3264 fb_info.layers = 1;
3265
3266 VkFramebuffer fb;
3267 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3268
3269 m_errorMonitor->VerifyFound();
3270
3271 if (err == VK_SUCCESS) {
3272 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3273 }
3274 vkDestroyRenderPass(m_device->device(), rp, NULL);
3275}
3276
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003277// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003278TEST_F(VkLayerTest, WaitEventThenSet) {
3279 TEST_DESCRIPTION(
3280 "Wait on a event then set it after the wait has been submitted.");
3281
Michael Lentine860b0fe2016-05-20 10:14:00 -05003282 m_errorMonitor->ExpectSuccess();
3283
3284 VkEvent event;
3285 VkEventCreateInfo event_create_info{};
3286 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3287 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3288
3289 VkCommandPool command_pool;
3290 VkCommandPoolCreateInfo pool_create_info{};
3291 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3292 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3293 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3294 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3295 &command_pool);
3296
3297 VkCommandBuffer command_buffer;
3298 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3299 command_buffer_allocate_info.sType =
3300 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3301 command_buffer_allocate_info.commandPool = command_pool;
3302 command_buffer_allocate_info.commandBufferCount = 1;
3303 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3304 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3305 &command_buffer);
3306
3307 VkQueue queue = VK_NULL_HANDLE;
3308 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003309 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003310
3311 {
3312 VkCommandBufferBeginInfo begin_info{};
3313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3314 vkBeginCommandBuffer(command_buffer, &begin_info);
3315
3316 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3317 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3318 nullptr, 0, nullptr);
3319 vkCmdResetEvent(command_buffer, event,
3320 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3321 vkEndCommandBuffer(command_buffer);
3322 }
3323 {
3324 VkSubmitInfo submit_info{};
3325 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3326 submit_info.commandBufferCount = 1;
3327 submit_info.pCommandBuffers = &command_buffer;
3328 submit_info.signalSemaphoreCount = 0;
3329 submit_info.pSignalSemaphores = nullptr;
3330 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3331 }
3332 { vkSetEvent(m_device->device(), event); }
3333
3334 vkQueueWaitIdle(queue);
3335
3336 vkDestroyEvent(m_device->device(), event, nullptr);
3337 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3338 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3339
3340 m_errorMonitor->VerifyNotFound();
3341}
Michael Lentine5627e692016-05-20 17:45:02 -05003342// This is a positive test. No errors should be generated.
3343TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3344 TEST_DESCRIPTION(
3345 "Issue a query and copy from it on a second command buffer.");
3346
3347 if ((m_device->queue_props.empty()) ||
3348 (m_device->queue_props[0].queueCount < 2))
3349 return;
3350
3351 m_errorMonitor->ExpectSuccess();
3352
3353 VkQueryPool query_pool;
3354 VkQueryPoolCreateInfo query_pool_create_info{};
3355 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3356 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3357 query_pool_create_info.queryCount = 1;
3358 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3359 &query_pool);
3360
3361 VkCommandPool command_pool;
3362 VkCommandPoolCreateInfo pool_create_info{};
3363 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3364 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3365 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3366 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3367 &command_pool);
3368
3369 VkCommandBuffer command_buffer[2];
3370 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3371 command_buffer_allocate_info.sType =
3372 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3373 command_buffer_allocate_info.commandPool = command_pool;
3374 command_buffer_allocate_info.commandBufferCount = 2;
3375 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3376 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3377 command_buffer);
3378
3379 VkQueue queue = VK_NULL_HANDLE;
3380 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3381 1, &queue);
3382
3383 uint32_t qfi = 0;
3384 VkBufferCreateInfo buff_create_info = {};
3385 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3386 buff_create_info.size = 1024;
3387 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3388 buff_create_info.queueFamilyIndexCount = 1;
3389 buff_create_info.pQueueFamilyIndices = &qfi;
3390
3391 VkResult err;
3392 VkBuffer buffer;
3393 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3394 ASSERT_VK_SUCCESS(err);
3395 VkMemoryAllocateInfo mem_alloc = {};
3396 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3397 mem_alloc.pNext = NULL;
3398 mem_alloc.allocationSize = 1024;
3399 mem_alloc.memoryTypeIndex = 0;
3400
3401 VkMemoryRequirements memReqs;
3402 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3403 bool pass =
3404 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3405 if (!pass) {
3406 vkDestroyBuffer(m_device->device(), buffer, NULL);
3407 return;
3408 }
3409
3410 VkDeviceMemory mem;
3411 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3412 ASSERT_VK_SUCCESS(err);
3413 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3414 ASSERT_VK_SUCCESS(err);
3415
3416 {
3417 VkCommandBufferBeginInfo begin_info{};
3418 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3419 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3420
3421 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3422 vkCmdWriteTimestamp(command_buffer[0],
3423 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3424
3425 vkEndCommandBuffer(command_buffer[0]);
3426
3427 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3428
3429 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3430 0, 0, 0);
3431
3432 vkEndCommandBuffer(command_buffer[1]);
3433 }
3434 {
3435 VkSubmitInfo submit_info{};
3436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3437 submit_info.commandBufferCount = 2;
3438 submit_info.pCommandBuffers = command_buffer;
3439 submit_info.signalSemaphoreCount = 0;
3440 submit_info.pSignalSemaphores = nullptr;
3441 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3442 }
3443
3444 vkQueueWaitIdle(queue);
3445
3446 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3447 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3448 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003449 vkDestroyBuffer(m_device->device(), buffer, NULL);
3450 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003451
3452 m_errorMonitor->VerifyNotFound();
3453}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003454
3455TEST_F(VkLayerTest, ResetEventThenSet) {
3456 TEST_DESCRIPTION(
3457 "Reset an event then set it after the reset has been submitted.");
3458
Michael Lentine860b0fe2016-05-20 10:14:00 -05003459 m_errorMonitor->ExpectSuccess();
3460
3461 VkEvent event;
3462 VkEventCreateInfo event_create_info{};
3463 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3464 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3465
3466 VkCommandPool command_pool;
3467 VkCommandPoolCreateInfo pool_create_info{};
3468 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3469 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3470 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3471 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3472 &command_pool);
3473
3474 VkCommandBuffer command_buffer;
3475 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3476 command_buffer_allocate_info.sType =
3477 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3478 command_buffer_allocate_info.commandPool = command_pool;
3479 command_buffer_allocate_info.commandBufferCount = 1;
3480 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3481 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3482 &command_buffer);
3483
3484 VkQueue queue = VK_NULL_HANDLE;
3485 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003486 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003487
3488 {
3489 VkCommandBufferBeginInfo begin_info{};
3490 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3491 vkBeginCommandBuffer(command_buffer, &begin_info);
3492
3493 vkCmdResetEvent(command_buffer, event,
3494 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3495 vkCmdWaitEvents(command_buffer, 1, &event,
3496 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3497 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3498 nullptr, 0, nullptr);
3499 vkEndCommandBuffer(command_buffer);
3500 }
3501 {
3502 VkSubmitInfo submit_info{};
3503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3504 submit_info.commandBufferCount = 1;
3505 submit_info.pCommandBuffers = &command_buffer;
3506 submit_info.signalSemaphoreCount = 0;
3507 submit_info.pSignalSemaphores = nullptr;
3508 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3509 }
3510 {
3511 m_errorMonitor->SetDesiredFailureMsg(
3512 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3513 "0x1 that is already in use by a "
3514 "command buffer.");
3515 vkSetEvent(m_device->device(), event);
3516 m_errorMonitor->VerifyFound();
3517 }
3518
3519 vkQueueWaitIdle(queue);
3520
3521 vkDestroyEvent(m_device->device(), event, nullptr);
3522 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3523 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3524}
3525
3526// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003527TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3528 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3529 "run through a Submit & WaitForFences cycle 3 times. This "
3530 "previously revealed a bug so running this positive test "
3531 "to prevent a regression.");
3532 m_errorMonitor->ExpectSuccess();
3533
3534 ASSERT_NO_FATAL_FAILURE(InitState());
3535 VkQueue queue = VK_NULL_HANDLE;
3536 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3537 0, &queue);
3538
3539 static const uint32_t NUM_OBJECTS = 2;
3540 static const uint32_t NUM_FRAMES = 3;
3541 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3542 VkFence fences[NUM_OBJECTS] = {};
3543
3544 VkCommandPool cmd_pool;
3545 VkCommandPoolCreateInfo cmd_pool_ci = {};
3546 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3547 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3548 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3549 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3550 nullptr, &cmd_pool);
3551 ASSERT_VK_SUCCESS(err);
3552
3553 VkCommandBufferAllocateInfo cmd_buf_info = {};
3554 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3555 cmd_buf_info.commandPool = cmd_pool;
3556 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3557 cmd_buf_info.commandBufferCount = 1;
3558
3559 VkFenceCreateInfo fence_ci = {};
3560 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3561 fence_ci.pNext = nullptr;
3562 fence_ci.flags = 0;
3563
3564 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3565 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3566 &cmd_buffers[i]);
3567 ASSERT_VK_SUCCESS(err);
3568 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3569 ASSERT_VK_SUCCESS(err);
3570 }
3571
3572 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003573 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3574 // Create empty cmd buffer
3575 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3576 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003577
Tobin Ehlisf9025162016-05-26 06:55:21 -06003578 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3579 ASSERT_VK_SUCCESS(err);
3580 err = vkEndCommandBuffer(cmd_buffers[obj]);
3581 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003582
Tobin Ehlisf9025162016-05-26 06:55:21 -06003583 VkSubmitInfo submit_info = {};
3584 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3585 submit_info.commandBufferCount = 1;
3586 submit_info.pCommandBuffers = &cmd_buffers[obj];
3587 // Submit cmd buffer and wait for fence
3588 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3589 ASSERT_VK_SUCCESS(err);
3590 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3591 UINT64_MAX);
3592 ASSERT_VK_SUCCESS(err);
3593 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3594 ASSERT_VK_SUCCESS(err);
3595 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003596 }
3597 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003598 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3599 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3600 vkDestroyFence(m_device->device(), fences[i], nullptr);
3601 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003602}
3603// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003604TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3605
3606 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3607 "submitted on separate queues followed by a QueueWaitIdle.");
3608
Dustin Graves48458142016-04-29 16:11:55 -06003609 if ((m_device->queue_props.empty()) ||
3610 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003611 return;
3612
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003613 m_errorMonitor->ExpectSuccess();
3614
3615 VkSemaphore semaphore;
3616 VkSemaphoreCreateInfo semaphore_create_info{};
3617 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3618 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3619 &semaphore);
3620
3621 VkCommandPool command_pool;
3622 VkCommandPoolCreateInfo pool_create_info{};
3623 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3624 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3625 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3626 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3627 &command_pool);
3628
3629 VkCommandBuffer command_buffer[2];
3630 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3631 command_buffer_allocate_info.sType =
3632 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3633 command_buffer_allocate_info.commandPool = command_pool;
3634 command_buffer_allocate_info.commandBufferCount = 2;
3635 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3636 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3637 command_buffer);
3638
3639 VkQueue queue = VK_NULL_HANDLE;
3640 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3641 1, &queue);
3642
3643 {
3644 VkCommandBufferBeginInfo begin_info{};
3645 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3646 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3647
3648 vkCmdPipelineBarrier(command_buffer[0],
3649 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3650 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3651 0, nullptr, 0, nullptr);
3652
3653 VkViewport viewport{};
3654 viewport.maxDepth = 1.0f;
3655 viewport.minDepth = 0.0f;
3656 viewport.width = 512;
3657 viewport.height = 512;
3658 viewport.x = 0;
3659 viewport.y = 0;
3660 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3661 vkEndCommandBuffer(command_buffer[0]);
3662 }
3663 {
3664 VkCommandBufferBeginInfo begin_info{};
3665 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3666 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3667
3668 VkViewport viewport{};
3669 viewport.maxDepth = 1.0f;
3670 viewport.minDepth = 0.0f;
3671 viewport.width = 512;
3672 viewport.height = 512;
3673 viewport.x = 0;
3674 viewport.y = 0;
3675 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3676 vkEndCommandBuffer(command_buffer[1]);
3677 }
3678 {
3679 VkSubmitInfo submit_info{};
3680 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3681 submit_info.commandBufferCount = 1;
3682 submit_info.pCommandBuffers = &command_buffer[0];
3683 submit_info.signalSemaphoreCount = 1;
3684 submit_info.pSignalSemaphores = &semaphore;
3685 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3686 }
3687 {
3688 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3689 VkSubmitInfo submit_info{};
3690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3691 submit_info.commandBufferCount = 1;
3692 submit_info.pCommandBuffers = &command_buffer[1];
3693 submit_info.waitSemaphoreCount = 1;
3694 submit_info.pWaitSemaphores = &semaphore;
3695 submit_info.pWaitDstStageMask = flags;
3696 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3697 }
3698
3699 vkQueueWaitIdle(m_device->m_queue);
3700
3701 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3702 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3703 &command_buffer[0]);
3704 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3705
3706 m_errorMonitor->VerifyNotFound();
3707}
3708
3709// This is a positive test. No errors should be generated.
3710TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3711
3712 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3713 "submitted on separate queues, the second having a fence"
3714 "followed by a QueueWaitIdle.");
3715
Dustin Graves48458142016-04-29 16:11:55 -06003716 if ((m_device->queue_props.empty()) ||
3717 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003718 return;
3719
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003720 m_errorMonitor->ExpectSuccess();
3721
3722 VkFence fence;
3723 VkFenceCreateInfo fence_create_info{};
3724 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3725 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3726
3727 VkSemaphore semaphore;
3728 VkSemaphoreCreateInfo semaphore_create_info{};
3729 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3730 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3731 &semaphore);
3732
3733 VkCommandPool command_pool;
3734 VkCommandPoolCreateInfo pool_create_info{};
3735 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3736 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3737 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3738 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3739 &command_pool);
3740
3741 VkCommandBuffer command_buffer[2];
3742 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3743 command_buffer_allocate_info.sType =
3744 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3745 command_buffer_allocate_info.commandPool = command_pool;
3746 command_buffer_allocate_info.commandBufferCount = 2;
3747 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3748 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3749 command_buffer);
3750
3751 VkQueue queue = VK_NULL_HANDLE;
3752 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3753 1, &queue);
3754
3755 {
3756 VkCommandBufferBeginInfo begin_info{};
3757 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3758 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3759
3760 vkCmdPipelineBarrier(command_buffer[0],
3761 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3763 0, nullptr, 0, nullptr);
3764
3765 VkViewport viewport{};
3766 viewport.maxDepth = 1.0f;
3767 viewport.minDepth = 0.0f;
3768 viewport.width = 512;
3769 viewport.height = 512;
3770 viewport.x = 0;
3771 viewport.y = 0;
3772 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3773 vkEndCommandBuffer(command_buffer[0]);
3774 }
3775 {
3776 VkCommandBufferBeginInfo begin_info{};
3777 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3778 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3779
3780 VkViewport viewport{};
3781 viewport.maxDepth = 1.0f;
3782 viewport.minDepth = 0.0f;
3783 viewport.width = 512;
3784 viewport.height = 512;
3785 viewport.x = 0;
3786 viewport.y = 0;
3787 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3788 vkEndCommandBuffer(command_buffer[1]);
3789 }
3790 {
3791 VkSubmitInfo submit_info{};
3792 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3793 submit_info.commandBufferCount = 1;
3794 submit_info.pCommandBuffers = &command_buffer[0];
3795 submit_info.signalSemaphoreCount = 1;
3796 submit_info.pSignalSemaphores = &semaphore;
3797 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3798 }
3799 {
3800 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3801 VkSubmitInfo submit_info{};
3802 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3803 submit_info.commandBufferCount = 1;
3804 submit_info.pCommandBuffers = &command_buffer[1];
3805 submit_info.waitSemaphoreCount = 1;
3806 submit_info.pWaitSemaphores = &semaphore;
3807 submit_info.pWaitDstStageMask = flags;
3808 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3809 }
3810
3811 vkQueueWaitIdle(m_device->m_queue);
3812
3813 vkDestroyFence(m_device->device(), fence, nullptr);
3814 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3815 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3816 &command_buffer[0]);
3817 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3818
3819 m_errorMonitor->VerifyNotFound();
3820}
3821
3822// This is a positive test. No errors should be generated.
3823TEST_F(VkLayerTest,
3824 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3825
3826 TEST_DESCRIPTION(
3827 "Two command buffers, each in a separate QueueSubmit call "
3828 "submitted on separate queues, the second having a fence"
3829 "followed by two consecutive WaitForFences calls on the same fence.");
3830
Dustin Graves48458142016-04-29 16:11:55 -06003831 if ((m_device->queue_props.empty()) ||
3832 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003833 return;
3834
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003835 m_errorMonitor->ExpectSuccess();
3836
3837 VkFence fence;
3838 VkFenceCreateInfo fence_create_info{};
3839 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3840 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3841
3842 VkSemaphore semaphore;
3843 VkSemaphoreCreateInfo semaphore_create_info{};
3844 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3845 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3846 &semaphore);
3847
3848 VkCommandPool command_pool;
3849 VkCommandPoolCreateInfo pool_create_info{};
3850 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3851 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3852 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3853 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3854 &command_pool);
3855
3856 VkCommandBuffer command_buffer[2];
3857 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3858 command_buffer_allocate_info.sType =
3859 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3860 command_buffer_allocate_info.commandPool = command_pool;
3861 command_buffer_allocate_info.commandBufferCount = 2;
3862 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3863 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3864 command_buffer);
3865
3866 VkQueue queue = VK_NULL_HANDLE;
3867 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3868 1, &queue);
3869
3870 {
3871 VkCommandBufferBeginInfo begin_info{};
3872 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3873 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3874
3875 vkCmdPipelineBarrier(command_buffer[0],
3876 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3877 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3878 0, nullptr, 0, nullptr);
3879
3880 VkViewport viewport{};
3881 viewport.maxDepth = 1.0f;
3882 viewport.minDepth = 0.0f;
3883 viewport.width = 512;
3884 viewport.height = 512;
3885 viewport.x = 0;
3886 viewport.y = 0;
3887 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3888 vkEndCommandBuffer(command_buffer[0]);
3889 }
3890 {
3891 VkCommandBufferBeginInfo begin_info{};
3892 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3893 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3894
3895 VkViewport viewport{};
3896 viewport.maxDepth = 1.0f;
3897 viewport.minDepth = 0.0f;
3898 viewport.width = 512;
3899 viewport.height = 512;
3900 viewport.x = 0;
3901 viewport.y = 0;
3902 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3903 vkEndCommandBuffer(command_buffer[1]);
3904 }
3905 {
3906 VkSubmitInfo submit_info{};
3907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3908 submit_info.commandBufferCount = 1;
3909 submit_info.pCommandBuffers = &command_buffer[0];
3910 submit_info.signalSemaphoreCount = 1;
3911 submit_info.pSignalSemaphores = &semaphore;
3912 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3913 }
3914 {
3915 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3916 VkSubmitInfo submit_info{};
3917 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3918 submit_info.commandBufferCount = 1;
3919 submit_info.pCommandBuffers = &command_buffer[1];
3920 submit_info.waitSemaphoreCount = 1;
3921 submit_info.pWaitSemaphores = &semaphore;
3922 submit_info.pWaitDstStageMask = flags;
3923 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3924 }
3925
3926 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3927 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3928
3929 vkDestroyFence(m_device->device(), fence, nullptr);
3930 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3931 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3932 &command_buffer[0]);
3933 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3934
3935 m_errorMonitor->VerifyNotFound();
3936}
3937
3938// This is a positive test. No errors should be generated.
3939TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3940
3941 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3942 "submitted on separate queues, the second having a fence, "
3943 "followed by a WaitForFences call.");
3944
Dustin Graves48458142016-04-29 16:11:55 -06003945 if ((m_device->queue_props.empty()) ||
3946 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003947 return;
3948
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003949 m_errorMonitor->ExpectSuccess();
3950
3951 VkFence fence;
3952 VkFenceCreateInfo fence_create_info{};
3953 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3954 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3955
3956 VkSemaphore semaphore;
3957 VkSemaphoreCreateInfo semaphore_create_info{};
3958 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3959 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3960 &semaphore);
3961
3962 VkCommandPool command_pool;
3963 VkCommandPoolCreateInfo pool_create_info{};
3964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3968 &command_pool);
3969
3970 VkCommandBuffer command_buffer[2];
3971 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3972 command_buffer_allocate_info.sType =
3973 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3974 command_buffer_allocate_info.commandPool = command_pool;
3975 command_buffer_allocate_info.commandBufferCount = 2;
3976 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3977 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3978 command_buffer);
3979
3980 VkQueue queue = VK_NULL_HANDLE;
3981 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3982 1, &queue);
3983
3984
3985 {
3986 VkCommandBufferBeginInfo begin_info{};
3987 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3988 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3989
3990 vkCmdPipelineBarrier(command_buffer[0],
3991 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3992 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3993 0, nullptr, 0, nullptr);
3994
3995 VkViewport viewport{};
3996 viewport.maxDepth = 1.0f;
3997 viewport.minDepth = 0.0f;
3998 viewport.width = 512;
3999 viewport.height = 512;
4000 viewport.x = 0;
4001 viewport.y = 0;
4002 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4003 vkEndCommandBuffer(command_buffer[0]);
4004 }
4005 {
4006 VkCommandBufferBeginInfo begin_info{};
4007 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4008 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4009
4010 VkViewport viewport{};
4011 viewport.maxDepth = 1.0f;
4012 viewport.minDepth = 0.0f;
4013 viewport.width = 512;
4014 viewport.height = 512;
4015 viewport.x = 0;
4016 viewport.y = 0;
4017 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4018 vkEndCommandBuffer(command_buffer[1]);
4019 }
4020 {
4021 VkSubmitInfo submit_info{};
4022 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4023 submit_info.commandBufferCount = 1;
4024 submit_info.pCommandBuffers = &command_buffer[0];
4025 submit_info.signalSemaphoreCount = 1;
4026 submit_info.pSignalSemaphores = &semaphore;
4027 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
4028 }
4029 {
4030 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4031 VkSubmitInfo submit_info{};
4032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4033 submit_info.commandBufferCount = 1;
4034 submit_info.pCommandBuffers = &command_buffer[1];
4035 submit_info.waitSemaphoreCount = 1;
4036 submit_info.pWaitSemaphores = &semaphore;
4037 submit_info.pWaitDstStageMask = flags;
4038 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4039 }
4040
4041 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4042
4043 vkDestroyFence(m_device->device(), fence, nullptr);
4044 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4045 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4046 &command_buffer[0]);
4047 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4048
4049 m_errorMonitor->VerifyNotFound();
4050}
4051
4052// This is a positive test. No errors should be generated.
4053TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
4054
4055 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4056 "on the same queue, sharing a signal/wait semaphore, the "
4057 "second having a fence, "
4058 "followed by a WaitForFences call.");
4059
4060 m_errorMonitor->ExpectSuccess();
4061
4062 VkFence fence;
4063 VkFenceCreateInfo fence_create_info{};
4064 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4065 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4066
4067 VkSemaphore semaphore;
4068 VkSemaphoreCreateInfo semaphore_create_info{};
4069 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4070 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4071 &semaphore);
4072
4073 VkCommandPool command_pool;
4074 VkCommandPoolCreateInfo pool_create_info{};
4075 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4076 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4077 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4078 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4079 &command_pool);
4080
4081 VkCommandBuffer command_buffer[2];
4082 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4083 command_buffer_allocate_info.sType =
4084 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4085 command_buffer_allocate_info.commandPool = command_pool;
4086 command_buffer_allocate_info.commandBufferCount = 2;
4087 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4088 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4089 command_buffer);
4090
4091 {
4092 VkCommandBufferBeginInfo begin_info{};
4093 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4094 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4095
4096 vkCmdPipelineBarrier(command_buffer[0],
4097 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4098 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4099 0, nullptr, 0, nullptr);
4100
4101 VkViewport viewport{};
4102 viewport.maxDepth = 1.0f;
4103 viewport.minDepth = 0.0f;
4104 viewport.width = 512;
4105 viewport.height = 512;
4106 viewport.x = 0;
4107 viewport.y = 0;
4108 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4109 vkEndCommandBuffer(command_buffer[0]);
4110 }
4111 {
4112 VkCommandBufferBeginInfo begin_info{};
4113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4114 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4115
4116 VkViewport viewport{};
4117 viewport.maxDepth = 1.0f;
4118 viewport.minDepth = 0.0f;
4119 viewport.width = 512;
4120 viewport.height = 512;
4121 viewport.x = 0;
4122 viewport.y = 0;
4123 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4124 vkEndCommandBuffer(command_buffer[1]);
4125 }
4126 {
4127 VkSubmitInfo submit_info{};
4128 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4129 submit_info.commandBufferCount = 1;
4130 submit_info.pCommandBuffers = &command_buffer[0];
4131 submit_info.signalSemaphoreCount = 1;
4132 submit_info.pSignalSemaphores = &semaphore;
4133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4134 }
4135 {
4136 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4137 VkSubmitInfo submit_info{};
4138 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4139 submit_info.commandBufferCount = 1;
4140 submit_info.pCommandBuffers = &command_buffer[1];
4141 submit_info.waitSemaphoreCount = 1;
4142 submit_info.pWaitSemaphores = &semaphore;
4143 submit_info.pWaitDstStageMask = flags;
4144 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4145 }
4146
4147 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4148
4149 vkDestroyFence(m_device->device(), fence, nullptr);
4150 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4151 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4152 &command_buffer[0]);
4153 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4154
4155 m_errorMonitor->VerifyNotFound();
4156}
4157
4158// This is a positive test. No errors should be generated.
4159TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4160
4161 TEST_DESCRIPTION(
4162 "Two command buffers, each in a separate QueueSubmit call "
4163 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4164 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4165
4166 m_errorMonitor->ExpectSuccess();
4167
4168 VkFence fence;
4169 VkFenceCreateInfo fence_create_info{};
4170 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4171 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4172
4173 VkCommandPool command_pool;
4174 VkCommandPoolCreateInfo pool_create_info{};
4175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4179 &command_pool);
4180
4181 VkCommandBuffer command_buffer[2];
4182 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4183 command_buffer_allocate_info.sType =
4184 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4185 command_buffer_allocate_info.commandPool = command_pool;
4186 command_buffer_allocate_info.commandBufferCount = 2;
4187 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4188 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4189 command_buffer);
4190
4191 {
4192 VkCommandBufferBeginInfo begin_info{};
4193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4194 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4195
4196 vkCmdPipelineBarrier(command_buffer[0],
4197 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4198 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4199 0, nullptr, 0, nullptr);
4200
4201 VkViewport viewport{};
4202 viewport.maxDepth = 1.0f;
4203 viewport.minDepth = 0.0f;
4204 viewport.width = 512;
4205 viewport.height = 512;
4206 viewport.x = 0;
4207 viewport.y = 0;
4208 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4209 vkEndCommandBuffer(command_buffer[0]);
4210 }
4211 {
4212 VkCommandBufferBeginInfo begin_info{};
4213 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4214 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4215
4216 VkViewport viewport{};
4217 viewport.maxDepth = 1.0f;
4218 viewport.minDepth = 0.0f;
4219 viewport.width = 512;
4220 viewport.height = 512;
4221 viewport.x = 0;
4222 viewport.y = 0;
4223 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4224 vkEndCommandBuffer(command_buffer[1]);
4225 }
4226 {
4227 VkSubmitInfo submit_info{};
4228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4229 submit_info.commandBufferCount = 1;
4230 submit_info.pCommandBuffers = &command_buffer[0];
4231 submit_info.signalSemaphoreCount = 0;
4232 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4234 }
4235 {
4236 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4237 VkSubmitInfo submit_info{};
4238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4239 submit_info.commandBufferCount = 1;
4240 submit_info.pCommandBuffers = &command_buffer[1];
4241 submit_info.waitSemaphoreCount = 0;
4242 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4243 submit_info.pWaitDstStageMask = flags;
4244 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4245 }
4246
4247 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4248
4249 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4250
4251 vkDestroyFence(m_device->device(), fence, nullptr);
4252 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4253 &command_buffer[0]);
4254 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4255
4256 m_errorMonitor->VerifyNotFound();
4257}
4258
4259// This is a positive test. No errors should be generated.
4260TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4261
4262 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4263 "on the same queue, the second having a fence, followed "
4264 "by a WaitForFences call.");
4265
4266 m_errorMonitor->ExpectSuccess();
4267
4268 VkFence fence;
4269 VkFenceCreateInfo fence_create_info{};
4270 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4271 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4272
4273 VkCommandPool command_pool;
4274 VkCommandPoolCreateInfo pool_create_info{};
4275 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4276 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4277 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4278 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4279 &command_pool);
4280
4281 VkCommandBuffer command_buffer[2];
4282 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4283 command_buffer_allocate_info.sType =
4284 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4285 command_buffer_allocate_info.commandPool = command_pool;
4286 command_buffer_allocate_info.commandBufferCount = 2;
4287 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4288 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4289 command_buffer);
4290
4291 {
4292 VkCommandBufferBeginInfo begin_info{};
4293 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4294 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4295
4296 vkCmdPipelineBarrier(command_buffer[0],
4297 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4298 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4299 0, nullptr, 0, nullptr);
4300
4301 VkViewport viewport{};
4302 viewport.maxDepth = 1.0f;
4303 viewport.minDepth = 0.0f;
4304 viewport.width = 512;
4305 viewport.height = 512;
4306 viewport.x = 0;
4307 viewport.y = 0;
4308 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4309 vkEndCommandBuffer(command_buffer[0]);
4310 }
4311 {
4312 VkCommandBufferBeginInfo begin_info{};
4313 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4314 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4315
4316 VkViewport viewport{};
4317 viewport.maxDepth = 1.0f;
4318 viewport.minDepth = 0.0f;
4319 viewport.width = 512;
4320 viewport.height = 512;
4321 viewport.x = 0;
4322 viewport.y = 0;
4323 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4324 vkEndCommandBuffer(command_buffer[1]);
4325 }
4326 {
4327 VkSubmitInfo submit_info{};
4328 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4329 submit_info.commandBufferCount = 1;
4330 submit_info.pCommandBuffers = &command_buffer[0];
4331 submit_info.signalSemaphoreCount = 0;
4332 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4333 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4334 }
4335 {
4336 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4337 VkSubmitInfo submit_info{};
4338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4339 submit_info.commandBufferCount = 1;
4340 submit_info.pCommandBuffers = &command_buffer[1];
4341 submit_info.waitSemaphoreCount = 0;
4342 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4343 submit_info.pWaitDstStageMask = flags;
4344 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4345 }
4346
4347 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4348
4349 vkDestroyFence(m_device->device(), fence, nullptr);
4350 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4351 &command_buffer[0]);
4352 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4353
4354 m_errorMonitor->VerifyNotFound();
4355}
4356
4357// This is a positive test. No errors should be generated.
4358TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4359
4360 TEST_DESCRIPTION(
4361 "Two command buffers each in a separate SubmitInfo sent in a single "
4362 "QueueSubmit call followed by a WaitForFences call.");
4363
4364 m_errorMonitor->ExpectSuccess();
4365
4366 VkFence fence;
4367 VkFenceCreateInfo fence_create_info{};
4368 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4369 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4370
4371 VkSemaphore semaphore;
4372 VkSemaphoreCreateInfo semaphore_create_info{};
4373 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4374 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4375 &semaphore);
4376
4377 VkCommandPool command_pool;
4378 VkCommandPoolCreateInfo pool_create_info{};
4379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4382 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4383 &command_pool);
4384
4385 VkCommandBuffer command_buffer[2];
4386 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4387 command_buffer_allocate_info.sType =
4388 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4389 command_buffer_allocate_info.commandPool = command_pool;
4390 command_buffer_allocate_info.commandBufferCount = 2;
4391 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4392 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4393 command_buffer);
4394
4395 {
4396 VkCommandBufferBeginInfo begin_info{};
4397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4398 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4399
4400 vkCmdPipelineBarrier(command_buffer[0],
4401 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4402 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4403 0, nullptr, 0, nullptr);
4404
4405 VkViewport viewport{};
4406 viewport.maxDepth = 1.0f;
4407 viewport.minDepth = 0.0f;
4408 viewport.width = 512;
4409 viewport.height = 512;
4410 viewport.x = 0;
4411 viewport.y = 0;
4412 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4413 vkEndCommandBuffer(command_buffer[0]);
4414 }
4415 {
4416 VkCommandBufferBeginInfo begin_info{};
4417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4418 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4419
4420 VkViewport viewport{};
4421 viewport.maxDepth = 1.0f;
4422 viewport.minDepth = 0.0f;
4423 viewport.width = 512;
4424 viewport.height = 512;
4425 viewport.x = 0;
4426 viewport.y = 0;
4427 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4428 vkEndCommandBuffer(command_buffer[1]);
4429 }
4430 {
4431 VkSubmitInfo submit_info[2];
4432 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4433
4434 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4435 submit_info[0].pNext = NULL;
4436 submit_info[0].commandBufferCount = 1;
4437 submit_info[0].pCommandBuffers = &command_buffer[0];
4438 submit_info[0].signalSemaphoreCount = 1;
4439 submit_info[0].pSignalSemaphores = &semaphore;
4440 submit_info[0].waitSemaphoreCount = 0;
4441 submit_info[0].pWaitSemaphores = NULL;
4442 submit_info[0].pWaitDstStageMask = 0;
4443
4444 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4445 submit_info[1].pNext = NULL;
4446 submit_info[1].commandBufferCount = 1;
4447 submit_info[1].pCommandBuffers = &command_buffer[1];
4448 submit_info[1].waitSemaphoreCount = 1;
4449 submit_info[1].pWaitSemaphores = &semaphore;
4450 submit_info[1].pWaitDstStageMask = flags;
4451 submit_info[1].signalSemaphoreCount = 0;
4452 submit_info[1].pSignalSemaphores = NULL;
4453 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4454 }
4455
4456 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4457
4458 vkDestroyFence(m_device->device(), fence, nullptr);
4459 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4460 &command_buffer[0]);
4461 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004462 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004463
4464 m_errorMonitor->VerifyNotFound();
4465}
4466
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004467TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004468 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004469 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4470 "state is required but not correctly bound.");
4471
4472 // Dynamic depth bias
4473 m_errorMonitor->SetDesiredFailureMsg(
4474 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4475 "Dynamic depth bias state not set for this command buffer");
4476 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4477 BsoFailDepthBias);
4478 m_errorMonitor->VerifyFound();
4479}
4480
4481TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4482 TEST_DESCRIPTION(
4483 "Run a simple draw calls to validate failure when Line Width dynamic "
4484 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004485
4486 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004487 m_errorMonitor->SetDesiredFailureMsg(
4488 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004489 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004490 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4491 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004492 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004493}
4494
4495TEST_F(VkLayerTest, DynamicViewportNotBound) {
4496 TEST_DESCRIPTION(
4497 "Run a simple draw calls to validate failure when Viewport dynamic "
4498 "state is required but not correctly bound.");
4499
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004500 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004501 m_errorMonitor->SetDesiredFailureMsg(
4502 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004503 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004504 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4505 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004506 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004507}
4508
4509TEST_F(VkLayerTest, DynamicScissorNotBound) {
4510 TEST_DESCRIPTION(
4511 "Run a simple draw calls to validate failure when Scissor dynamic "
4512 "state is required but not correctly bound.");
4513
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004514 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004515 m_errorMonitor->SetDesiredFailureMsg(
4516 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004517 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004518 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4519 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004520 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004521}
4522
Tobin Ehlis21c88352016-05-26 06:15:45 -06004523TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004524 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004525 "Run a simple draw calls to validate failure when Blend Constants "
4526 "dynamic state is required but not correctly bound.");
4527 // Dynamic blend constant state
4528 m_errorMonitor->SetDesiredFailureMsg(
4529 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4530 "Dynamic blend constants state not set for this command buffer");
4531 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4532 BsoFailBlend);
4533 m_errorMonitor->VerifyFound();
4534}
4535
4536TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4537 TEST_DESCRIPTION(
4538 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004539 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004540 if (!m_device->phy().features().depthBounds) {
4541 printf("Device does not support depthBounds test; skipped.\n");
4542 return;
4543 }
4544 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004545 m_errorMonitor->SetDesiredFailureMsg(
4546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004547 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004548 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4549 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004551}
4552
4553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4554 TEST_DESCRIPTION(
4555 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4556 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004557 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004558 m_errorMonitor->SetDesiredFailureMsg(
4559 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004560 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4562 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004563 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004564}
4565
4566TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4567 TEST_DESCRIPTION(
4568 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4569 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004570 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004571 m_errorMonitor->SetDesiredFailureMsg(
4572 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004573 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004574 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4575 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004576 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004577}
4578
4579TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4580 TEST_DESCRIPTION(
4581 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4582 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004583 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004584 m_errorMonitor->SetDesiredFailureMsg(
4585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004586 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004587 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4588 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004589 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004590}
4591
Karl Schultz6addd812016-02-02 17:17:23 -07004592TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004593 m_errorMonitor->SetDesiredFailureMsg(
4594 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4595 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4596 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004597
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004598 ASSERT_NO_FATAL_FAILURE(InitState());
4599 ASSERT_NO_FATAL_FAILURE(InitViewport());
4600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4601
Karl Schultz6addd812016-02-02 17:17:23 -07004602 // We luck out b/c by default the framework creates CB w/ the
4603 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004604 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004605 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4606 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004607 EndCommandBuffer();
4608
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004609 // Bypass framework since it does the waits automatically
4610 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004611 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4613 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004614 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004615 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004616 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004617 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004618 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004619 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004620 submit_info.pSignalSemaphores = NULL;
4621
Chris Forbes40028e22016-06-13 09:59:34 +12004622 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004623 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004624
Karl Schultz6addd812016-02-02 17:17:23 -07004625 // Cause validation error by re-submitting cmd buffer that should only be
4626 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004628
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004629 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004630}
4631
Karl Schultz6addd812016-02-02 17:17:23 -07004632TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004633 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004634 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004635
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004637 "Unable to allocate 1 descriptors of "
4638 "type "
4639 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004640
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004641 ASSERT_NO_FATAL_FAILURE(InitState());
4642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004643
Karl Schultz6addd812016-02-02 17:17:23 -07004644 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4645 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004646 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004647 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4648 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004649
4650 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004651 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4652 ds_pool_ci.pNext = NULL;
4653 ds_pool_ci.flags = 0;
4654 ds_pool_ci.maxSets = 1;
4655 ds_pool_ci.poolSizeCount = 1;
4656 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004657
4658 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004659 err =
4660 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004661 ASSERT_VK_SUCCESS(err);
4662
4663 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004664 dsl_binding.binding = 0;
4665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4666 dsl_binding.descriptorCount = 1;
4667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4668 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004669
4670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4672 ds_layout_ci.pNext = NULL;
4673 ds_layout_ci.bindingCount = 1;
4674 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004675
4676 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4678 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004679 ASSERT_VK_SUCCESS(err);
4680
4681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004682 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004684 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004685 alloc_info.descriptorPool = ds_pool;
4686 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4688 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004690 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004691
Chia-I Wuf7458c52015-10-26 21:10:41 +08004692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4693 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004694}
4695
Karl Schultz6addd812016-02-02 17:17:23 -07004696TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4697 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004698
Karl Schultz6addd812016-02-02 17:17:23 -07004699 m_errorMonitor->SetDesiredFailureMsg(
4700 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4701 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4702 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004703
Tobin Ehlise735c692015-10-08 13:13:50 -06004704 ASSERT_NO_FATAL_FAILURE(InitState());
4705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004706
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004707 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004708 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4709 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004710
4711 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004712 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4713 ds_pool_ci.pNext = NULL;
4714 ds_pool_ci.maxSets = 1;
4715 ds_pool_ci.poolSizeCount = 1;
4716 ds_pool_ci.flags = 0;
4717 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4718 // app can only call vkResetDescriptorPool on this pool.;
4719 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004720
4721 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004722 err =
4723 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004724 ASSERT_VK_SUCCESS(err);
4725
4726 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004727 dsl_binding.binding = 0;
4728 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4729 dsl_binding.descriptorCount = 1;
4730 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4731 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004732
4733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4735 ds_layout_ci.pNext = NULL;
4736 ds_layout_ci.bindingCount = 1;
4737 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004738
4739 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004740 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4741 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004742 ASSERT_VK_SUCCESS(err);
4743
4744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004748 alloc_info.descriptorPool = ds_pool;
4749 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4751 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004752 ASSERT_VK_SUCCESS(err);
4753
4754 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004755 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004756
Chia-I Wuf7458c52015-10-26 21:10:41 +08004757 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4758 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004759}
4760
Karl Schultz6addd812016-02-02 17:17:23 -07004761TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004762 // Attempt to clear Descriptor Pool with bad object.
4763 // ObjectTracker should catch this.
4764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4765 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004766 uint64_t fake_pool_handle = 0xbaad6001;
4767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004770}
4771
Karl Schultz6addd812016-02-02 17:17:23 -07004772TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004777
4778 uint64_t fake_set_handle = 0xbaad6001;
4779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004780 VkResult err;
4781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4782 "Invalid VkDescriptorSet Object 0xbaad6001");
4783
4784 ASSERT_NO_FATAL_FAILURE(InitState());
4785
4786 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4787 layout_bindings[0].binding = 0;
4788 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4789 layout_bindings[0].descriptorCount = 1;
4790 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4791 layout_bindings[0].pImmutableSamplers = NULL;
4792
4793 VkDescriptorSetLayout descriptor_set_layout;
4794 VkDescriptorSetLayoutCreateInfo dslci = {};
4795 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4796 dslci.pNext = NULL;
4797 dslci.bindingCount = 1;
4798 dslci.pBindings = layout_bindings;
4799 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004800 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004801
4802 VkPipelineLayout pipeline_layout;
4803 VkPipelineLayoutCreateInfo plci = {};
4804 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4805 plci.pNext = NULL;
4806 plci.setLayoutCount = 1;
4807 plci.pSetLayouts = &descriptor_set_layout;
4808 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004809 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004810
4811 BeginCommandBuffer();
4812 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004813 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004814 m_errorMonitor->VerifyFound();
4815 EndCommandBuffer();
4816 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4817 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004818}
4819
Karl Schultz6addd812016-02-02 17:17:23 -07004820TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004821 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4822 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004823 uint64_t fake_layout_handle = 0xbaad6001;
4824 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4826 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4827
4828 VkPipelineLayout pipeline_layout;
4829 VkPipelineLayoutCreateInfo plci = {};
4830 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4831 plci.pNext = NULL;
4832 plci.setLayoutCount = 1;
4833 plci.pSetLayouts = &bad_layout;
4834 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4835
4836 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004837}
4838
Mark Muellerd4914412016-06-13 17:52:06 -06004839TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4840 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4841 "1) A uniform buffer update must have a valid buffer index."
4842 "2) When using an array of descriptors in a single WriteDescriptor,"
4843 " the descriptor types and stageflags must all be the same."
4844 "3) Immutable Sampler state must match across descriptors");
4845
4846 const char *invalid_BufferInfo_ErrorMessage =
4847 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4848 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4849 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4850 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004851 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004852 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004853 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004854
Mark Muellerd4914412016-06-13 17:52:06 -06004855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4856
4857 ASSERT_NO_FATAL_FAILURE(InitState());
4858 VkDescriptorPoolSize ds_type_count[4] = {};
4859 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4860 ds_type_count[0].descriptorCount = 1;
4861 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4862 ds_type_count[1].descriptorCount = 1;
4863 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4864 ds_type_count[2].descriptorCount = 1;
4865 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4866 ds_type_count[3].descriptorCount = 1;
4867
4868 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4869 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4870 ds_pool_ci.maxSets = 1;
4871 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4872 ds_pool_ci.pPoolSizes = ds_type_count;
4873
4874 VkDescriptorPool ds_pool;
4875 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4876 ASSERT_VK_SUCCESS(err);
4877
Mark Muellerb9896722016-06-16 09:54:29 -06004878 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004879 layout_binding[0].binding = 0;
4880 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4881 layout_binding[0].descriptorCount = 1;
4882 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4883 layout_binding[0].pImmutableSamplers = NULL;
4884
4885 layout_binding[1].binding = 1;
4886 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4887 layout_binding[1].descriptorCount = 1;
4888 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4889 layout_binding[1].pImmutableSamplers = NULL;
4890
4891 VkSamplerCreateInfo sampler_ci = {};
4892 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4893 sampler_ci.pNext = NULL;
4894 sampler_ci.magFilter = VK_FILTER_NEAREST;
4895 sampler_ci.minFilter = VK_FILTER_NEAREST;
4896 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4897 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4898 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4899 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4900 sampler_ci.mipLodBias = 1.0;
4901 sampler_ci.anisotropyEnable = VK_FALSE;
4902 sampler_ci.maxAnisotropy = 1;
4903 sampler_ci.compareEnable = VK_FALSE;
4904 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4905 sampler_ci.minLod = 1.0;
4906 sampler_ci.maxLod = 1.0;
4907 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4908 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4909 VkSampler sampler;
4910
4911 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4912 ASSERT_VK_SUCCESS(err);
4913
4914 layout_binding[2].binding = 2;
4915 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4916 layout_binding[2].descriptorCount = 1;
4917 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4918 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4919
Mark Muellerd4914412016-06-13 17:52:06 -06004920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4922 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4923 ds_layout_ci.pBindings = layout_binding;
4924 VkDescriptorSetLayout ds_layout;
4925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4926 ASSERT_VK_SUCCESS(err);
4927
4928 VkDescriptorSetAllocateInfo alloc_info = {};
4929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4930 alloc_info.descriptorSetCount = 1;
4931 alloc_info.descriptorPool = ds_pool;
4932 alloc_info.pSetLayouts = &ds_layout;
4933 VkDescriptorSet descriptorSet;
4934 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4935 ASSERT_VK_SUCCESS(err);
4936
4937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4939 pipeline_layout_ci.pNext = NULL;
4940 pipeline_layout_ci.setLayoutCount = 1;
4941 pipeline_layout_ci.pSetLayouts = &ds_layout;
4942
4943 VkPipelineLayout pipeline_layout;
4944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4945 ASSERT_VK_SUCCESS(err);
4946
Mark Mueller5c838ce2016-06-16 09:54:29 -06004947 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4949 descriptor_write.dstSet = descriptorSet;
4950 descriptor_write.dstBinding = 0;
4951 descriptor_write.descriptorCount = 1;
4952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4953
Mark Mueller5c838ce2016-06-16 09:54:29 -06004954 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004955 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4956 m_errorMonitor->VerifyFound();
4957
4958 // Create a buffer to update the descriptor with
4959 uint32_t qfi = 0;
4960 VkBufferCreateInfo buffCI = {};
4961 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4962 buffCI.size = 1024;
4963 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4964 buffCI.queueFamilyIndexCount = 1;
4965 buffCI.pQueueFamilyIndices = &qfi;
4966
4967 VkBuffer dyub;
4968 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4969 ASSERT_VK_SUCCESS(err);
4970 VkDescriptorBufferInfo buffInfo = {};
4971 buffInfo.buffer = dyub;
4972 buffInfo.offset = 0;
4973 buffInfo.range = 1024;
4974
4975 descriptor_write.pBufferInfo = &buffInfo;
4976 descriptor_write.descriptorCount = 2;
4977
Mark Mueller5c838ce2016-06-16 09:54:29 -06004978 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4980 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4981 m_errorMonitor->VerifyFound();
4982
Mark Mueller5c838ce2016-06-16 09:54:29 -06004983 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4984 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004985 descriptor_write.dstBinding = 1;
4986 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004987
4988
4989 // Make pImageInfo index non-null to avoid complaints of it missing
4990 VkDescriptorImageInfo imageInfo = {};
4991 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4992 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4994 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4995 m_errorMonitor->VerifyFound();
4996
Mark Muellerd4914412016-06-13 17:52:06 -06004997 vkDestroyBuffer(m_device->device(), dyub, NULL);
4998 vkDestroySampler(m_device->device(), sampler, NULL);
4999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5002}
5003
Karl Schultz6addd812016-02-02 17:17:23 -07005004TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005005 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5006 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005007 // Create a valid cmd buffer
5008 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005009 uint64_t fake_pipeline_handle = 0xbaad6001;
5010 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5012 "Invalid VkPipeline Object 0xbaad6001");
5013 ASSERT_NO_FATAL_FAILURE(InitState());
5014 BeginCommandBuffer();
5015 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5016 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
5017 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005018 // Now issue a draw call with no pipeline bound
5019 m_errorMonitor->SetDesiredFailureMsg(
5020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5021 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06005022
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005023 BeginCommandBuffer();
5024 Draw(1, 0, 0, 0);
5025 m_errorMonitor->VerifyFound();
5026 // Finally same check once more but with Dispatch/Compute
5027 m_errorMonitor->SetDesiredFailureMsg(
5028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5029 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005030 BeginCommandBuffer();
5031 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5032 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005033}
5034
Karl Schultz6addd812016-02-02 17:17:23 -07005035TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
5036 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
5037 // CommandBuffer
5038 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005039
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005041 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005042
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005043 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005044 ASSERT_NO_FATAL_FAILURE(InitViewport());
5045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5048 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005049
5050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5052 ds_pool_ci.pNext = NULL;
5053 ds_pool_ci.maxSets = 1;
5054 ds_pool_ci.poolSizeCount = 1;
5055 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005056
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005057 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005058 err =
5059 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005060 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005061
Tony Barboureb254902015-07-15 12:50:33 -06005062 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005063 dsl_binding.binding = 0;
5064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5065 dsl_binding.descriptorCount = 1;
5066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5067 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005068
Tony Barboureb254902015-07-15 12:50:33 -06005069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5071 ds_layout_ci.pNext = NULL;
5072 ds_layout_ci.bindingCount = 1;
5073 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005074 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5076 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005080 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005082 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5086 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005087 ASSERT_VK_SUCCESS(err);
5088
Tony Barboureb254902015-07-15 12:50:33 -06005089 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005090 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5091 pipeline_layout_ci.pNext = NULL;
5092 pipeline_layout_ci.setLayoutCount = 1;
5093 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005094
5095 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005096 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5097 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005098 ASSERT_VK_SUCCESS(err);
5099
Karl Schultz6addd812016-02-02 17:17:23 -07005100 VkShaderObj vs(m_device, bindStateVertShaderText,
5101 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005102 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005103 // on more devices
5104 VkShaderObj fs(m_device, bindStateFragShaderText,
5105 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005106
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005107 VkPipelineObj pipe(m_device);
5108 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005109 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005110 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005111 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005112
5113 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005114 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5115 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5116 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5117 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5118 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005119
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005120 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005121
Chia-I Wuf7458c52015-10-26 21:10:41 +08005122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005125}
5126
Karl Schultz6addd812016-02-02 17:17:23 -07005127TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005128 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005129 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005130
Karl Schultz6addd812016-02-02 17:17:23 -07005131 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005132 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5133 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005134
5135 ASSERT_NO_FATAL_FAILURE(InitState());
5136 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005137 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5138 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005139
5140 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005141 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5142 ds_pool_ci.pNext = NULL;
5143 ds_pool_ci.maxSets = 1;
5144 ds_pool_ci.poolSizeCount = 1;
5145 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005146
5147 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005148 err =
5149 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005150 ASSERT_VK_SUCCESS(err);
5151
5152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005153 dsl_binding.binding = 0;
5154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5155 dsl_binding.descriptorCount = 1;
5156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5157 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005158
5159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5161 ds_layout_ci.pNext = NULL;
5162 ds_layout_ci.bindingCount = 1;
5163 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005164 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5166 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005167 ASSERT_VK_SUCCESS(err);
5168
5169 VkDescriptorSet descriptorSet;
5170 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005172 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005173 alloc_info.descriptorPool = ds_pool;
5174 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5176 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005177 ASSERT_VK_SUCCESS(err);
5178
Karl Schultz6addd812016-02-02 17:17:23 -07005179 VkBufferView view =
5180 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005181 VkWriteDescriptorSet descriptor_write;
5182 memset(&descriptor_write, 0, sizeof(descriptor_write));
5183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5184 descriptor_write.dstSet = descriptorSet;
5185 descriptor_write.dstBinding = 0;
5186 descriptor_write.descriptorCount = 1;
5187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5188 descriptor_write.pTexelBufferView = &view;
5189
5190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005192 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005193
5194 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5196}
5197
Karl Schultz6addd812016-02-02 17:17:23 -07005198TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5199 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5200 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005201 // 1. No dynamicOffset supplied
5202 // 2. Too many dynamicOffsets supplied
5203 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005204 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005206 " requires 1 dynamicOffsets, but only "
5207 "0 dynamicOffsets are left in "
5208 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005209
5210 ASSERT_NO_FATAL_FAILURE(InitState());
5211 ASSERT_NO_FATAL_FAILURE(InitViewport());
5212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5213
5214 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5216 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005217
5218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5220 ds_pool_ci.pNext = NULL;
5221 ds_pool_ci.maxSets = 1;
5222 ds_pool_ci.poolSizeCount = 1;
5223 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005224
5225 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005226 err =
5227 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005228 ASSERT_VK_SUCCESS(err);
5229
5230 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005231 dsl_binding.binding = 0;
5232 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5233 dsl_binding.descriptorCount = 1;
5234 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5235 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005236
5237 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005238 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5239 ds_layout_ci.pNext = NULL;
5240 ds_layout_ci.bindingCount = 1;
5241 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005242 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5244 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005245 ASSERT_VK_SUCCESS(err);
5246
5247 VkDescriptorSet descriptorSet;
5248 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005249 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005250 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005251 alloc_info.descriptorPool = ds_pool;
5252 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005253 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5254 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005255 ASSERT_VK_SUCCESS(err);
5256
5257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5259 pipeline_layout_ci.pNext = NULL;
5260 pipeline_layout_ci.setLayoutCount = 1;
5261 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005262
5263 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5265 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005266 ASSERT_VK_SUCCESS(err);
5267
5268 // Create a buffer to update the descriptor with
5269 uint32_t qfi = 0;
5270 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005271 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5272 buffCI.size = 1024;
5273 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5274 buffCI.queueFamilyIndexCount = 1;
5275 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005276
5277 VkBuffer dyub;
5278 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5279 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005280 // Allocate memory and bind to buffer so we can make it to the appropriate
5281 // error
5282 VkMemoryAllocateInfo mem_alloc = {};
5283 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5284 mem_alloc.pNext = NULL;
5285 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005286 mem_alloc.memoryTypeIndex = 0;
5287
5288 VkMemoryRequirements memReqs;
5289 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5290 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5291 0);
5292 if (!pass) {
5293 vkDestroyBuffer(m_device->device(), dyub, NULL);
5294 return;
5295 }
5296
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005297 VkDeviceMemory mem;
5298 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5299 ASSERT_VK_SUCCESS(err);
5300 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5301 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005302 // Correctly update descriptor to avoid "NOT_UPDATED" error
5303 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005304 buffInfo.buffer = dyub;
5305 buffInfo.offset = 0;
5306 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005307
5308 VkWriteDescriptorSet descriptor_write;
5309 memset(&descriptor_write, 0, sizeof(descriptor_write));
5310 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5311 descriptor_write.dstSet = descriptorSet;
5312 descriptor_write.dstBinding = 0;
5313 descriptor_write.descriptorCount = 1;
5314 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5315 descriptor_write.pBufferInfo = &buffInfo;
5316
5317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5318
5319 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005320 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5321 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5322 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005323 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005324 uint32_t pDynOff[2] = {512, 756};
5325 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005326 m_errorMonitor->SetDesiredFailureMsg(
5327 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005328 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005329 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5330 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5331 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005332 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005333 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5335 " dynamic offset 512 combined with "
5336 "offset 0 and range 1024 that "
5337 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005338 // Create PSO to be used for draw-time errors below
5339 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005340 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005341 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005342 "out gl_PerVertex { \n"
5343 " vec4 gl_Position;\n"
5344 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005345 "void main(){\n"
5346 " gl_Position = vec4(1);\n"
5347 "}\n";
5348 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005349 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005350 "\n"
5351 "layout(location=0) out vec4 x;\n"
5352 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5353 "void main(){\n"
5354 " x = vec4(bar.y);\n"
5355 "}\n";
5356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5358 VkPipelineObj pipe(m_device);
5359 pipe.AddShader(&vs);
5360 pipe.AddShader(&fs);
5361 pipe.AddColorAttachment();
5362 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5363
Karl Schultz6addd812016-02-02 17:17:23 -07005364 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5365 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5366 // This update should succeed, but offset size of 512 will overstep buffer
5367 // /w range 1024 & size 1024
5368 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5369 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5370 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005371 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005372 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005373
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005374 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005375 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005376
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005379 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5380}
5381
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005382TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005383 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005384 ASSERT_NO_FATAL_FAILURE(InitState());
5385 ASSERT_NO_FATAL_FAILURE(InitViewport());
5386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5387
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005388 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005389 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5392 pipeline_layout_ci.pushConstantRangeCount = 1;
5393 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5394
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005395 //
5396 // Check for invalid push constant ranges in pipeline layouts.
5397 //
5398 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005399 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005400 char const *msg;
5401 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005402
Karl Schultzc81037d2016-05-12 08:11:23 -06005403 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5404 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5405 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5406 "vkCreatePipelineLayout() call has push constants index 0 with "
5407 "size 0."},
5408 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5409 "vkCreatePipelineLayout() call has push constants index 0 with "
5410 "size 1."},
5411 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5412 "vkCreatePipelineLayout() call has push constants index 0 with "
5413 "size 1."},
5414 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5415 "vkCreatePipelineLayout() call has push constants index 0 with "
5416 "size 0."},
5417 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5418 "vkCreatePipelineLayout() call has push constants index 0 with "
5419 "offset 1. Offset must"},
5420 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5421 "vkCreatePipelineLayout() call has push constants index 0 "
5422 "with offset "},
5423 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5424 "vkCreatePipelineLayout() call has push constants "
5425 "index 0 with offset "},
5426 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5427 "vkCreatePipelineLayout() call has push constants index 0 "
5428 "with offset "},
5429 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5430 "vkCreatePipelineLayout() call has push "
5431 "constants index 0 with offset "},
5432 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5433 "vkCreatePipelineLayout() call has push "
5434 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005435 }};
5436
5437 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005438 for (const auto &iter : range_tests) {
5439 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5441 iter.msg);
5442 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5443 NULL, &pipeline_layout);
5444 m_errorMonitor->VerifyFound();
5445 if (VK_SUCCESS == err) {
5446 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5447 }
5448 }
5449
5450 // Check for invalid stage flag
5451 pc_range.offset = 0;
5452 pc_range.size = 16;
5453 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005454 m_errorMonitor->SetDesiredFailureMsg(
5455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005456 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5458 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005459 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005460 if (VK_SUCCESS == err) {
5461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5462 }
5463
5464 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005465 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005466 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005467 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005468 char const *msg;
5469 };
5470
Karl Schultzc81037d2016-05-12 08:11:23 -06005471 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005472 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5473 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5474 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5475 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5476 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5477 "vkCreatePipelineLayout() call has push constants with overlapping "
5478 "ranges: 0:[0, 4), 1:[0, 4)"},
5479 {
5480 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5481 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5482 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5483 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5484 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5485 "vkCreatePipelineLayout() call has push constants with "
5486 "overlapping "
5487 "ranges: 3:[12, 20), 4:[16, 20)",
5488 },
5489 {
5490 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5491 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5492 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5493 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5494 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5495 "vkCreatePipelineLayout() call has push constants with "
5496 "overlapping "
5497 "ranges: 0:[16, 20), 1:[12, 20)",
5498 },
5499 {
5500 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5501 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5502 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5503 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5504 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5505 "vkCreatePipelineLayout() call has push constants with "
5506 "overlapping "
5507 "ranges: 0:[16, 20), 3:[12, 20)",
5508 },
5509 {
5510 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5511 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5512 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5513 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5514 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5515 "vkCreatePipelineLayout() call has push constants with "
5516 "overlapping "
5517 "ranges: 0:[16, 20), 2:[4, 100)",
5518 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005519
Karl Schultzc81037d2016-05-12 08:11:23 -06005520 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005521 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005522 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005524 iter.msg);
5525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5526 NULL, &pipeline_layout);
5527 m_errorMonitor->VerifyFound();
5528 if (VK_SUCCESS == err) {
5529 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5530 }
5531 }
5532
5533 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005534 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5535 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5536 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5537 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5538 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5539 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5540 ""},
5541 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5542 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5543 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5544 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5545 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5546 ""}}};
5547 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005548 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5549 m_errorMonitor->ExpectSuccess();
5550 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5551 NULL, &pipeline_layout);
5552 m_errorMonitor->VerifyNotFound();
5553 if (VK_SUCCESS == err) {
5554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5555 }
5556 }
5557
5558 //
5559 // CmdPushConstants tests
5560 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005561 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005562
5563 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005564 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5565 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5566 "vkCmdPushConstants() call has push constants with size 0. Size "
5567 "must be greater than zero and a multiple of 4."},
5568 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5569 "vkCmdPushConstants() call has push constants with size 1. Size "
5570 "must be greater than zero and a multiple of 4."},
5571 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5572 "vkCmdPushConstants() call has push constants with size 1. Size "
5573 "must be greater than zero and a multiple of 4."},
5574 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5575 "vkCmdPushConstants() call has push constants with offset 1. "
5576 "Offset must be a multiple of 4."},
5577 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5578 "vkCmdPushConstants() call has push constants with offset 1. "
5579 "Offset must be a multiple of 4."},
5580 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5581 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5582 "0x1 not within flag-matching ranges in pipeline layout"},
5583 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5584 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5585 "0x1 not within flag-matching ranges in pipeline layout"},
5586 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5587 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5588 "0x1 not within flag-matching ranges in pipeline layout"},
5589 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5590 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5591 "0x1 not within flag-matching ranges in pipeline layout"},
5592 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5593 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5594 "any of the ranges in pipeline layout"},
5595 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5596 0, 16},
5597 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5598 "any of the ranges in pipeline layout"},
5599 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005600 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005601 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005602 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005603 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005604 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005605 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005606 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005607 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005608 "vkCmdPushConstants() call has push constants with offset "},
5609 }};
5610
5611 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005612 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005613 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005614 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005615 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005616 pipeline_layout_ci.pushConstantRangeCount =
5617 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005618 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5620 &pipeline_layout);
5621 ASSERT_VK_SUCCESS(err);
5622 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005623 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5625 iter.msg);
5626 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005627 iter.range.stageFlags, iter.range.offset,
5628 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005629 m_errorMonitor->VerifyFound();
5630 }
5631
5632 // Check for invalid stage flag
5633 m_errorMonitor->SetDesiredFailureMsg(
5634 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5635 "vkCmdPushConstants() call has no stageFlags set.");
5636 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005637 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005638 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005639 EndCommandBuffer();
5640 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5641 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005642
Karl Schultzc81037d2016-05-12 08:11:23 -06005643 // overlapping range tests with cmd
5644 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5645 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5646 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5647 "0x1 not within flag-matching ranges in pipeline layout"},
5648 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5649 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5650 "0x1 not within flag-matching ranges in pipeline layout"},
5651 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5652 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5653 "0x1 not within flag-matching ranges in pipeline layout"},
5654 }};
5655 const VkPushConstantRange pc_range3[] = {
5656 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5657 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5658 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5659 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5660 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5661 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5662 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5663 };
5664 pipeline_layout_ci.pushConstantRangeCount =
5665 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5666 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5667 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5668 &pipeline_layout);
5669 ASSERT_VK_SUCCESS(err);
5670 BeginCommandBuffer();
5671 for (const auto &iter : cmd_overlap_tests) {
5672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5673 iter.msg);
5674 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5675 iter.range.stageFlags, iter.range.offset,
5676 iter.range.size, dummy_values);
5677 m_errorMonitor->VerifyFound();
5678 }
5679 EndCommandBuffer();
5680 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5682
5683 // positive overlapping range tests with cmd
5684 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5685 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5686 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5687 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5688 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5689 }};
5690 const VkPushConstantRange pc_range4[] = {
5691 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5692 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5693 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5694 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5695 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5696 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5697 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5698 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5699 };
5700 pipeline_layout_ci.pushConstantRangeCount =
5701 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5702 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5703 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5704 &pipeline_layout);
5705 ASSERT_VK_SUCCESS(err);
5706 BeginCommandBuffer();
5707 for (const auto &iter : cmd_overlap_tests_pos) {
5708 m_errorMonitor->ExpectSuccess();
5709 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5710 iter.range.stageFlags, iter.range.offset,
5711 iter.range.size, dummy_values);
5712 m_errorMonitor->VerifyNotFound();
5713 }
5714 EndCommandBuffer();
5715 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5717}
5718
Karl Schultz6addd812016-02-02 17:17:23 -07005719TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005720 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005721 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005722
5723 ASSERT_NO_FATAL_FAILURE(InitState());
5724 ASSERT_NO_FATAL_FAILURE(InitViewport());
5725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5726
5727 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5728 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005729 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5730 ds_type_count[0].descriptorCount = 10;
5731 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5732 ds_type_count[1].descriptorCount = 2;
5733 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5734 ds_type_count[2].descriptorCount = 2;
5735 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5736 ds_type_count[3].descriptorCount = 5;
5737 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5738 // type
5739 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5740 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5741 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005742
5743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5745 ds_pool_ci.pNext = NULL;
5746 ds_pool_ci.maxSets = 5;
5747 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5748 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005749
5750 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005751 err =
5752 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005753 ASSERT_VK_SUCCESS(err);
5754
5755 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5756 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005757 dsl_binding[0].binding = 0;
5758 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5759 dsl_binding[0].descriptorCount = 5;
5760 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5761 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005762
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005763 // Create layout identical to set0 layout but w/ different stageFlags
5764 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005765 dsl_fs_stage_only.binding = 0;
5766 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5767 dsl_fs_stage_only.descriptorCount = 5;
5768 dsl_fs_stage_only.stageFlags =
5769 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5770 // bind time
5771 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5774 ds_layout_ci.pNext = NULL;
5775 ds_layout_ci.bindingCount = 1;
5776 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005777 static const uint32_t NUM_LAYOUTS = 4;
5778 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005779 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005780 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5781 // layout for error case
5782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5783 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005784 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005785 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5787 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005788 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005789 dsl_binding[0].binding = 0;
5790 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005791 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005792 dsl_binding[1].binding = 1;
5793 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5794 dsl_binding[1].descriptorCount = 2;
5795 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5796 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005797 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005798 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005799 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5800 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005801 ASSERT_VK_SUCCESS(err);
5802 dsl_binding[0].binding = 0;
5803 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005804 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005805 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5807 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005808 ASSERT_VK_SUCCESS(err);
5809 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005810 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5812 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005813 ASSERT_VK_SUCCESS(err);
5814
5815 static const uint32_t NUM_SETS = 4;
5816 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5817 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005819 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005820 alloc_info.descriptorPool = ds_pool;
5821 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5823 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005824 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005825 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005826 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005827 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005828 err =
5829 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005830 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005831
5832 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5834 pipeline_layout_ci.pNext = NULL;
5835 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5836 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005837
5838 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005839 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5840 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005841 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005842 // Create pipelineLayout with only one setLayout
5843 pipeline_layout_ci.setLayoutCount = 1;
5844 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5846 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005847 ASSERT_VK_SUCCESS(err);
5848 // Create pipelineLayout with 2 descriptor setLayout at index 0
5849 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5850 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005851 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5852 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005853 ASSERT_VK_SUCCESS(err);
5854 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5855 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5856 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005857 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5858 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005859 ASSERT_VK_SUCCESS(err);
5860 // Create pipelineLayout with UB type, but stageFlags for FS only
5861 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5862 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5864 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005865 ASSERT_VK_SUCCESS(err);
5866 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5867 VkDescriptorSetLayout pl_bad_s0[2] = {};
5868 pl_bad_s0[0] = ds_layout_fs_only;
5869 pl_bad_s0[1] = ds_layout[1];
5870 pipeline_layout_ci.setLayoutCount = 2;
5871 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5872 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005873 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5874 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005875 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005876
5877 // Create a buffer to update the descriptor with
5878 uint32_t qfi = 0;
5879 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005880 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5881 buffCI.size = 1024;
5882 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5883 buffCI.queueFamilyIndexCount = 1;
5884 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005885
5886 VkBuffer dyub;
5887 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5888 ASSERT_VK_SUCCESS(err);
5889 // Correctly update descriptor to avoid "NOT_UPDATED" error
5890 static const uint32_t NUM_BUFFS = 5;
5891 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005892 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005893 buffInfo[i].buffer = dyub;
5894 buffInfo[i].offset = 0;
5895 buffInfo[i].range = 1024;
5896 }
Karl Schultz6addd812016-02-02 17:17:23 -07005897 VkImage image;
5898 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5899 const int32_t tex_width = 32;
5900 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005901 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5903 image_create_info.pNext = NULL;
5904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5905 image_create_info.format = tex_format;
5906 image_create_info.extent.width = tex_width;
5907 image_create_info.extent.height = tex_height;
5908 image_create_info.extent.depth = 1;
5909 image_create_info.mipLevels = 1;
5910 image_create_info.arrayLayers = 1;
5911 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5912 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5913 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5914 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005915 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5916 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005917
Karl Schultz6addd812016-02-02 17:17:23 -07005918 VkMemoryRequirements memReqs;
5919 VkDeviceMemory imageMem;
5920 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005921 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005922 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5923 memAlloc.pNext = NULL;
5924 memAlloc.allocationSize = 0;
5925 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005926 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5927 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005928 pass =
5929 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005930 ASSERT_TRUE(pass);
5931 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5932 ASSERT_VK_SUCCESS(err);
5933 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5934 ASSERT_VK_SUCCESS(err);
5935
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005936 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005937 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5938 image_view_create_info.image = image;
5939 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5940 image_view_create_info.format = tex_format;
5941 image_view_create_info.subresourceRange.layerCount = 1;
5942 image_view_create_info.subresourceRange.baseMipLevel = 0;
5943 image_view_create_info.subresourceRange.levelCount = 1;
5944 image_view_create_info.subresourceRange.aspectMask =
5945 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005946
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005947 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005948 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5949 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005950 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005951 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005952 imageInfo[0].imageView = view;
5953 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5954 imageInfo[1].imageView = view;
5955 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005956 imageInfo[2].imageView = view;
5957 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5958 imageInfo[3].imageView = view;
5959 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005960
5961 static const uint32_t NUM_SET_UPDATES = 3;
5962 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5963 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5964 descriptor_write[0].dstSet = descriptorSet[0];
5965 descriptor_write[0].dstBinding = 0;
5966 descriptor_write[0].descriptorCount = 5;
5967 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5968 descriptor_write[0].pBufferInfo = buffInfo;
5969 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5970 descriptor_write[1].dstSet = descriptorSet[1];
5971 descriptor_write[1].dstBinding = 0;
5972 descriptor_write[1].descriptorCount = 2;
5973 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5974 descriptor_write[1].pImageInfo = imageInfo;
5975 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5976 descriptor_write[2].dstSet = descriptorSet[1];
5977 descriptor_write[2].dstBinding = 1;
5978 descriptor_write[2].descriptorCount = 2;
5979 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005980 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005981
5982 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005983
Tobin Ehlis88452832015-12-03 09:40:56 -07005984 // Create PSO to be used for draw-time errors below
5985 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005986 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005987 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005988 "out gl_PerVertex {\n"
5989 " vec4 gl_Position;\n"
5990 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005991 "void main(){\n"
5992 " gl_Position = vec4(1);\n"
5993 "}\n";
5994 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005995 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005996 "\n"
5997 "layout(location=0) out vec4 x;\n"
5998 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5999 "void main(){\n"
6000 " x = vec4(bar.y);\n"
6001 "}\n";
6002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006004 VkPipelineObj pipe(m_device);
6005 pipe.AddShader(&vs);
6006 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006007 pipe.AddColorAttachment();
6008 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006009
6010 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006011
Karl Schultz6addd812016-02-02 17:17:23 -07006012 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6013 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6014 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6015 // of PSO
6016 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6017 // cmd_pipeline.c
6018 // due to the fact that cmd_alloc_dset_data() has not been called in
6019 // cmd_bind_graphics_pipeline()
6020 // TODO : Want to cause various binding incompatibility issues here to test
6021 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006022 // First cause various verify_layout_compatibility() fails
6023 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006024 // verify_set_layout_compatibility fail cases:
6025 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07006026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6027 " due to: invalid VkPipelineLayout ");
6028 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6029 VK_PIPELINE_BIND_POINT_GRAPHICS,
6030 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
6031 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006032 m_errorMonitor->VerifyFound();
6033
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006034 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07006035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6036 " attempting to bind set to index 1");
6037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6038 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
6039 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006040 m_errorMonitor->VerifyFound();
6041
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006042 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006043 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6044 // descriptors
6045 m_errorMonitor->SetDesiredFailureMsg(
6046 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006047 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006048 vkCmdBindDescriptorSets(
6049 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6050 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006051 m_errorMonitor->VerifyFound();
6052
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006053 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6054 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07006055 m_errorMonitor->SetDesiredFailureMsg(
6056 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006057 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07006058 vkCmdBindDescriptorSets(
6059 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6060 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006061 m_errorMonitor->VerifyFound();
6062
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006063 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6064 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07006065 m_errorMonitor->SetDesiredFailureMsg(
6066 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06006067 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07006068 vkCmdBindDescriptorSets(
6069 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6070 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006071 m_errorMonitor->VerifyFound();
6072
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006073 // Cause INFO messages due to disturbing previously bound Sets
6074 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006075 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6076 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6077 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006078 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006079 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006080 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006081 " previously bound as set #0 was disturbed ");
6082 vkCmdBindDescriptorSets(
6083 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6084 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006085 m_errorMonitor->VerifyFound();
6086
Karl Schultz6addd812016-02-02 17:17:23 -07006087 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6088 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6089 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006090 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006092 " newly bound as set #0 so set #1 and "
6093 "any subsequent sets were disturbed ");
6094 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6095 VK_PIPELINE_BIND_POINT_GRAPHICS,
6096 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006097 m_errorMonitor->VerifyFound();
6098
Tobin Ehlis88452832015-12-03 09:40:56 -07006099 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006100 // 1. Error due to not binding required set (we actually use same code as
6101 // above to disturb set0)
6102 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6103 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6104 2, &descriptorSet[0], 0, NULL);
6105 vkCmdBindDescriptorSets(
6106 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6107 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6108 m_errorMonitor->SetDesiredFailureMsg(
6109 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6110 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006111 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006112 m_errorMonitor->VerifyFound();
6113
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006114 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006115 // 2. Error due to bound set not being compatible with PSO's
6116 // VkPipelineLayout (diff stageFlags in this case)
6117 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6118 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6119 2, &descriptorSet[0], 0, NULL);
6120 m_errorMonitor->SetDesiredFailureMsg(
6121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6122 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006123 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006124 m_errorMonitor->VerifyFound();
6125
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006126 // Remaining clean-up
6127 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006128 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006129 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6130 }
6131 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006132 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6133 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006134 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006135 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006137 vkFreeMemory(m_device->device(), imageMem, NULL);
6138 vkDestroyImage(m_device->device(), image, NULL);
6139 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006140}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006141
Karl Schultz6addd812016-02-02 17:17:23 -07006142TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006143
Karl Schultz6addd812016-02-02 17:17:23 -07006144 m_errorMonitor->SetDesiredFailureMsg(
6145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006146 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006147
6148 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006149 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006150 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006151 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006152
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006153 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006154}
6155
Karl Schultz6addd812016-02-02 17:17:23 -07006156TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6157 VkResult err;
6158 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006159
Karl Schultz6addd812016-02-02 17:17:23 -07006160 m_errorMonitor->SetDesiredFailureMsg(
6161 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006162 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006163
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006164 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006165
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006166 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006167 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006168 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006169 cmd.commandPool = m_commandPool;
6170 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006171 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006172
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006173 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006174 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006175
6176 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006177 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006178 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006179 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006180 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006181 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6182 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006183 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006184
6185 // The error should be caught by validation of the BeginCommandBuffer call
6186 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6187
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006188 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006189 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006190}
6191
Karl Schultz6addd812016-02-02 17:17:23 -07006192TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006193 // Cause error due to Begin while recording CB
6194 // Then cause 2 errors for attempting to reset CB w/o having
6195 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6196 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006198 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006199
6200 ASSERT_NO_FATAL_FAILURE(InitState());
6201
6202 // Calls AllocateCommandBuffers
6203 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6204
Karl Schultz6addd812016-02-02 17:17:23 -07006205 // Force the failure by setting the Renderpass and Framebuffer fields with
6206 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006207 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006208 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006209 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6210 cmd_buf_info.pNext = NULL;
6211 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006212 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006213
6214 // Begin CB to transition to recording state
6215 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6216 // Can't re-begin. This should trigger error
6217 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006218 m_errorMonitor->VerifyFound();
6219
Karl Schultz6addd812016-02-02 17:17:23 -07006220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6221 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006222 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6223 // Reset attempt will trigger error due to incorrect CommandPool state
6224 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006225 m_errorMonitor->VerifyFound();
6226
Karl Schultz6addd812016-02-02 17:17:23 -07006227 m_errorMonitor->SetDesiredFailureMsg(
6228 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6229 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006230 // Transition CB to RECORDED state
6231 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6232 // Now attempting to Begin will implicitly reset, which triggers error
6233 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006234 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006235}
6236
Karl Schultz6addd812016-02-02 17:17:23 -07006237TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006238 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006239 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006240
Karl Schultz6addd812016-02-02 17:17:23 -07006241 m_errorMonitor->SetDesiredFailureMsg(
6242 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006243 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6244
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006245 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006247
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006248 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6250 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006251
6252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6254 ds_pool_ci.pNext = NULL;
6255 ds_pool_ci.maxSets = 1;
6256 ds_pool_ci.poolSizeCount = 1;
6257 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006258
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006259 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006260 err =
6261 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006262 ASSERT_VK_SUCCESS(err);
6263
Tony Barboureb254902015-07-15 12:50:33 -06006264 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006265 dsl_binding.binding = 0;
6266 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6267 dsl_binding.descriptorCount = 1;
6268 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6269 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006270
Tony Barboureb254902015-07-15 12:50:33 -06006271 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006272 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6273 ds_layout_ci.pNext = NULL;
6274 ds_layout_ci.bindingCount = 1;
6275 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006276
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006277 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006278 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6279 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006280 ASSERT_VK_SUCCESS(err);
6281
6282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006285 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006286 alloc_info.descriptorPool = ds_pool;
6287 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6289 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006290 ASSERT_VK_SUCCESS(err);
6291
Tony Barboureb254902015-07-15 12:50:33 -06006292 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006293 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6294 pipeline_layout_ci.setLayoutCount = 1;
6295 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006296
6297 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006298 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6299 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006300 ASSERT_VK_SUCCESS(err);
6301
Tobin Ehlise68360f2015-10-01 11:15:13 -06006302 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006303 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006304
6305 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006306 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6307 vp_state_ci.scissorCount = 1;
6308 vp_state_ci.pScissors = &sc;
6309 vp_state_ci.viewportCount = 1;
6310 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006311
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006312 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6313 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6314 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6315 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6316 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6317 rs_state_ci.depthClampEnable = VK_FALSE;
6318 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6319 rs_state_ci.depthBiasEnable = VK_FALSE;
6320
Tony Barboureb254902015-07-15 12:50:33 -06006321 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006322 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6323 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006324 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006325 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6326 gp_ci.layout = pipeline_layout;
6327 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006328
6329 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6331 pc_ci.initialDataSize = 0;
6332 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006333
6334 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006335 VkPipelineCache pipelineCache;
6336
Karl Schultz6addd812016-02-02 17:17:23 -07006337 err =
6338 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006339 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006340 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6341 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006342
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006343 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006344
Chia-I Wuf7458c52015-10-26 21:10:41 +08006345 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6346 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6347 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6348 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006349}
Tobin Ehlis912df022015-09-17 08:46:18 -06006350/*// TODO : This test should be good, but needs Tess support in compiler to run
6351TEST_F(VkLayerTest, InvalidPatchControlPoints)
6352{
6353 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006354 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006355
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006357 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6358primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006359
Tobin Ehlis912df022015-09-17 08:46:18 -06006360 ASSERT_NO_FATAL_FAILURE(InitState());
6361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006362
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006363 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006365 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006366
6367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6369 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006370 ds_pool_ci.poolSizeCount = 1;
6371 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006372
6373 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006374 err = vkCreateDescriptorPool(m_device->device(),
6375VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006376 ASSERT_VK_SUCCESS(err);
6377
6378 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006379 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006380 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006381 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006382 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6383 dsl_binding.pImmutableSamplers = NULL;
6384
6385 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 ds_layout_ci.sType =
6387VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006388 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006389 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006390 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006391
6392 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006393 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6394&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006395 ASSERT_VK_SUCCESS(err);
6396
6397 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006398 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6399VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006400 ASSERT_VK_SUCCESS(err);
6401
6402 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006403 pipeline_layout_ci.sType =
6404VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006405 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006406 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006407 pipeline_layout_ci.pSetLayouts = &ds_layout;
6408
6409 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006410 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6411&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006412 ASSERT_VK_SUCCESS(err);
6413
6414 VkPipelineShaderStageCreateInfo shaderStages[3];
6415 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6416
Karl Schultz6addd812016-02-02 17:17:23 -07006417 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6418this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006419 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006420 VkShaderObj
6421tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6422this);
6423 VkShaderObj
6424te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6425this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006426
Karl Schultz6addd812016-02-02 17:17:23 -07006427 shaderStages[0].sType =
6428VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006429 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006430 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006431 shaderStages[1].sType =
6432VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006433 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006434 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006435 shaderStages[2].sType =
6436VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006437 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006438 shaderStages[2].shader = te.handle();
6439
6440 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 iaCI.sType =
6442VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006443 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006444
6445 VkPipelineTessellationStateCreateInfo tsCI = {};
6446 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6447 tsCI.patchControlPoints = 0; // This will cause an error
6448
6449 VkGraphicsPipelineCreateInfo gp_ci = {};
6450 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6451 gp_ci.pNext = NULL;
6452 gp_ci.stageCount = 3;
6453 gp_ci.pStages = shaderStages;
6454 gp_ci.pVertexInputState = NULL;
6455 gp_ci.pInputAssemblyState = &iaCI;
6456 gp_ci.pTessellationState = &tsCI;
6457 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006458 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006459 gp_ci.pMultisampleState = NULL;
6460 gp_ci.pDepthStencilState = NULL;
6461 gp_ci.pColorBlendState = NULL;
6462 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6463 gp_ci.layout = pipeline_layout;
6464 gp_ci.renderPass = renderPass();
6465
6466 VkPipelineCacheCreateInfo pc_ci = {};
6467 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6468 pc_ci.pNext = NULL;
6469 pc_ci.initialSize = 0;
6470 pc_ci.initialData = 0;
6471 pc_ci.maxSize = 0;
6472
6473 VkPipeline pipeline;
6474 VkPipelineCache pipelineCache;
6475
Karl Schultz6addd812016-02-02 17:17:23 -07006476 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6477&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006478 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006479 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6480&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006481
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006482 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006483
Chia-I Wuf7458c52015-10-26 21:10:41 +08006484 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006488}
6489*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006490// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006491TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006492 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006493
Karl Schultz6addd812016-02-02 17:17:23 -07006494 m_errorMonitor->SetDesiredFailureMsg(
6495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006496 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6497
Tobin Ehlise68360f2015-10-01 11:15:13 -06006498 ASSERT_NO_FATAL_FAILURE(InitState());
6499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006500
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006501 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6503 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006504
6505 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6507 ds_pool_ci.maxSets = 1;
6508 ds_pool_ci.poolSizeCount = 1;
6509 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006510
6511 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006512 err =
6513 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006514 ASSERT_VK_SUCCESS(err);
6515
6516 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006517 dsl_binding.binding = 0;
6518 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6519 dsl_binding.descriptorCount = 1;
6520 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006521
6522 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6524 ds_layout_ci.bindingCount = 1;
6525 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006526
6527 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006528 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6529 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006530 ASSERT_VK_SUCCESS(err);
6531
6532 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006533 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006534 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006535 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006536 alloc_info.descriptorPool = ds_pool;
6537 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006538 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6539 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006540 ASSERT_VK_SUCCESS(err);
6541
6542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6544 pipeline_layout_ci.setLayoutCount = 1;
6545 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006546
6547 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006548 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6549 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006550 ASSERT_VK_SUCCESS(err);
6551
6552 VkViewport vp = {}; // Just need dummy vp to point to
6553
6554 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006555 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6556 vp_state_ci.scissorCount = 0;
6557 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6558 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006559
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006560 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6561 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6562 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6563 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6564 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6565 rs_state_ci.depthClampEnable = VK_FALSE;
6566 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6567 rs_state_ci.depthBiasEnable = VK_FALSE;
6568
Cody Northropeb3a6c12015-10-05 14:44:45 -06006569 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006570 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006571
Karl Schultz6addd812016-02-02 17:17:23 -07006572 VkShaderObj vs(m_device, bindStateVertShaderText,
6573 VK_SHADER_STAGE_VERTEX_BIT, this);
6574 VkShaderObj fs(m_device, bindStateFragShaderText,
6575 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006576 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006577 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006578 shaderStages[0] = vs.GetStageCreateInfo();
6579 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006580
6581 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006582 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6583 gp_ci.stageCount = 2;
6584 gp_ci.pStages = shaderStages;
6585 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006586 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006587 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6588 gp_ci.layout = pipeline_layout;
6589 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006590
6591 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006592 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006593
6594 VkPipeline pipeline;
6595 VkPipelineCache pipelineCache;
6596
Karl Schultz6addd812016-02-02 17:17:23 -07006597 err =
6598 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006599 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006600 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6601 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006602
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006603 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006604
Chia-I Wuf7458c52015-10-26 21:10:41 +08006605 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6606 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6607 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6608 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006609}
Karl Schultz6addd812016-02-02 17:17:23 -07006610// Don't set viewport state in PSO. This is an error b/c we always need this
6611// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006612// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006613TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006614 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006615 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006616
Karl Schultz6addd812016-02-02 17:17:23 -07006617 m_errorMonitor->SetDesiredFailureMsg(
6618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006619 "Gfx Pipeline pViewportState is null. Even if ");
6620
Tobin Ehlise68360f2015-10-01 11:15:13 -06006621 ASSERT_NO_FATAL_FAILURE(InitState());
6622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006623
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006624 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006625 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6626 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006627
6628 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006629 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6630 ds_pool_ci.maxSets = 1;
6631 ds_pool_ci.poolSizeCount = 1;
6632 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006633
6634 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006635 err =
6636 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006637 ASSERT_VK_SUCCESS(err);
6638
6639 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006640 dsl_binding.binding = 0;
6641 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6642 dsl_binding.descriptorCount = 1;
6643 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006644
6645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6647 ds_layout_ci.bindingCount = 1;
6648 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006649
6650 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006651 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6652 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006653 ASSERT_VK_SUCCESS(err);
6654
6655 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006656 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006657 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006658 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006659 alloc_info.descriptorPool = ds_pool;
6660 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6662 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006663 ASSERT_VK_SUCCESS(err);
6664
6665 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006666 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6667 pipeline_layout_ci.setLayoutCount = 1;
6668 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006669
6670 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6672 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006673 ASSERT_VK_SUCCESS(err);
6674
6675 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6676 // Set scissor as dynamic to avoid second error
6677 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006678 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6679 dyn_state_ci.dynamicStateCount = 1;
6680 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006681
Cody Northropeb3a6c12015-10-05 14:44:45 -06006682 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006683 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006684
Karl Schultz6addd812016-02-02 17:17:23 -07006685 VkShaderObj vs(m_device, bindStateVertShaderText,
6686 VK_SHADER_STAGE_VERTEX_BIT, this);
6687 VkShaderObj fs(m_device, bindStateFragShaderText,
6688 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006689 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006690 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006691 shaderStages[0] = vs.GetStageCreateInfo();
6692 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006693
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006694
6695 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6696 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6697 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6698 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6699 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6700 rs_state_ci.depthClampEnable = VK_FALSE;
6701 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6702 rs_state_ci.depthBiasEnable = VK_FALSE;
6703
Tobin Ehlise68360f2015-10-01 11:15:13 -06006704 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006705 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6706 gp_ci.stageCount = 2;
6707 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006708 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006709 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6710 // should cause validation error
6711 gp_ci.pDynamicState = &dyn_state_ci;
6712 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6713 gp_ci.layout = pipeline_layout;
6714 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006715
6716 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006717 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006718
6719 VkPipeline pipeline;
6720 VkPipelineCache pipelineCache;
6721
Karl Schultz6addd812016-02-02 17:17:23 -07006722 err =
6723 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006724 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006725 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6726 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006727
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006728 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006729
Chia-I Wuf7458c52015-10-26 21:10:41 +08006730 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6731 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6732 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6733 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006734}
6735// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006736// Then run second test where dynamic scissor count doesn't match PSO scissor
6737// count
6738TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6739 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006740
Karl Schultz6addd812016-02-02 17:17:23 -07006741 m_errorMonitor->SetDesiredFailureMsg(
6742 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006743 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6744
Tobin Ehlise68360f2015-10-01 11:15:13 -06006745 ASSERT_NO_FATAL_FAILURE(InitState());
6746 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006747
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006748 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006749 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6750 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006751
6752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6754 ds_pool_ci.maxSets = 1;
6755 ds_pool_ci.poolSizeCount = 1;
6756 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006757
6758 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006759 err =
6760 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006761 ASSERT_VK_SUCCESS(err);
6762
6763 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006764 dsl_binding.binding = 0;
6765 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6766 dsl_binding.descriptorCount = 1;
6767 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006768
6769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6771 ds_layout_ci.bindingCount = 1;
6772 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006773
6774 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6776 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006777 ASSERT_VK_SUCCESS(err);
6778
6779 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006780 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006781 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006782 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006783 alloc_info.descriptorPool = ds_pool;
6784 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006785 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6786 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006787 ASSERT_VK_SUCCESS(err);
6788
6789 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006790 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6791 pipeline_layout_ci.setLayoutCount = 1;
6792 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006793
6794 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006795 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6796 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006797 ASSERT_VK_SUCCESS(err);
6798
6799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6801 vp_state_ci.viewportCount = 1;
6802 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6803 vp_state_ci.scissorCount = 1;
6804 vp_state_ci.pScissors =
6805 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006806
6807 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6808 // Set scissor as dynamic to avoid that error
6809 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6811 dyn_state_ci.dynamicStateCount = 1;
6812 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006813
Cody Northropeb3a6c12015-10-05 14:44:45 -06006814 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006815 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006816
Karl Schultz6addd812016-02-02 17:17:23 -07006817 VkShaderObj vs(m_device, bindStateVertShaderText,
6818 VK_SHADER_STAGE_VERTEX_BIT, this);
6819 VkShaderObj fs(m_device, bindStateFragShaderText,
6820 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006821 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006822 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006823 shaderStages[0] = vs.GetStageCreateInfo();
6824 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006825
Cody Northropf6622dc2015-10-06 10:33:21 -06006826 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6827 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6828 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006829 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006830 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006831 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006832 vi_ci.pVertexAttributeDescriptions = nullptr;
6833
6834 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6835 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6836 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6837
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006838 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006839 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006840 rs_ci.pNext = nullptr;
6841
Mark Youngc89c6312016-03-31 16:03:20 -06006842 VkPipelineColorBlendAttachmentState att = {};
6843 att.blendEnable = VK_FALSE;
6844 att.colorWriteMask = 0xf;
6845
Cody Northropf6622dc2015-10-06 10:33:21 -06006846 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6847 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6848 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006849 cb_ci.attachmentCount = 1;
6850 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006851
Tobin Ehlise68360f2015-10-01 11:15:13 -06006852 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006853 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6854 gp_ci.stageCount = 2;
6855 gp_ci.pStages = shaderStages;
6856 gp_ci.pVertexInputState = &vi_ci;
6857 gp_ci.pInputAssemblyState = &ia_ci;
6858 gp_ci.pViewportState = &vp_state_ci;
6859 gp_ci.pRasterizationState = &rs_ci;
6860 gp_ci.pColorBlendState = &cb_ci;
6861 gp_ci.pDynamicState = &dyn_state_ci;
6862 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6863 gp_ci.layout = pipeline_layout;
6864 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006865
6866 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006867 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006868
6869 VkPipeline pipeline;
6870 VkPipelineCache pipelineCache;
6871
Karl Schultz6addd812016-02-02 17:17:23 -07006872 err =
6873 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006874 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006875 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6876 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006878 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006879
Tobin Ehlisd332f282015-10-02 11:00:56 -06006880 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006881 // First need to successfully create the PSO from above by setting
6882 // pViewports
6883 m_errorMonitor->SetDesiredFailureMsg(
6884 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6885 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6886 "scissorCount is 1. These counts must match.");
6887
6888 VkViewport vp = {}; // Just need dummy vp to point to
6889 vp_state_ci.pViewports = &vp;
6890 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6891 &gp_ci, NULL, &pipeline);
6892 ASSERT_VK_SUCCESS(err);
6893 BeginCommandBuffer();
6894 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6895 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6896 VkRect2D scissors[2] = {}; // don't care about data
6897 // Count of 2 doesn't match PSO count of 1
6898 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6899 Draw(1, 0, 0, 0);
6900
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006901 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006902
6903 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6904 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6905 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6906 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006907 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006908}
6909// Create PSO w/o non-zero scissorCount but no scissor data
6910// Then run second test where dynamic viewportCount doesn't match PSO
6911// viewportCount
6912TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6913 VkResult err;
6914
6915 m_errorMonitor->SetDesiredFailureMsg(
6916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6917 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6918
6919 ASSERT_NO_FATAL_FAILURE(InitState());
6920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6921
6922 VkDescriptorPoolSize ds_type_count = {};
6923 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6924 ds_type_count.descriptorCount = 1;
6925
6926 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6927 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6928 ds_pool_ci.maxSets = 1;
6929 ds_pool_ci.poolSizeCount = 1;
6930 ds_pool_ci.pPoolSizes = &ds_type_count;
6931
6932 VkDescriptorPool ds_pool;
6933 err =
6934 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSetLayoutBinding dsl_binding = {};
6938 dsl_binding.binding = 0;
6939 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6940 dsl_binding.descriptorCount = 1;
6941 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6942
6943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6945 ds_layout_ci.bindingCount = 1;
6946 ds_layout_ci.pBindings = &dsl_binding;
6947
6948 VkDescriptorSetLayout ds_layout;
6949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6950 &ds_layout);
6951 ASSERT_VK_SUCCESS(err);
6952
6953 VkDescriptorSet descriptorSet;
6954 VkDescriptorSetAllocateInfo alloc_info = {};
6955 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6956 alloc_info.descriptorSetCount = 1;
6957 alloc_info.descriptorPool = ds_pool;
6958 alloc_info.pSetLayouts = &ds_layout;
6959 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6960 &descriptorSet);
6961 ASSERT_VK_SUCCESS(err);
6962
6963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6965 pipeline_layout_ci.setLayoutCount = 1;
6966 pipeline_layout_ci.pSetLayouts = &ds_layout;
6967
6968 VkPipelineLayout pipeline_layout;
6969 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6970 &pipeline_layout);
6971 ASSERT_VK_SUCCESS(err);
6972
6973 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6974 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6975 vp_state_ci.scissorCount = 1;
6976 vp_state_ci.pScissors =
6977 NULL; // Null scissor w/ count of 1 should cause error
6978 vp_state_ci.viewportCount = 1;
6979 vp_state_ci.pViewports =
6980 NULL; // vp is dynamic (below) so this won't cause error
6981
6982 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6983 // Set scissor as dynamic to avoid that error
6984 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6985 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6986 dyn_state_ci.dynamicStateCount = 1;
6987 dyn_state_ci.pDynamicStates = &vp_state;
6988
6989 VkPipelineShaderStageCreateInfo shaderStages[2];
6990 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6991
6992 VkShaderObj vs(m_device, bindStateVertShaderText,
6993 VK_SHADER_STAGE_VERTEX_BIT, this);
6994 VkShaderObj fs(m_device, bindStateFragShaderText,
6995 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006996 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006997 // but add it to be able to run on more devices
6998 shaderStages[0] = vs.GetStageCreateInfo();
6999 shaderStages[1] = fs.GetStageCreateInfo();
7000
7001 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7002 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7003 vi_ci.pNext = nullptr;
7004 vi_ci.vertexBindingDescriptionCount = 0;
7005 vi_ci.pVertexBindingDescriptions = nullptr;
7006 vi_ci.vertexAttributeDescriptionCount = 0;
7007 vi_ci.pVertexAttributeDescriptions = nullptr;
7008
7009 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7010 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7011 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7012
7013 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7014 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7015 rs_ci.pNext = nullptr;
7016
Mark Youngc89c6312016-03-31 16:03:20 -06007017 VkPipelineColorBlendAttachmentState att = {};
7018 att.blendEnable = VK_FALSE;
7019 att.colorWriteMask = 0xf;
7020
Karl Schultz6addd812016-02-02 17:17:23 -07007021 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7022 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7023 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007024 cb_ci.attachmentCount = 1;
7025 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007026
7027 VkGraphicsPipelineCreateInfo gp_ci = {};
7028 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7029 gp_ci.stageCount = 2;
7030 gp_ci.pStages = shaderStages;
7031 gp_ci.pVertexInputState = &vi_ci;
7032 gp_ci.pInputAssemblyState = &ia_ci;
7033 gp_ci.pViewportState = &vp_state_ci;
7034 gp_ci.pRasterizationState = &rs_ci;
7035 gp_ci.pColorBlendState = &cb_ci;
7036 gp_ci.pDynamicState = &dyn_state_ci;
7037 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7038 gp_ci.layout = pipeline_layout;
7039 gp_ci.renderPass = renderPass();
7040
7041 VkPipelineCacheCreateInfo pc_ci = {};
7042 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7043
7044 VkPipeline pipeline;
7045 VkPipelineCache pipelineCache;
7046
7047 err =
7048 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7049 ASSERT_VK_SUCCESS(err);
7050 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7051 &gp_ci, NULL, &pipeline);
7052
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007053 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007054
7055 // Now hit second fail case where we set scissor w/ different count than PSO
7056 // First need to successfully create the PSO from above by setting
7057 // pViewports
7058 m_errorMonitor->SetDesiredFailureMsg(
7059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7060 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
7061 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007062
Tobin Ehlisd332f282015-10-02 11:00:56 -06007063 VkRect2D sc = {}; // Just need dummy vp to point to
7064 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07007065 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7066 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007067 ASSERT_VK_SUCCESS(err);
7068 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007069 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7070 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007071 VkViewport viewports[2] = {}; // don't care about data
7072 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007073 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007074 Draw(1, 0, 0, 0);
7075
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007076 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007077
Chia-I Wuf7458c52015-10-26 21:10:41 +08007078 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007082 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007083}
7084
Mark Young7394fdd2016-03-31 14:56:43 -06007085TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7086 VkResult err;
7087
7088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007089 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007090
7091 ASSERT_NO_FATAL_FAILURE(InitState());
7092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7093
7094 VkDescriptorPoolSize ds_type_count = {};
7095 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7096 ds_type_count.descriptorCount = 1;
7097
7098 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7099 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7100 ds_pool_ci.maxSets = 1;
7101 ds_pool_ci.poolSizeCount = 1;
7102 ds_pool_ci.pPoolSizes = &ds_type_count;
7103
7104 VkDescriptorPool ds_pool;
7105 err =
7106 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7107 ASSERT_VK_SUCCESS(err);
7108
7109 VkDescriptorSetLayoutBinding dsl_binding = {};
7110 dsl_binding.binding = 0;
7111 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7112 dsl_binding.descriptorCount = 1;
7113 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7114
7115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7117 ds_layout_ci.bindingCount = 1;
7118 ds_layout_ci.pBindings = &dsl_binding;
7119
7120 VkDescriptorSetLayout ds_layout;
7121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7122 &ds_layout);
7123 ASSERT_VK_SUCCESS(err);
7124
7125 VkDescriptorSet descriptorSet;
7126 VkDescriptorSetAllocateInfo alloc_info = {};
7127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7128 alloc_info.descriptorSetCount = 1;
7129 alloc_info.descriptorPool = ds_pool;
7130 alloc_info.pSetLayouts = &ds_layout;
7131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7132 &descriptorSet);
7133 ASSERT_VK_SUCCESS(err);
7134
7135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7137 pipeline_layout_ci.setLayoutCount = 1;
7138 pipeline_layout_ci.pSetLayouts = &ds_layout;
7139
7140 VkPipelineLayout pipeline_layout;
7141 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7142 &pipeline_layout);
7143 ASSERT_VK_SUCCESS(err);
7144
7145 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7146 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7147 vp_state_ci.scissorCount = 1;
7148 vp_state_ci.pScissors = NULL;
7149 vp_state_ci.viewportCount = 1;
7150 vp_state_ci.pViewports = NULL;
7151
7152 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7153 VK_DYNAMIC_STATE_SCISSOR,
7154 VK_DYNAMIC_STATE_LINE_WIDTH};
7155 // Set scissor as dynamic to avoid that error
7156 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7157 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7158 dyn_state_ci.dynamicStateCount = 2;
7159 dyn_state_ci.pDynamicStates = dynamic_states;
7160
7161 VkPipelineShaderStageCreateInfo shaderStages[2];
7162 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7163
7164 VkShaderObj vs(m_device, bindStateVertShaderText,
7165 VK_SHADER_STAGE_VERTEX_BIT, this);
7166 VkShaderObj fs(m_device, bindStateFragShaderText,
7167 VK_SHADER_STAGE_FRAGMENT_BIT,
7168 this); // TODO - We shouldn't need a fragment shader
7169 // but add it to be able to run on more devices
7170 shaderStages[0] = vs.GetStageCreateInfo();
7171 shaderStages[1] = fs.GetStageCreateInfo();
7172
7173 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7174 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7175 vi_ci.pNext = nullptr;
7176 vi_ci.vertexBindingDescriptionCount = 0;
7177 vi_ci.pVertexBindingDescriptions = nullptr;
7178 vi_ci.vertexAttributeDescriptionCount = 0;
7179 vi_ci.pVertexAttributeDescriptions = nullptr;
7180
7181 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7182 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7183 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7184
7185 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7186 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7187 rs_ci.pNext = nullptr;
7188
Mark Young47107952016-05-02 15:59:55 -06007189 // Check too low (line width of -1.0f).
7190 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007191
7192 VkPipelineColorBlendAttachmentState att = {};
7193 att.blendEnable = VK_FALSE;
7194 att.colorWriteMask = 0xf;
7195
7196 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7197 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7198 cb_ci.pNext = nullptr;
7199 cb_ci.attachmentCount = 1;
7200 cb_ci.pAttachments = &att;
7201
7202 VkGraphicsPipelineCreateInfo gp_ci = {};
7203 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7204 gp_ci.stageCount = 2;
7205 gp_ci.pStages = shaderStages;
7206 gp_ci.pVertexInputState = &vi_ci;
7207 gp_ci.pInputAssemblyState = &ia_ci;
7208 gp_ci.pViewportState = &vp_state_ci;
7209 gp_ci.pRasterizationState = &rs_ci;
7210 gp_ci.pColorBlendState = &cb_ci;
7211 gp_ci.pDynamicState = &dyn_state_ci;
7212 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7213 gp_ci.layout = pipeline_layout;
7214 gp_ci.renderPass = renderPass();
7215
7216 VkPipelineCacheCreateInfo pc_ci = {};
7217 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7218
7219 VkPipeline pipeline;
7220 VkPipelineCache pipelineCache;
7221
7222 err =
7223 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7224 ASSERT_VK_SUCCESS(err);
7225 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7226 &gp_ci, NULL, &pipeline);
7227
7228 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007229 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007230
7231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7232 "Attempt to set lineWidth to 65536");
7233
7234 // Check too high (line width of 65536.0f).
7235 rs_ci.lineWidth = 65536.0f;
7236
7237 err =
7238 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7239 ASSERT_VK_SUCCESS(err);
7240 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7241 &gp_ci, NULL, &pipeline);
7242
7243 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007244 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007245
7246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007247 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007248
7249 dyn_state_ci.dynamicStateCount = 3;
7250
7251 rs_ci.lineWidth = 1.0f;
7252
7253 err =
7254 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7255 ASSERT_VK_SUCCESS(err);
7256 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7257 &gp_ci, NULL, &pipeline);
7258 BeginCommandBuffer();
7259 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7260 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7261
7262 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007263 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007264 m_errorMonitor->VerifyFound();
7265
7266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7267 "Attempt to set lineWidth to 65536");
7268
7269 // Check too high with dynamic setting.
7270 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7271 m_errorMonitor->VerifyFound();
7272 EndCommandBuffer();
7273
7274 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7275 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7276 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7277 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007278 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007279}
7280
Karl Schultz6addd812016-02-02 17:17:23 -07007281TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007282 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007283 m_errorMonitor->SetDesiredFailureMsg(
7284 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007285 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007286
7287 ASSERT_NO_FATAL_FAILURE(InitState());
7288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007289
Tony Barbourfe3351b2015-07-28 10:17:20 -06007290 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007291 // Don't care about RenderPass handle b/c error should be flagged before
7292 // that
7293 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7294 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007295
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007296 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007297}
7298
Karl Schultz6addd812016-02-02 17:17:23 -07007299TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007300 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007301 m_errorMonitor->SetDesiredFailureMsg(
7302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007303 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007304
7305 ASSERT_NO_FATAL_FAILURE(InitState());
7306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007307
Tony Barbourfe3351b2015-07-28 10:17:20 -06007308 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007309 // Just create a dummy Renderpass that's non-NULL so we can get to the
7310 // proper error
Chris Forbes38ae7c42016-06-21 20:51:44 +12007311 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo,
Karl Schultz6addd812016-02-02 17:17:23 -07007312 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007313
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007314 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007315}
7316
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007317TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7318 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7319 "the number of renderPass attachments that use loadOp"
7320 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7321
7322 ASSERT_NO_FATAL_FAILURE(InitState());
7323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7324
7325 // Create a renderPass with a single attachment that uses loadOp CLEAR
7326 VkAttachmentReference attach = {};
7327 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7328 VkSubpassDescription subpass = {};
7329 subpass.inputAttachmentCount = 1;
7330 subpass.pInputAttachments = &attach;
7331 VkRenderPassCreateInfo rpci = {};
7332 rpci.subpassCount = 1;
7333 rpci.pSubpasses = &subpass;
7334 rpci.attachmentCount = 1;
7335 VkAttachmentDescription attach_desc = {};
7336 attach_desc.format = VK_FORMAT_UNDEFINED;
7337 // Set loadOp to CLEAR
7338 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7339 rpci.pAttachments = &attach_desc;
7340 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7341 VkRenderPass rp;
7342 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7343
7344 VkCommandBufferInheritanceInfo hinfo = {};
7345 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7346 hinfo.renderPass = VK_NULL_HANDLE;
7347 hinfo.subpass = 0;
7348 hinfo.framebuffer = VK_NULL_HANDLE;
7349 hinfo.occlusionQueryEnable = VK_FALSE;
7350 hinfo.queryFlags = 0;
7351 hinfo.pipelineStatistics = 0;
7352 VkCommandBufferBeginInfo info = {};
7353 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7354 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7355 info.pInheritanceInfo = &hinfo;
7356
7357 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7358 VkRenderPassBeginInfo rp_begin = {};
7359 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7360 rp_begin.pNext = NULL;
7361 rp_begin.renderPass = renderPass();
7362 rp_begin.framebuffer = framebuffer();
7363 rp_begin.clearValueCount = 0; // Should be 1
7364
7365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7366 " has a clearValueCount of 0 but the "
7367 "actual number of attachments in "
7368 "renderPass ");
7369
7370 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7371 VK_SUBPASS_CONTENTS_INLINE);
7372
7373 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007374
7375 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007376}
7377
Cody Northrop3bb4d962016-05-09 16:15:57 -06007378TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7379
7380 TEST_DESCRIPTION("End a command buffer with an active render pass");
7381
7382 m_errorMonitor->SetDesiredFailureMsg(
7383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7384 "It is invalid to issue this call inside an active render pass");
7385
7386 ASSERT_NO_FATAL_FAILURE(InitState());
7387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7388
7389 // The framework's BeginCommandBuffer calls CreateRenderPass
7390 BeginCommandBuffer();
7391
7392 // Call directly into vkEndCommandBuffer instead of the
7393 // the framework's EndCommandBuffer, which inserts a
7394 // vkEndRenderPass
7395 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7396
7397 m_errorMonitor->VerifyFound();
7398
7399 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7400 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7401}
7402
Karl Schultz6addd812016-02-02 17:17:23 -07007403TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007404 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007405 m_errorMonitor->SetDesiredFailureMsg(
7406 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007407 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007408
7409 ASSERT_NO_FATAL_FAILURE(InitState());
7410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007411
7412 // Renderpass is started here
7413 BeginCommandBuffer();
7414
7415 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007416 vk_testing::Buffer dstBuffer;
7417 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007418
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007419 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007421 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007422}
7423
Karl Schultz6addd812016-02-02 17:17:23 -07007424TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007425 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007426 m_errorMonitor->SetDesiredFailureMsg(
7427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007428 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007429
7430 ASSERT_NO_FATAL_FAILURE(InitState());
7431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007432
7433 // Renderpass is started here
7434 BeginCommandBuffer();
7435
7436 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007437 vk_testing::Buffer dstBuffer;
7438 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007439
Karl Schultz6addd812016-02-02 17:17:23 -07007440 VkDeviceSize dstOffset = 0;
7441 VkDeviceSize dataSize = 1024;
7442 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007443
Karl Schultz6addd812016-02-02 17:17:23 -07007444 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7445 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007447 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007448}
7449
Karl Schultz6addd812016-02-02 17:17:23 -07007450TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007451 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007452 m_errorMonitor->SetDesiredFailureMsg(
7453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007454 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007455
7456 ASSERT_NO_FATAL_FAILURE(InitState());
7457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007458
7459 // Renderpass is started here
7460 BeginCommandBuffer();
7461
Michael Lentine0a369f62016-02-03 16:51:46 -06007462 VkClearColorValue clear_color;
7463 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007464 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7465 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7466 const int32_t tex_width = 32;
7467 const int32_t tex_height = 32;
7468 VkImageCreateInfo image_create_info = {};
7469 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7470 image_create_info.pNext = NULL;
7471 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7472 image_create_info.format = tex_format;
7473 image_create_info.extent.width = tex_width;
7474 image_create_info.extent.height = tex_height;
7475 image_create_info.extent.depth = 1;
7476 image_create_info.mipLevels = 1;
7477 image_create_info.arrayLayers = 1;
7478 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7479 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7480 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007481
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007482 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007483 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7484 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007485
Karl Schultz6addd812016-02-02 17:17:23 -07007486 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7487 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007488
Karl Schultz6addd812016-02-02 17:17:23 -07007489 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7490 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007491
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007492 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007493}
7494
Karl Schultz6addd812016-02-02 17:17:23 -07007495TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007496 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007497 m_errorMonitor->SetDesiredFailureMsg(
7498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007499 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007500
7501 ASSERT_NO_FATAL_FAILURE(InitState());
7502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007503
7504 // Renderpass is started here
7505 BeginCommandBuffer();
7506
7507 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007508 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007509 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7511 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7512 image_create_info.extent.width = 64;
7513 image_create_info.extent.height = 64;
7514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7515 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007516
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007517 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007518 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7519 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007520
Karl Schultz6addd812016-02-02 17:17:23 -07007521 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7522 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 vkCmdClearDepthStencilImage(
7525 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7526 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7527 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007529 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007530}
7531
Karl Schultz6addd812016-02-02 17:17:23 -07007532TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007533 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007534 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007535
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007537 "vkCmdClearAttachments: This call "
7538 "must be issued inside an active "
7539 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007540
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007541 ASSERT_NO_FATAL_FAILURE(InitState());
7542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007543
7544 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007545 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007546 ASSERT_VK_SUCCESS(err);
7547
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007548 VkClearAttachment color_attachment;
7549 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7550 color_attachment.clearValue.color.float32[0] = 0;
7551 color_attachment.clearValue.color.float32[1] = 0;
7552 color_attachment.clearValue.color.float32[2] = 0;
7553 color_attachment.clearValue.color.float32[3] = 0;
7554 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007555 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7556 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7557 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007558
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007559 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007560}
7561
Karl Schultz9e66a292016-04-21 15:57:51 -06007562TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7563 // Try to add a buffer memory barrier with no buffer.
7564 m_errorMonitor->SetDesiredFailureMsg(
7565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7566 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7567
7568 ASSERT_NO_FATAL_FAILURE(InitState());
7569 BeginCommandBuffer();
7570
7571 VkBufferMemoryBarrier buf_barrier = {};
7572 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7573 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7574 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7575 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7576 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7577 buf_barrier.buffer = VK_NULL_HANDLE;
7578 buf_barrier.offset = 0;
7579 buf_barrier.size = VK_WHOLE_SIZE;
7580 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7581 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7582 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7583
7584 m_errorMonitor->VerifyFound();
7585}
7586
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007587TEST_F(VkLayerTest, InvalidBarriers) {
7588 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7589
7590 m_errorMonitor->SetDesiredFailureMsg(
7591 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7592
7593 ASSERT_NO_FATAL_FAILURE(InitState());
7594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7595
7596 VkMemoryBarrier mem_barrier = {};
7597 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7598 mem_barrier.pNext = NULL;
7599 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7600 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7601 BeginCommandBuffer();
7602 // BeginCommandBuffer() starts a render pass
7603 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7604 VK_PIPELINE_STAGE_HOST_BIT,
7605 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7606 &mem_barrier, 0, nullptr, 0, nullptr);
7607 m_errorMonitor->VerifyFound();
7608
7609 m_errorMonitor->SetDesiredFailureMsg(
7610 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7611 "Image Layout cannot be transitioned to UNDEFINED");
7612 VkImageObj image(m_device);
7613 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7614 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7615 ASSERT_TRUE(image.initialized());
7616 VkImageMemoryBarrier img_barrier = {};
7617 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7618 img_barrier.pNext = NULL;
7619 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7620 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7621 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7622 // New layout can't be UNDEFINED
7623 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7624 img_barrier.image = image.handle();
7625 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7626 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7627 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7628 img_barrier.subresourceRange.baseArrayLayer = 0;
7629 img_barrier.subresourceRange.baseMipLevel = 0;
7630 img_barrier.subresourceRange.layerCount = 1;
7631 img_barrier.subresourceRange.levelCount = 1;
7632 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7633 VK_PIPELINE_STAGE_HOST_BIT,
7634 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7635 nullptr, 1, &img_barrier);
7636 m_errorMonitor->VerifyFound();
7637 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7638
7639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7640 "Subresource must have the sum of the "
7641 "baseArrayLayer");
7642 // baseArrayLayer + layerCount must be <= image's arrayLayers
7643 img_barrier.subresourceRange.baseArrayLayer = 1;
7644 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7645 VK_PIPELINE_STAGE_HOST_BIT,
7646 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7647 nullptr, 1, &img_barrier);
7648 m_errorMonitor->VerifyFound();
7649 img_barrier.subresourceRange.baseArrayLayer = 0;
7650
7651 m_errorMonitor->SetDesiredFailureMsg(
7652 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7653 "Subresource must have the sum of the baseMipLevel");
7654 // baseMipLevel + levelCount must be <= image's mipLevels
7655 img_barrier.subresourceRange.baseMipLevel = 1;
7656 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7657 VK_PIPELINE_STAGE_HOST_BIT,
7658 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7659 nullptr, 1, &img_barrier);
7660 m_errorMonitor->VerifyFound();
7661 img_barrier.subresourceRange.baseMipLevel = 0;
7662
7663 m_errorMonitor->SetDesiredFailureMsg(
7664 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7665 "Buffer Barriers cannot be used during a render pass");
7666 vk_testing::Buffer buffer;
7667 buffer.init(*m_device, 256);
7668 VkBufferMemoryBarrier buf_barrier = {};
7669 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7670 buf_barrier.pNext = NULL;
7671 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7672 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7673 buf_barrier.buffer = buffer.handle();
7674 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7675 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7676 buf_barrier.offset = 0;
7677 buf_barrier.size = VK_WHOLE_SIZE;
7678 // Can't send buffer barrier during a render pass
7679 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7680 VK_PIPELINE_STAGE_HOST_BIT,
7681 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7682 &buf_barrier, 0, nullptr);
7683 m_errorMonitor->VerifyFound();
7684 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7685
7686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7687 "which is not less than total size");
7688 buf_barrier.offset = 257;
7689 // Offset greater than total size
7690 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7691 VK_PIPELINE_STAGE_HOST_BIT,
7692 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7693 &buf_barrier, 0, nullptr);
7694 m_errorMonitor->VerifyFound();
7695 buf_barrier.offset = 0;
7696
7697 m_errorMonitor->SetDesiredFailureMsg(
7698 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7699 buf_barrier.size = 257;
7700 // Size greater than total size
7701 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7702 VK_PIPELINE_STAGE_HOST_BIT,
7703 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7704 &buf_barrier, 0, nullptr);
7705 m_errorMonitor->VerifyFound();
7706 buf_barrier.size = VK_WHOLE_SIZE;
7707
7708 m_errorMonitor->SetDesiredFailureMsg(
7709 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7710 "Image is a depth and stencil format and thus must "
7711 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7712 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7713 VkDepthStencilObj ds_image(m_device);
7714 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7715 ASSERT_TRUE(ds_image.initialized());
7716 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7717 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7718 img_barrier.image = ds_image.handle();
7719 // Leave aspectMask at COLOR on purpose
7720 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7721 VK_PIPELINE_STAGE_HOST_BIT,
7722 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7723 nullptr, 1, &img_barrier);
7724 m_errorMonitor->VerifyFound();
7725}
7726
Karl Schultz6addd812016-02-02 17:17:23 -07007727TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007728 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007729 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007730
Karl Schultz6addd812016-02-02 17:17:23 -07007731 m_errorMonitor->SetDesiredFailureMsg(
7732 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007733 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7734
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007735 ASSERT_NO_FATAL_FAILURE(InitState());
7736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007737 uint32_t qfi = 0;
7738 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007739 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7740 buffCI.size = 1024;
7741 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7742 buffCI.queueFamilyIndexCount = 1;
7743 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007744
7745 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007746 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007747 ASSERT_VK_SUCCESS(err);
7748
7749 BeginCommandBuffer();
7750 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007751 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7752 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007753 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007754 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7755 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007757 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007758
Chia-I Wuf7458c52015-10-26 21:10:41 +08007759 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007760}
7761
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007762TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7763 // Create an out-of-range queueFamilyIndex
7764 m_errorMonitor->SetDesiredFailureMsg(
7765 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007766 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7767 "of the indices specified when the device was created, via the "
7768 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007769
7770 ASSERT_NO_FATAL_FAILURE(InitState());
7771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7772 VkBufferCreateInfo buffCI = {};
7773 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7774 buffCI.size = 1024;
7775 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7776 buffCI.queueFamilyIndexCount = 1;
7777 // Introduce failure by specifying invalid queue_family_index
7778 uint32_t qfi = 777;
7779 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007780 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007781
7782 VkBuffer ib;
7783 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007785 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007786 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007787}
7788
Karl Schultz6addd812016-02-02 17:17:23 -07007789TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7790 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7791 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007792
Karl Schultz6addd812016-02-02 17:17:23 -07007793 m_errorMonitor->SetDesiredFailureMsg(
7794 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007795 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007796
7797 ASSERT_NO_FATAL_FAILURE(InitState());
7798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007799
7800 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007801 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007802 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7803 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007805 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007806}
7807
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007808TEST_F(VkLayerTest, DSUsageBitsErrors) {
7809 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7810 "that do not have correct usage bits sets.");
7811 VkResult err;
7812
7813 ASSERT_NO_FATAL_FAILURE(InitState());
7814 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7815 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7816 ds_type_count[i].type = VkDescriptorType(i);
7817 ds_type_count[i].descriptorCount = 1;
7818 }
7819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7821 ds_pool_ci.pNext = NULL;
7822 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7823 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7824 ds_pool_ci.pPoolSizes = ds_type_count;
7825
7826 VkDescriptorPool ds_pool;
7827 err =
7828 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7829 ASSERT_VK_SUCCESS(err);
7830
7831 // Create 10 layouts where each has a single descriptor of different type
7832 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7833 {};
7834 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7835 dsl_binding[i].binding = 0;
7836 dsl_binding[i].descriptorType = VkDescriptorType(i);
7837 dsl_binding[i].descriptorCount = 1;
7838 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7839 dsl_binding[i].pImmutableSamplers = NULL;
7840 }
7841
7842 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7843 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7844 ds_layout_ci.pNext = NULL;
7845 ds_layout_ci.bindingCount = 1;
7846 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7847 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7848 ds_layout_ci.pBindings = dsl_binding + i;
7849 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7850 NULL, ds_layouts + i);
7851 ASSERT_VK_SUCCESS(err);
7852 }
7853 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7854 VkDescriptorSetAllocateInfo alloc_info = {};
7855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7856 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7857 alloc_info.descriptorPool = ds_pool;
7858 alloc_info.pSetLayouts = ds_layouts;
7859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7860 descriptor_sets);
7861 ASSERT_VK_SUCCESS(err);
7862
7863 // Create a buffer & bufferView to be used for invalid updates
7864 VkBufferCreateInfo buff_ci = {};
7865 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7866 // This usage is not valid for any descriptor type
7867 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7868 buff_ci.size = 256;
7869 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7870 VkBuffer buffer;
7871 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7872 ASSERT_VK_SUCCESS(err);
7873
7874 VkBufferViewCreateInfo buff_view_ci = {};
7875 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7876 buff_view_ci.buffer = buffer;
7877 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7878 buff_view_ci.range = VK_WHOLE_SIZE;
7879 VkBufferView buff_view;
7880 err =
7881 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7882 ASSERT_VK_SUCCESS(err);
7883
7884 // Create an image to be used for invalid updates
7885 VkImageCreateInfo image_ci = {};
7886 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7887 image_ci.imageType = VK_IMAGE_TYPE_2D;
7888 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7889 image_ci.extent.width = 64;
7890 image_ci.extent.height = 64;
7891 image_ci.extent.depth = 1;
7892 image_ci.mipLevels = 1;
7893 image_ci.arrayLayers = 1;
7894 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7895 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7896 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7897 // This usage is not valid for any descriptor type
7898 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7899 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7900 VkImage image;
7901 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7902 ASSERT_VK_SUCCESS(err);
7903 // Bind memory to image
7904 VkMemoryRequirements mem_reqs;
7905 VkDeviceMemory image_mem;
7906 bool pass;
7907 VkMemoryAllocateInfo mem_alloc = {};
7908 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7909 mem_alloc.pNext = NULL;
7910 mem_alloc.allocationSize = 0;
7911 mem_alloc.memoryTypeIndex = 0;
7912 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7913 mem_alloc.allocationSize = mem_reqs.size;
7914 pass =
7915 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7916 ASSERT_TRUE(pass);
7917 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7918 ASSERT_VK_SUCCESS(err);
7919 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7920 ASSERT_VK_SUCCESS(err);
7921 // Now create view for image
7922 VkImageViewCreateInfo image_view_ci = {};
7923 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7924 image_view_ci.image = image;
7925 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7926 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7927 image_view_ci.subresourceRange.layerCount = 1;
7928 image_view_ci.subresourceRange.baseArrayLayer = 0;
7929 image_view_ci.subresourceRange.levelCount = 1;
7930 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7931 VkImageView image_view;
7932 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7933 &image_view);
7934 ASSERT_VK_SUCCESS(err);
7935
7936 VkDescriptorBufferInfo buff_info = {};
7937 buff_info.buffer = buffer;
7938 VkDescriptorImageInfo img_info = {};
7939 img_info.imageView = image_view;
7940 VkWriteDescriptorSet descriptor_write = {};
7941 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7942 descriptor_write.dstBinding = 0;
7943 descriptor_write.descriptorCount = 1;
7944 descriptor_write.pTexelBufferView = &buff_view;
7945 descriptor_write.pBufferInfo = &buff_info;
7946 descriptor_write.pImageInfo = &img_info;
7947
7948 // These error messages align with VkDescriptorType struct
7949 const char *error_msgs[] = {
7950 "", // placeholder, no error for SAMPLER descriptor
7951 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7952 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7953 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7954 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7955 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7956 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7957 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7958 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7959 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7960 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7961 // Start loop at 1 as SAMPLER desc type has no usage bit error
7962 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7963 descriptor_write.descriptorType = VkDescriptorType(i);
7964 descriptor_write.dstSet = descriptor_sets[i];
7965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7966 error_msgs[i]);
7967
7968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7969 NULL);
7970
7971 m_errorMonitor->VerifyFound();
7972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7973 }
7974 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7975 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007976 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007977 vkDestroyImageView(m_device->device(), image_view, NULL);
7978 vkDestroyBuffer(m_device->device(), buffer, NULL);
7979 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7980 vkFreeDescriptorSets(m_device->device(), ds_pool,
7981 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7983}
7984
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06007985TEST_F(VkLayerTest, DSAspectBitsErrors) {
7986 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
7987 // are set, but could expand this test to hit more cases.
7988 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
7989 "that do not have correct aspect bits sets.");
7990 VkResult err;
7991
7992 ASSERT_NO_FATAL_FAILURE(InitState());
7993 VkDescriptorPoolSize ds_type_count = {};
7994 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7995 ds_type_count.descriptorCount = 1;
7996
7997 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7998 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7999 ds_pool_ci.pNext = NULL;
8000 ds_pool_ci.maxSets = 5;
8001 ds_pool_ci.poolSizeCount = 1;
8002 ds_pool_ci.pPoolSizes = &ds_type_count;
8003
8004 VkDescriptorPool ds_pool;
8005 err =
8006 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8007 ASSERT_VK_SUCCESS(err);
8008
8009 VkDescriptorSetLayoutBinding dsl_binding = {};
8010 dsl_binding.binding = 0;
8011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8012 dsl_binding.descriptorCount = 1;
8013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8014 dsl_binding.pImmutableSamplers = NULL;
8015
8016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8017 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8018 ds_layout_ci.pNext = NULL;
8019 ds_layout_ci.bindingCount = 1;
8020 ds_layout_ci.pBindings = &dsl_binding;
8021 VkDescriptorSetLayout ds_layout;
8022 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8023 &ds_layout);
8024 ASSERT_VK_SUCCESS(err);
8025
8026 VkDescriptorSet descriptor_set = {};
8027 VkDescriptorSetAllocateInfo alloc_info = {};
8028 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8029 alloc_info.descriptorSetCount = 1;
8030 alloc_info.descriptorPool = ds_pool;
8031 alloc_info.pSetLayouts = &ds_layout;
8032 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8033 &descriptor_set);
8034 ASSERT_VK_SUCCESS(err);
8035
8036 // Create an image to be used for invalid updates
8037 VkImageCreateInfo image_ci = {};
8038 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8039 image_ci.imageType = VK_IMAGE_TYPE_2D;
8040 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8041 image_ci.extent.width = 64;
8042 image_ci.extent.height = 64;
8043 image_ci.extent.depth = 1;
8044 image_ci.mipLevels = 1;
8045 image_ci.arrayLayers = 1;
8046 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8047 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8048 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8049 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8050 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8051 VkImage image;
8052 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8053 ASSERT_VK_SUCCESS(err);
8054 // Bind memory to image
8055 VkMemoryRequirements mem_reqs;
8056 VkDeviceMemory image_mem;
8057 bool pass;
8058 VkMemoryAllocateInfo mem_alloc = {};
8059 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8060 mem_alloc.pNext = NULL;
8061 mem_alloc.allocationSize = 0;
8062 mem_alloc.memoryTypeIndex = 0;
8063 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8064 mem_alloc.allocationSize = mem_reqs.size;
8065 pass =
8066 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8067 ASSERT_TRUE(pass);
8068 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8069 ASSERT_VK_SUCCESS(err);
8070 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8071 ASSERT_VK_SUCCESS(err);
8072 // Now create view for image
8073 VkImageViewCreateInfo image_view_ci = {};
8074 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8075 image_view_ci.image = image;
8076 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8077 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8078 image_view_ci.subresourceRange.layerCount = 1;
8079 image_view_ci.subresourceRange.baseArrayLayer = 0;
8080 image_view_ci.subresourceRange.levelCount = 1;
8081 // Setting both depth & stencil aspect bits is illegal for descriptor
8082 image_view_ci.subresourceRange.aspectMask =
8083 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8084
8085 VkImageView image_view;
8086 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8087 &image_view);
8088 ASSERT_VK_SUCCESS(err);
8089
8090 VkDescriptorImageInfo img_info = {};
8091 img_info.imageView = image_view;
8092 VkWriteDescriptorSet descriptor_write = {};
8093 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8094 descriptor_write.dstBinding = 0;
8095 descriptor_write.descriptorCount = 1;
8096 descriptor_write.pTexelBufferView = NULL;
8097 descriptor_write.pBufferInfo = NULL;
8098 descriptor_write.pImageInfo = &img_info;
8099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8100 descriptor_write.dstSet = descriptor_set;
8101 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8102 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8104 error_msg);
8105
8106 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8107
8108 m_errorMonitor->VerifyFound();
8109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8110 vkDestroyImage(m_device->device(), image, NULL);
8111 vkFreeMemory(m_device->device(), image_mem, NULL);
8112 vkDestroyImageView(m_device->device(), image_view, NULL);
8113 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8114 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8115}
8116
Karl Schultz6addd812016-02-02 17:17:23 -07008117TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008118 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008119 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008120
Karl Schultz6addd812016-02-02 17:17:23 -07008121 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008122 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8123 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8124 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008125
Tobin Ehlis3b780662015-05-28 12:11:26 -06008126 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008127 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8130 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008131
8132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8134 ds_pool_ci.pNext = NULL;
8135 ds_pool_ci.maxSets = 1;
8136 ds_pool_ci.poolSizeCount = 1;
8137 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008138
Tobin Ehlis3b780662015-05-28 12:11:26 -06008139 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008140 err =
8141 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008142 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008143 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008144 dsl_binding.binding = 0;
8145 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8146 dsl_binding.descriptorCount = 1;
8147 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8148 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008149
Tony Barboureb254902015-07-15 12:50:33 -06008150 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008151 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8152 ds_layout_ci.pNext = NULL;
8153 ds_layout_ci.bindingCount = 1;
8154 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008155
Tobin Ehlis3b780662015-05-28 12:11:26 -06008156 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008157 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8158 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008159 ASSERT_VK_SUCCESS(err);
8160
8161 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008162 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008164 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008165 alloc_info.descriptorPool = ds_pool;
8166 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8168 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008169 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008170
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008171 VkSamplerCreateInfo sampler_ci = {};
8172 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8173 sampler_ci.pNext = NULL;
8174 sampler_ci.magFilter = VK_FILTER_NEAREST;
8175 sampler_ci.minFilter = VK_FILTER_NEAREST;
8176 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8177 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8178 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8179 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8180 sampler_ci.mipLodBias = 1.0;
8181 sampler_ci.anisotropyEnable = VK_FALSE;
8182 sampler_ci.maxAnisotropy = 1;
8183 sampler_ci.compareEnable = VK_FALSE;
8184 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8185 sampler_ci.minLod = 1.0;
8186 sampler_ci.maxLod = 1.0;
8187 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8188 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8189 VkSampler sampler;
8190 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8191 ASSERT_VK_SUCCESS(err);
8192
8193 VkDescriptorImageInfo info = {};
8194 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008195
8196 VkWriteDescriptorSet descriptor_write;
8197 memset(&descriptor_write, 0, sizeof(descriptor_write));
8198 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008199 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008200 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008201 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008202 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008203 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008204
8205 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8206
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008207 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008208
Chia-I Wuf7458c52015-10-26 21:10:41 +08008209 vkDestroySampler(m_device->device(), sampler, NULL);
8210 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8211 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008212}
8213
Karl Schultz6addd812016-02-02 17:17:23 -07008214TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008215 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008216 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008217
Karl Schultz6addd812016-02-02 17:17:23 -07008218 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008219 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8220 " binding #0 with 1 total descriptors but update of 1 descriptors "
8221 "starting at binding offset of 0 combined with update array element "
8222 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008223
Tobin Ehlis3b780662015-05-28 12:11:26 -06008224 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008225 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008226 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008227 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8228 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008229
8230 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008231 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8232 ds_pool_ci.pNext = NULL;
8233 ds_pool_ci.maxSets = 1;
8234 ds_pool_ci.poolSizeCount = 1;
8235 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008236
Tobin Ehlis3b780662015-05-28 12:11:26 -06008237 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008238 err =
8239 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008240 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008241
Tony Barboureb254902015-07-15 12:50:33 -06008242 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008243 dsl_binding.binding = 0;
8244 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8245 dsl_binding.descriptorCount = 1;
8246 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8247 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008248
8249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8251 ds_layout_ci.pNext = NULL;
8252 ds_layout_ci.bindingCount = 1;
8253 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008254
Tobin Ehlis3b780662015-05-28 12:11:26 -06008255 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8257 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008258 ASSERT_VK_SUCCESS(err);
8259
8260 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008261 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008262 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008263 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008264 alloc_info.descriptorPool = ds_pool;
8265 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008266 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8267 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008268 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008269
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008270 // Correctly update descriptor to avoid "NOT_UPDATED" error
8271 VkDescriptorBufferInfo buff_info = {};
8272 buff_info.buffer =
8273 VkBuffer(0); // Don't care about buffer handle for this test
8274 buff_info.offset = 0;
8275 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008276
8277 VkWriteDescriptorSet descriptor_write;
8278 memset(&descriptor_write, 0, sizeof(descriptor_write));
8279 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008280 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008281 descriptor_write.dstArrayElement =
8282 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008283 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8285 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008286
8287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8288
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008289 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008290
Chia-I Wuf7458c52015-10-26 21:10:41 +08008291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008293}
8294
Karl Schultz6addd812016-02-02 17:17:23 -07008295TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8296 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8297 // index 2
8298 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008299
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8301 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008302
Tobin Ehlis3b780662015-05-28 12:11:26 -06008303 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008304 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8307 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008308
8309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8311 ds_pool_ci.pNext = NULL;
8312 ds_pool_ci.maxSets = 1;
8313 ds_pool_ci.poolSizeCount = 1;
8314 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008315
Tobin Ehlis3b780662015-05-28 12:11:26 -06008316 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008317 err =
8318 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008319 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008320
Tony Barboureb254902015-07-15 12:50:33 -06008321 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008322 dsl_binding.binding = 0;
8323 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8324 dsl_binding.descriptorCount = 1;
8325 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8326 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008327
8328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8330 ds_layout_ci.pNext = NULL;
8331 ds_layout_ci.bindingCount = 1;
8332 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008333 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8335 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008336 ASSERT_VK_SUCCESS(err);
8337
8338 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008339 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008341 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008342 alloc_info.descriptorPool = ds_pool;
8343 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8345 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008347
Tony Barboureb254902015-07-15 12:50:33 -06008348 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008349 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8350 sampler_ci.pNext = NULL;
8351 sampler_ci.magFilter = VK_FILTER_NEAREST;
8352 sampler_ci.minFilter = VK_FILTER_NEAREST;
8353 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8354 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8355 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8356 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8357 sampler_ci.mipLodBias = 1.0;
8358 sampler_ci.anisotropyEnable = VK_FALSE;
8359 sampler_ci.maxAnisotropy = 1;
8360 sampler_ci.compareEnable = VK_FALSE;
8361 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8362 sampler_ci.minLod = 1.0;
8363 sampler_ci.maxLod = 1.0;
8364 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8365 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008366
Tobin Ehlis3b780662015-05-28 12:11:26 -06008367 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008368 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008369 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008370
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008371 VkDescriptorImageInfo info = {};
8372 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008373
8374 VkWriteDescriptorSet descriptor_write;
8375 memset(&descriptor_write, 0, sizeof(descriptor_write));
8376 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008377 descriptor_write.dstSet = descriptorSet;
8378 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008379 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008380 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008381 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008382 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008383
8384 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008386 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008387
Chia-I Wuf7458c52015-10-26 21:10:41 +08008388 vkDestroySampler(m_device->device(), sampler, NULL);
8389 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008391}
8392
Karl Schultz6addd812016-02-02 17:17:23 -07008393TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8394 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8395 // types
8396 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008397
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008399 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008400
Tobin Ehlis3b780662015-05-28 12:11:26 -06008401 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008402
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008403 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008404 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8405 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008406
8407 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008408 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8409 ds_pool_ci.pNext = NULL;
8410 ds_pool_ci.maxSets = 1;
8411 ds_pool_ci.poolSizeCount = 1;
8412 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008413
Tobin Ehlis3b780662015-05-28 12:11:26 -06008414 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008415 err =
8416 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008417 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008418 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008419 dsl_binding.binding = 0;
8420 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8421 dsl_binding.descriptorCount = 1;
8422 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8423 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008424
Tony Barboureb254902015-07-15 12:50:33 -06008425 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008426 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8427 ds_layout_ci.pNext = NULL;
8428 ds_layout_ci.bindingCount = 1;
8429 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008430
Tobin Ehlis3b780662015-05-28 12:11:26 -06008431 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8433 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008434 ASSERT_VK_SUCCESS(err);
8435
8436 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008437 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008439 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008440 alloc_info.descriptorPool = ds_pool;
8441 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8443 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008444 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008445
Tony Barboureb254902015-07-15 12:50:33 -06008446 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008447 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8448 sampler_ci.pNext = NULL;
8449 sampler_ci.magFilter = VK_FILTER_NEAREST;
8450 sampler_ci.minFilter = VK_FILTER_NEAREST;
8451 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8452 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8453 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8454 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8455 sampler_ci.mipLodBias = 1.0;
8456 sampler_ci.anisotropyEnable = VK_FALSE;
8457 sampler_ci.maxAnisotropy = 1;
8458 sampler_ci.compareEnable = VK_FALSE;
8459 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8460 sampler_ci.minLod = 1.0;
8461 sampler_ci.maxLod = 1.0;
8462 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8463 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008464 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008465 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008466 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008467
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008468 VkDescriptorImageInfo info = {};
8469 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008470
8471 VkWriteDescriptorSet descriptor_write;
8472 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008473 descriptor_write.sType =
8474 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008475 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008476 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008477 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008478 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008479 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008480
8481 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008483 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008484
Chia-I Wuf7458c52015-10-26 21:10:41 +08008485 vkDestroySampler(m_device->device(), sampler, NULL);
8486 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8487 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008488}
8489
Karl Schultz6addd812016-02-02 17:17:23 -07008490TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008491 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008492 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008493
Karl Schultz6addd812016-02-02 17:17:23 -07008494 m_errorMonitor->SetDesiredFailureMsg(
8495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008496 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008497
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008498 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008499 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8500 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008501 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008502 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8503 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008504
8505 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008506 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8507 ds_pool_ci.pNext = NULL;
8508 ds_pool_ci.maxSets = 1;
8509 ds_pool_ci.poolSizeCount = 1;
8510 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008511
8512 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008513 err =
8514 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008515 ASSERT_VK_SUCCESS(err);
8516
8517 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008518 dsl_binding.binding = 0;
8519 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8520 dsl_binding.descriptorCount = 1;
8521 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8522 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008523
8524 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008525 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8526 ds_layout_ci.pNext = NULL;
8527 ds_layout_ci.bindingCount = 1;
8528 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008529 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008530 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8531 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008532 ASSERT_VK_SUCCESS(err);
8533
8534 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008535 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008536 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008537 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008538 alloc_info.descriptorPool = ds_pool;
8539 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008540 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8541 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008542 ASSERT_VK_SUCCESS(err);
8543
Karl Schultz6addd812016-02-02 17:17:23 -07008544 VkSampler sampler =
8545 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008546
8547 VkDescriptorImageInfo descriptor_info;
8548 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8549 descriptor_info.sampler = sampler;
8550
8551 VkWriteDescriptorSet descriptor_write;
8552 memset(&descriptor_write, 0, sizeof(descriptor_write));
8553 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008554 descriptor_write.dstSet = descriptorSet;
8555 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008556 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008557 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8558 descriptor_write.pImageInfo = &descriptor_info;
8559
8560 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8561
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008562 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008563
Chia-I Wuf7458c52015-10-26 21:10:41 +08008564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8565 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008566}
8567
Karl Schultz6addd812016-02-02 17:17:23 -07008568TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8569 // Create a single combined Image/Sampler descriptor and send it an invalid
8570 // imageView
8571 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008572
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8574 "Attempted write update to combined "
8575 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008576 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008577
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008578 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008579 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008580 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8581 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008582
8583 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008584 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8585 ds_pool_ci.pNext = NULL;
8586 ds_pool_ci.maxSets = 1;
8587 ds_pool_ci.poolSizeCount = 1;
8588 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008589
8590 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008591 err =
8592 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008593 ASSERT_VK_SUCCESS(err);
8594
8595 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008596 dsl_binding.binding = 0;
8597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8598 dsl_binding.descriptorCount = 1;
8599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8600 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008601
8602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8604 ds_layout_ci.pNext = NULL;
8605 ds_layout_ci.bindingCount = 1;
8606 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008607 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008608 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8609 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008610 ASSERT_VK_SUCCESS(err);
8611
8612 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008613 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008614 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008615 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008616 alloc_info.descriptorPool = ds_pool;
8617 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008618 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8619 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008620 ASSERT_VK_SUCCESS(err);
8621
8622 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008623 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8624 sampler_ci.pNext = NULL;
8625 sampler_ci.magFilter = VK_FILTER_NEAREST;
8626 sampler_ci.minFilter = VK_FILTER_NEAREST;
8627 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8628 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8629 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8630 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8631 sampler_ci.mipLodBias = 1.0;
8632 sampler_ci.anisotropyEnable = VK_FALSE;
8633 sampler_ci.maxAnisotropy = 1;
8634 sampler_ci.compareEnable = VK_FALSE;
8635 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8636 sampler_ci.minLod = 1.0;
8637 sampler_ci.maxLod = 1.0;
8638 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8639 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008640
8641 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008642 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008643 ASSERT_VK_SUCCESS(err);
8644
Karl Schultz6addd812016-02-02 17:17:23 -07008645 VkImageView view =
8646 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008647
8648 VkDescriptorImageInfo descriptor_info;
8649 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8650 descriptor_info.sampler = sampler;
8651 descriptor_info.imageView = view;
8652
8653 VkWriteDescriptorSet descriptor_write;
8654 memset(&descriptor_write, 0, sizeof(descriptor_write));
8655 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008656 descriptor_write.dstSet = descriptorSet;
8657 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008658 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008659 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8660 descriptor_write.pImageInfo = &descriptor_info;
8661
8662 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008664 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008665
Chia-I Wuf7458c52015-10-26 21:10:41 +08008666 vkDestroySampler(m_device->device(), sampler, NULL);
8667 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8668 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008669}
8670
Karl Schultz6addd812016-02-02 17:17:23 -07008671TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8672 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8673 // into the other
8674 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008675
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8677 " binding #1 with type "
8678 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8679 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008680
Tobin Ehlis04356f92015-10-27 16:35:27 -06008681 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008682 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008683 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008684 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8685 ds_type_count[0].descriptorCount = 1;
8686 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8687 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008688
8689 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008690 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8691 ds_pool_ci.pNext = NULL;
8692 ds_pool_ci.maxSets = 1;
8693 ds_pool_ci.poolSizeCount = 2;
8694 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008695
8696 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008697 err =
8698 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008699 ASSERT_VK_SUCCESS(err);
8700 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008701 dsl_binding[0].binding = 0;
8702 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8703 dsl_binding[0].descriptorCount = 1;
8704 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8705 dsl_binding[0].pImmutableSamplers = NULL;
8706 dsl_binding[1].binding = 1;
8707 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8708 dsl_binding[1].descriptorCount = 1;
8709 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8710 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008711
8712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8714 ds_layout_ci.pNext = NULL;
8715 ds_layout_ci.bindingCount = 2;
8716 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008717
8718 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008719 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8720 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008721 ASSERT_VK_SUCCESS(err);
8722
8723 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008724 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008725 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008726 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008727 alloc_info.descriptorPool = ds_pool;
8728 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008729 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8730 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008731 ASSERT_VK_SUCCESS(err);
8732
8733 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008734 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8735 sampler_ci.pNext = NULL;
8736 sampler_ci.magFilter = VK_FILTER_NEAREST;
8737 sampler_ci.minFilter = VK_FILTER_NEAREST;
8738 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8739 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8740 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8741 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8742 sampler_ci.mipLodBias = 1.0;
8743 sampler_ci.anisotropyEnable = VK_FALSE;
8744 sampler_ci.maxAnisotropy = 1;
8745 sampler_ci.compareEnable = VK_FALSE;
8746 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8747 sampler_ci.minLod = 1.0;
8748 sampler_ci.maxLod = 1.0;
8749 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8750 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008751
8752 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008753 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008754 ASSERT_VK_SUCCESS(err);
8755
8756 VkDescriptorImageInfo info = {};
8757 info.sampler = sampler;
8758
8759 VkWriteDescriptorSet descriptor_write;
8760 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8761 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008762 descriptor_write.dstSet = descriptorSet;
8763 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008764 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008765 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8766 descriptor_write.pImageInfo = &info;
8767 // This write update should succeed
8768 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8769 // Now perform a copy update that fails due to type mismatch
8770 VkCopyDescriptorSet copy_ds_update;
8771 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8772 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8773 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008774 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008775 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008776 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008777 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008778 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008780 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008781 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008782 m_errorMonitor->SetDesiredFailureMsg(
8783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008784 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008785 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8786 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8787 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008788 copy_ds_update.srcBinding =
8789 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008790 copy_ds_update.dstSet = descriptorSet;
8791 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008792 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008793 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008795 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008796
Tobin Ehlis04356f92015-10-27 16:35:27 -06008797 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008798 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008799 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8800 "update array offset of 0 and update of "
8801 "5 descriptors oversteps total number "
8802 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008803
Tobin Ehlis04356f92015-10-27 16:35:27 -06008804 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8805 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8806 copy_ds_update.srcSet = descriptorSet;
8807 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008808 copy_ds_update.dstSet = descriptorSet;
8809 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008810 copy_ds_update.descriptorCount =
8811 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008812 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8813
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008814 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008815
Chia-I Wuf7458c52015-10-26 21:10:41 +08008816 vkDestroySampler(m_device->device(), sampler, NULL);
8817 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8818 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008819}
8820
Karl Schultz6addd812016-02-02 17:17:23 -07008821TEST_F(VkLayerTest, NumSamplesMismatch) {
8822 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8823 // sampleCount
8824 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008825
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008827 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008828
Tobin Ehlis3b780662015-05-28 12:11:26 -06008829 ASSERT_NO_FATAL_FAILURE(InitState());
8830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008831 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008832 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008833 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008834
8835 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008836 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8837 ds_pool_ci.pNext = NULL;
8838 ds_pool_ci.maxSets = 1;
8839 ds_pool_ci.poolSizeCount = 1;
8840 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008841
Tobin Ehlis3b780662015-05-28 12:11:26 -06008842 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008843 err =
8844 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008845 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008846
Tony Barboureb254902015-07-15 12:50:33 -06008847 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008848 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008850 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008853
Tony Barboureb254902015-07-15 12:50:33 -06008854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8856 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008857 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008858 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008859
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8862 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008863 ASSERT_VK_SUCCESS(err);
8864
8865 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008866 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008868 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008869 alloc_info.descriptorPool = ds_pool;
8870 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8872 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008873 ASSERT_VK_SUCCESS(err);
8874
Tony Barboureb254902015-07-15 12:50:33 -06008875 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008876 pipe_ms_state_ci.sType =
8877 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8878 pipe_ms_state_ci.pNext = NULL;
8879 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8880 pipe_ms_state_ci.sampleShadingEnable = 0;
8881 pipe_ms_state_ci.minSampleShading = 1.0;
8882 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008883
Tony Barboureb254902015-07-15 12:50:33 -06008884 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008885 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8886 pipeline_layout_ci.pNext = NULL;
8887 pipeline_layout_ci.setLayoutCount = 1;
8888 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008889
8890 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008891 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8892 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008893 ASSERT_VK_SUCCESS(err);
8894
Karl Schultz6addd812016-02-02 17:17:23 -07008895 VkShaderObj vs(m_device, bindStateVertShaderText,
8896 VK_SHADER_STAGE_VERTEX_BIT, this);
8897 VkShaderObj fs(m_device, bindStateFragShaderText,
8898 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008899 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008900 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008901 VkPipelineObj pipe(m_device);
8902 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008903 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008904 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008905 pipe.SetMSAA(&pipe_ms_state_ci);
8906 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008907
Tony Barbourfe3351b2015-07-28 10:17:20 -06008908 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008909 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8910 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008911
Mark Young29927482016-05-04 14:38:51 -06008912 // Render triangle (the error should trigger on the attempt to draw).
8913 Draw(3, 1, 0, 0);
8914
8915 // Finalize recording of the command buffer
8916 EndCommandBuffer();
8917
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008918 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008919
Chia-I Wuf7458c52015-10-26 21:10:41 +08008920 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8921 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8922 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008923}
Mark Young29927482016-05-04 14:38:51 -06008924
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008925TEST_F(VkLayerTest, RenderPassIncompatible) {
8926 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8927 "Initial case is drawing with an active renderpass that's "
8928 "not compatible with the bound PSO's creation renderpass");
8929 VkResult err;
8930
8931 ASSERT_NO_FATAL_FAILURE(InitState());
8932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8933
8934 VkDescriptorSetLayoutBinding dsl_binding = {};
8935 dsl_binding.binding = 0;
8936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8937 dsl_binding.descriptorCount = 1;
8938 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8939 dsl_binding.pImmutableSamplers = NULL;
8940
8941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8943 ds_layout_ci.pNext = NULL;
8944 ds_layout_ci.bindingCount = 1;
8945 ds_layout_ci.pBindings = &dsl_binding;
8946
8947 VkDescriptorSetLayout ds_layout;
8948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8949 &ds_layout);
8950 ASSERT_VK_SUCCESS(err);
8951
8952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8954 pipeline_layout_ci.pNext = NULL;
8955 pipeline_layout_ci.setLayoutCount = 1;
8956 pipeline_layout_ci.pSetLayouts = &ds_layout;
8957
8958 VkPipelineLayout pipeline_layout;
8959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8960 &pipeline_layout);
8961 ASSERT_VK_SUCCESS(err);
8962
8963 VkShaderObj vs(m_device, bindStateVertShaderText,
8964 VK_SHADER_STAGE_VERTEX_BIT, this);
8965 VkShaderObj fs(m_device, bindStateFragShaderText,
8966 VK_SHADER_STAGE_FRAGMENT_BIT,
8967 this); // We shouldn't need a fragment shader
8968 // but add it to be able to run on more devices
8969 // Create a renderpass that will be incompatible with default renderpass
8970 VkAttachmentReference attach = {};
8971 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8972 VkAttachmentReference color_att = {};
8973 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8974 VkSubpassDescription subpass = {};
8975 subpass.inputAttachmentCount = 1;
8976 subpass.pInputAttachments = &attach;
8977 subpass.colorAttachmentCount = 1;
8978 subpass.pColorAttachments = &color_att;
8979 VkRenderPassCreateInfo rpci = {};
8980 rpci.subpassCount = 1;
8981 rpci.pSubpasses = &subpass;
8982 rpci.attachmentCount = 1;
8983 VkAttachmentDescription attach_desc = {};
8984 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06008985 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
8986 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008987 rpci.pAttachments = &attach_desc;
8988 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8989 VkRenderPass rp;
8990 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8991 VkPipelineObj pipe(m_device);
8992 pipe.AddShader(&vs);
8993 pipe.AddShader(&fs);
8994 pipe.AddColorAttachment();
8995 VkViewport view_port = {};
8996 m_viewports.push_back(view_port);
8997 pipe.SetViewport(m_viewports);
8998 VkRect2D rect = {};
8999 m_scissors.push_back(rect);
9000 pipe.SetScissor(m_scissors);
9001 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9002
9003 VkCommandBufferInheritanceInfo cbii = {};
9004 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9005 cbii.renderPass = rp;
9006 cbii.subpass = 0;
9007 VkCommandBufferBeginInfo cbbi = {};
9008 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9009 cbbi.pInheritanceInfo = &cbii;
9010 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9011 VkRenderPassBeginInfo rpbi = {};
9012 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9013 rpbi.framebuffer = m_framebuffer;
9014 rpbi.renderPass = rp;
9015 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
9016 VK_SUBPASS_CONTENTS_INLINE);
9017 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9018 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9019
9020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9021 " is incompatible w/ gfx pipeline ");
9022 // Render triangle (the error should trigger on the attempt to draw).
9023 Draw(3, 1, 0, 0);
9024
9025 // Finalize recording of the command buffer
9026 EndCommandBuffer();
9027
9028 m_errorMonitor->VerifyFound();
9029
9030 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9031 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9032 vkDestroyRenderPass(m_device->device(), rp, NULL);
9033}
9034
Mark Youngc89c6312016-03-31 16:03:20 -06009035TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9036 // Create Pipeline where the number of blend attachments doesn't match the
9037 // number of color attachments. In this case, we don't add any color
9038 // blend attachments even though we have a color attachment.
9039 VkResult err;
9040
9041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06009042 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009043
9044 ASSERT_NO_FATAL_FAILURE(InitState());
9045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9046 VkDescriptorPoolSize ds_type_count = {};
9047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9048 ds_type_count.descriptorCount = 1;
9049
9050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9052 ds_pool_ci.pNext = NULL;
9053 ds_pool_ci.maxSets = 1;
9054 ds_pool_ci.poolSizeCount = 1;
9055 ds_pool_ci.pPoolSizes = &ds_type_count;
9056
9057 VkDescriptorPool ds_pool;
9058 err =
9059 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9060 ASSERT_VK_SUCCESS(err);
9061
9062 VkDescriptorSetLayoutBinding dsl_binding = {};
9063 dsl_binding.binding = 0;
9064 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9065 dsl_binding.descriptorCount = 1;
9066 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9067 dsl_binding.pImmutableSamplers = NULL;
9068
9069 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9070 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9071 ds_layout_ci.pNext = NULL;
9072 ds_layout_ci.bindingCount = 1;
9073 ds_layout_ci.pBindings = &dsl_binding;
9074
9075 VkDescriptorSetLayout ds_layout;
9076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9077 &ds_layout);
9078 ASSERT_VK_SUCCESS(err);
9079
9080 VkDescriptorSet descriptorSet;
9081 VkDescriptorSetAllocateInfo alloc_info = {};
9082 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9083 alloc_info.descriptorSetCount = 1;
9084 alloc_info.descriptorPool = ds_pool;
9085 alloc_info.pSetLayouts = &ds_layout;
9086 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9087 &descriptorSet);
9088 ASSERT_VK_SUCCESS(err);
9089
9090 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9091 pipe_ms_state_ci.sType =
9092 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9093 pipe_ms_state_ci.pNext = NULL;
9094 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9095 pipe_ms_state_ci.sampleShadingEnable = 0;
9096 pipe_ms_state_ci.minSampleShading = 1.0;
9097 pipe_ms_state_ci.pSampleMask = NULL;
9098
9099 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9100 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9101 pipeline_layout_ci.pNext = NULL;
9102 pipeline_layout_ci.setLayoutCount = 1;
9103 pipeline_layout_ci.pSetLayouts = &ds_layout;
9104
9105 VkPipelineLayout pipeline_layout;
9106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9107 &pipeline_layout);
9108 ASSERT_VK_SUCCESS(err);
9109
9110 VkShaderObj vs(m_device, bindStateVertShaderText,
9111 VK_SHADER_STAGE_VERTEX_BIT, this);
9112 VkShaderObj fs(m_device, bindStateFragShaderText,
9113 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009114 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009115 // but add it to be able to run on more devices
9116 VkPipelineObj pipe(m_device);
9117 pipe.AddShader(&vs);
9118 pipe.AddShader(&fs);
9119 pipe.SetMSAA(&pipe_ms_state_ci);
9120 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9121
9122 BeginCommandBuffer();
9123 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9124 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9125
Mark Young29927482016-05-04 14:38:51 -06009126 // Render triangle (the error should trigger on the attempt to draw).
9127 Draw(3, 1, 0, 0);
9128
9129 // Finalize recording of the command buffer
9130 EndCommandBuffer();
9131
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009132 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009133
9134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9137}
Mark Young29927482016-05-04 14:38:51 -06009138
Mark Muellerd4914412016-06-13 17:52:06 -06009139TEST_F(VkLayerTest, MissingClearAttachment) {
9140 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9141 "structure passed to vkCmdClearAttachments");
9142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9143 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9144 "reference array of active subpass 0");
9145
9146 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9147 m_errorMonitor->VerifyFound();
9148}
9149
Karl Schultz6addd812016-02-02 17:17:23 -07009150TEST_F(VkLayerTest, ClearCmdNoDraw) {
9151 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9152 // to issuing a Draw
9153 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009154
Karl Schultz6addd812016-02-02 17:17:23 -07009155 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009156 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009157 "vkCmdClearAttachments() issued on CB object ");
9158
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009159 ASSERT_NO_FATAL_FAILURE(InitState());
9160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009161
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009162 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009163 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9164 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009165
9166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9168 ds_pool_ci.pNext = NULL;
9169 ds_pool_ci.maxSets = 1;
9170 ds_pool_ci.poolSizeCount = 1;
9171 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009172
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009173 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009174 err =
9175 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009176 ASSERT_VK_SUCCESS(err);
9177
Tony Barboureb254902015-07-15 12:50:33 -06009178 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009179 dsl_binding.binding = 0;
9180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9181 dsl_binding.descriptorCount = 1;
9182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9183 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009184
Tony Barboureb254902015-07-15 12:50:33 -06009185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9187 ds_layout_ci.pNext = NULL;
9188 ds_layout_ci.bindingCount = 1;
9189 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009190
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009191 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009192 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9193 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009194 ASSERT_VK_SUCCESS(err);
9195
9196 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009197 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009199 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009200 alloc_info.descriptorPool = ds_pool;
9201 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9203 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009204 ASSERT_VK_SUCCESS(err);
9205
Tony Barboureb254902015-07-15 12:50:33 -06009206 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009207 pipe_ms_state_ci.sType =
9208 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9209 pipe_ms_state_ci.pNext = NULL;
9210 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9211 pipe_ms_state_ci.sampleShadingEnable = 0;
9212 pipe_ms_state_ci.minSampleShading = 1.0;
9213 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009214
Tony Barboureb254902015-07-15 12:50:33 -06009215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9217 pipeline_layout_ci.pNext = NULL;
9218 pipeline_layout_ci.setLayoutCount = 1;
9219 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009220
9221 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009222 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9223 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009224 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009225
Karl Schultz6addd812016-02-02 17:17:23 -07009226 VkShaderObj vs(m_device, bindStateVertShaderText,
9227 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009228 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009229 // on more devices
9230 VkShaderObj fs(m_device, bindStateFragShaderText,
9231 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009232
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009233 VkPipelineObj pipe(m_device);
9234 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009235 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009236 pipe.SetMSAA(&pipe_ms_state_ci);
9237 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009238
9239 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009240
Karl Schultz6addd812016-02-02 17:17:23 -07009241 // Main thing we care about for this test is that the VkImage obj we're
9242 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009243 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009244 VkClearAttachment color_attachment;
9245 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9246 color_attachment.clearValue.color.float32[0] = 1.0;
9247 color_attachment.clearValue.color.float32[1] = 1.0;
9248 color_attachment.clearValue.color.float32[2] = 1.0;
9249 color_attachment.clearValue.color.float32[3] = 1.0;
9250 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009251 VkClearRect clear_rect = {
9252 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009253
Karl Schultz6addd812016-02-02 17:17:23 -07009254 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9255 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009258
Chia-I Wuf7458c52015-10-26 21:10:41 +08009259 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9260 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9261 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009262}
9263
Karl Schultz6addd812016-02-02 17:17:23 -07009264TEST_F(VkLayerTest, VtxBufferBadIndex) {
9265 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009266
Karl Schultz6addd812016-02-02 17:17:23 -07009267 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009268 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009269 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009270
Tobin Ehlis502480b2015-06-24 15:53:07 -06009271 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009272 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009274
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009276 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9277 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009278
9279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9281 ds_pool_ci.pNext = NULL;
9282 ds_pool_ci.maxSets = 1;
9283 ds_pool_ci.poolSizeCount = 1;
9284 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009285
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009286 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009287 err =
9288 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009289 ASSERT_VK_SUCCESS(err);
9290
Tony Barboureb254902015-07-15 12:50:33 -06009291 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009292 dsl_binding.binding = 0;
9293 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9294 dsl_binding.descriptorCount = 1;
9295 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9296 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009297
Tony Barboureb254902015-07-15 12:50:33 -06009298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9300 ds_layout_ci.pNext = NULL;
9301 ds_layout_ci.bindingCount = 1;
9302 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009303
Tobin Ehlis502480b2015-06-24 15:53:07 -06009304 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9306 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009307 ASSERT_VK_SUCCESS(err);
9308
9309 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009310 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009311 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009312 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009313 alloc_info.descriptorPool = ds_pool;
9314 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009315 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9316 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009317 ASSERT_VK_SUCCESS(err);
9318
Tony Barboureb254902015-07-15 12:50:33 -06009319 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009320 pipe_ms_state_ci.sType =
9321 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9322 pipe_ms_state_ci.pNext = NULL;
9323 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9324 pipe_ms_state_ci.sampleShadingEnable = 0;
9325 pipe_ms_state_ci.minSampleShading = 1.0;
9326 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009327
Tony Barboureb254902015-07-15 12:50:33 -06009328 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9330 pipeline_layout_ci.pNext = NULL;
9331 pipeline_layout_ci.setLayoutCount = 1;
9332 pipeline_layout_ci.pSetLayouts = &ds_layout;
9333 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009334
Karl Schultz6addd812016-02-02 17:17:23 -07009335 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9336 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009337 ASSERT_VK_SUCCESS(err);
9338
Karl Schultz6addd812016-02-02 17:17:23 -07009339 VkShaderObj vs(m_device, bindStateVertShaderText,
9340 VK_SHADER_STAGE_VERTEX_BIT, this);
9341 VkShaderObj fs(m_device, bindStateFragShaderText,
9342 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009343 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009344 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009345 VkPipelineObj pipe(m_device);
9346 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009347 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009348 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009349 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009350 pipe.SetViewport(m_viewports);
9351 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009352 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009353
9354 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009355 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9356 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009357 // Don't care about actual data, just need to get to draw to flag error
9358 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009359 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9360 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009361 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009362 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009363
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009364 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009365
Chia-I Wuf7458c52015-10-26 21:10:41 +08009366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9367 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9368 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009369}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009370// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9371TEST_F(VkLayerTest, InvalidImageLayout) {
9372 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9373 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9374 "images in the wrong layout when they're copied or transitioned.");
9375 // 3 in ValidateCmdBufImageLayouts
9376 // * -1 Attempt to submit cmd buf w/ deleted image
9377 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9378 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9379 m_errorMonitor->SetDesiredFailureMsg(
9380 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9381 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9382
9383 ASSERT_NO_FATAL_FAILURE(InitState());
9384 // Create src & dst images to use for copy operations
9385 VkImage src_image;
9386 VkImage dst_image;
9387
9388 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9389 const int32_t tex_width = 32;
9390 const int32_t tex_height = 32;
9391
9392 VkImageCreateInfo image_create_info = {};
9393 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9394 image_create_info.pNext = NULL;
9395 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9396 image_create_info.format = tex_format;
9397 image_create_info.extent.width = tex_width;
9398 image_create_info.extent.height = tex_height;
9399 image_create_info.extent.depth = 1;
9400 image_create_info.mipLevels = 1;
9401 image_create_info.arrayLayers = 4;
9402 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9403 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9404 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9405 image_create_info.flags = 0;
9406
9407 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9408 ASSERT_VK_SUCCESS(err);
9409 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9410 ASSERT_VK_SUCCESS(err);
9411
9412 BeginCommandBuffer();
9413 VkImageCopy copyRegion;
9414 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9415 copyRegion.srcSubresource.mipLevel = 0;
9416 copyRegion.srcSubresource.baseArrayLayer = 0;
9417 copyRegion.srcSubresource.layerCount = 1;
9418 copyRegion.srcOffset.x = 0;
9419 copyRegion.srcOffset.y = 0;
9420 copyRegion.srcOffset.z = 0;
9421 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9422 copyRegion.dstSubresource.mipLevel = 0;
9423 copyRegion.dstSubresource.baseArrayLayer = 0;
9424 copyRegion.dstSubresource.layerCount = 1;
9425 copyRegion.dstOffset.x = 0;
9426 copyRegion.dstOffset.y = 0;
9427 copyRegion.dstOffset.z = 0;
9428 copyRegion.extent.width = 1;
9429 copyRegion.extent.height = 1;
9430 copyRegion.extent.depth = 1;
9431 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9432 m_errorMonitor->VerifyFound();
9433 // Now cause error due to src image layout changing
9434 m_errorMonitor->SetDesiredFailureMsg(
9435 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9436 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9437 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9438 m_errorMonitor->VerifyFound();
9439 // Final src error is due to bad layout type
9440 m_errorMonitor->SetDesiredFailureMsg(
9441 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9442 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9443 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9444 m_errorMonitor->VerifyFound();
9445 // Now verify same checks for dst
9446 m_errorMonitor->SetDesiredFailureMsg(
9447 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9448 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9449 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9450 m_errorMonitor->VerifyFound();
9451 // Now cause error due to src image layout changing
9452 m_errorMonitor->SetDesiredFailureMsg(
9453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9454 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9455 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9456 m_errorMonitor->VerifyFound();
9457 m_errorMonitor->SetDesiredFailureMsg(
9458 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9459 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9460 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9461 m_errorMonitor->VerifyFound();
9462 // Now cause error due to bad image layout transition in PipelineBarrier
9463 VkImageMemoryBarrier image_barrier[1] = {};
9464 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9465 image_barrier[0].image = src_image;
9466 image_barrier[0].subresourceRange.layerCount = 2;
9467 image_barrier[0].subresourceRange.levelCount = 2;
9468 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9469 m_errorMonitor->SetDesiredFailureMsg(
9470 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9471 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9472 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9473 m_errorMonitor->VerifyFound();
9474
9475 // Finally some layout errors at RenderPass create time
9476 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9477 VkAttachmentReference attach = {};
9478 // perf warning for GENERAL layout w/ non-DS input attachment
9479 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9480 VkSubpassDescription subpass = {};
9481 subpass.inputAttachmentCount = 1;
9482 subpass.pInputAttachments = &attach;
9483 VkRenderPassCreateInfo rpci = {};
9484 rpci.subpassCount = 1;
9485 rpci.pSubpasses = &subpass;
9486 rpci.attachmentCount = 1;
9487 VkAttachmentDescription attach_desc = {};
9488 attach_desc.format = VK_FORMAT_UNDEFINED;
9489 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009490 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009491 VkRenderPass rp;
9492 m_errorMonitor->SetDesiredFailureMsg(
9493 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9494 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9495 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9496 m_errorMonitor->VerifyFound();
9497 // error w/ non-general layout
9498 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9499
9500 m_errorMonitor->SetDesiredFailureMsg(
9501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9502 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9503 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9504 m_errorMonitor->VerifyFound();
9505 subpass.inputAttachmentCount = 0;
9506 subpass.colorAttachmentCount = 1;
9507 subpass.pColorAttachments = &attach;
9508 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9509 // perf warning for GENERAL layout on color attachment
9510 m_errorMonitor->SetDesiredFailureMsg(
9511 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9512 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9513 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9514 m_errorMonitor->VerifyFound();
9515 // error w/ non-color opt or GENERAL layout for color attachment
9516 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9517 m_errorMonitor->SetDesiredFailureMsg(
9518 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9519 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9520 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9521 m_errorMonitor->VerifyFound();
9522 subpass.colorAttachmentCount = 0;
9523 subpass.pDepthStencilAttachment = &attach;
9524 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9525 // perf warning for GENERAL layout on DS attachment
9526 m_errorMonitor->SetDesiredFailureMsg(
9527 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9528 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9529 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9530 m_errorMonitor->VerifyFound();
9531 // error w/ non-ds opt or GENERAL layout for color attachment
9532 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9533 m_errorMonitor->SetDesiredFailureMsg(
9534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9535 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9536 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9537 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009538 // For this error we need a valid renderpass so create default one
9539 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9540 attach.attachment = 0;
9541 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9542 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9543 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9544 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9545 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9546 // Can't do a CLEAR load on READ_ONLY initialLayout
9547 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9548 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9549 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9551 " with invalid first layout "
9552 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9553 "ONLY_OPTIMAL");
9554 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9555 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009556
9557 vkDestroyImage(m_device->device(), src_image, NULL);
9558 vkDestroyImage(m_device->device(), dst_image, NULL);
9559}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009560#endif // DRAW_STATE_TESTS
9561
Tobin Ehlis0788f522015-05-26 16:11:58 -06009562#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009563#if GTEST_IS_THREADSAFE
9564struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009565 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009566 VkEvent event;
9567 bool bailout;
9568};
9569
Karl Schultz6addd812016-02-02 17:17:23 -07009570extern "C" void *AddToCommandBuffer(void *arg) {
9571 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009572
Karl Schultz6addd812016-02-02 17:17:23 -07009573 for (int i = 0; i < 10000; i++) {
9574 vkCmdSetEvent(data->commandBuffer, data->event,
9575 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009576 if (data->bailout) {
9577 break;
9578 }
9579 }
9580 return NULL;
9581}
9582
Karl Schultz6addd812016-02-02 17:17:23 -07009583TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009584 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009585
Karl Schultz6addd812016-02-02 17:17:23 -07009586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9587 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009588
Mike Stroyanaccf7692015-05-12 16:00:45 -06009589 ASSERT_NO_FATAL_FAILURE(InitState());
9590 ASSERT_NO_FATAL_FAILURE(InitViewport());
9591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9592
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009593 // Calls AllocateCommandBuffers
9594 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009595
9596 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009597 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009598
9599 VkEventCreateInfo event_info;
9600 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009601 VkResult err;
9602
9603 memset(&event_info, 0, sizeof(event_info));
9604 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9605
Chia-I Wuf7458c52015-10-26 21:10:41 +08009606 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009607 ASSERT_VK_SUCCESS(err);
9608
Mike Stroyanaccf7692015-05-12 16:00:45 -06009609 err = vkResetEvent(device(), event);
9610 ASSERT_VK_SUCCESS(err);
9611
9612 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009613 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009614 data.event = event;
9615 data.bailout = false;
9616 m_errorMonitor->SetBailout(&data.bailout);
9617 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009618 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009619 // Add many entries to command buffer from this thread at the same time.
9620 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009621
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009622 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009623 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009624
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009625 m_errorMonitor->SetBailout(NULL);
9626
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009627 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009628
Chia-I Wuf7458c52015-10-26 21:10:41 +08009629 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009630}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009631#endif // GTEST_IS_THREADSAFE
9632#endif // THREADING_TESTS
9633
Chris Forbes9f7ff632015-05-25 11:13:08 +12009634#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009635TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009637 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009638
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009639 ASSERT_NO_FATAL_FAILURE(InitState());
9640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9641
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009642 VkShaderModule module;
9643 VkShaderModuleCreateInfo moduleCreateInfo;
9644 struct icd_spv_header spv;
9645
9646 spv.magic = ICD_SPV_MAGIC;
9647 spv.version = ICD_SPV_VERSION;
9648 spv.gen_magic = 0;
9649
9650 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9651 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009652 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009653 moduleCreateInfo.codeSize = 4;
9654 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009655 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009656
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009657 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009658}
9659
Karl Schultz6addd812016-02-02 17:17:23 -07009660TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009662 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009663
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009664 ASSERT_NO_FATAL_FAILURE(InitState());
9665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9666
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009667 VkShaderModule module;
9668 VkShaderModuleCreateInfo moduleCreateInfo;
9669 struct icd_spv_header spv;
9670
9671 spv.magic = ~ICD_SPV_MAGIC;
9672 spv.version = ICD_SPV_VERSION;
9673 spv.gen_magic = 0;
9674
9675 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9676 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009677 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009678 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9679 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009680 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009681
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009682 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009683}
9684
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009685#if 0
9686// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009687TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009689 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009690
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009691 ASSERT_NO_FATAL_FAILURE(InitState());
9692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9693
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009694 VkShaderModule module;
9695 VkShaderModuleCreateInfo moduleCreateInfo;
9696 struct icd_spv_header spv;
9697
9698 spv.magic = ICD_SPV_MAGIC;
9699 spv.version = ~ICD_SPV_VERSION;
9700 spv.gen_magic = 0;
9701
9702 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9703 moduleCreateInfo.pNext = NULL;
9704
Karl Schultz6addd812016-02-02 17:17:23 -07009705 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009706 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9707 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009708 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009710 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009711}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009712#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009713
Karl Schultz6addd812016-02-02 17:17:23 -07009714TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009716 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009717
Chris Forbes9f7ff632015-05-25 11:13:08 +12009718 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009720
9721 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009722 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009723 "\n"
9724 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009725 "out gl_PerVertex {\n"
9726 " vec4 gl_Position;\n"
9727 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009728 "void main(){\n"
9729 " gl_Position = vec4(1);\n"
9730 " x = 0;\n"
9731 "}\n";
9732 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009733 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009734 "\n"
9735 "layout(location=0) out vec4 color;\n"
9736 "void main(){\n"
9737 " color = vec4(1);\n"
9738 "}\n";
9739
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009742
9743 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009744 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009745 pipe.AddShader(&vs);
9746 pipe.AddShader(&fs);
9747
Chris Forbes9f7ff632015-05-25 11:13:08 +12009748 VkDescriptorSetObj descriptorSet(m_device);
9749 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009750 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009751
Tony Barbour5781e8f2015-08-04 16:23:11 -06009752 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009753
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009754 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009755}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009756
Karl Schultz6addd812016-02-02 17:17:23 -07009757TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009759 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009760
Chris Forbes59cb88d2015-05-25 11:13:13 +12009761 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009763
9764 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009765 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009766 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009767 "out gl_PerVertex {\n"
9768 " vec4 gl_Position;\n"
9769 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009770 "void main(){\n"
9771 " gl_Position = vec4(1);\n"
9772 "}\n";
9773 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009774 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009775 "\n"
9776 "layout(location=0) in float x;\n"
9777 "layout(location=0) out vec4 color;\n"
9778 "void main(){\n"
9779 " color = vec4(x);\n"
9780 "}\n";
9781
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009784
9785 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009786 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009787 pipe.AddShader(&vs);
9788 pipe.AddShader(&fs);
9789
Chris Forbes59cb88d2015-05-25 11:13:13 +12009790 VkDescriptorSetObj descriptorSet(m_device);
9791 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009792 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009793
Tony Barbour5781e8f2015-08-04 16:23:11 -06009794 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009796 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009797}
9798
Karl Schultz6addd812016-02-02 17:17:23 -07009799TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009801 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009802
9803 ASSERT_NO_FATAL_FAILURE(InitState());
9804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9805
9806 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009807 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009808 "\n"
9809 "out gl_PerVertex {\n"
9810 " vec4 gl_Position;\n"
9811 "};\n"
9812 "void main(){\n"
9813 " gl_Position = vec4(1);\n"
9814 "}\n";
9815 char const *fsSource =
9816 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009817 "\n"
9818 "in block { layout(location=0) float x; } ins;\n"
9819 "layout(location=0) out vec4 color;\n"
9820 "void main(){\n"
9821 " color = vec4(ins.x);\n"
9822 "}\n";
9823
9824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9826
9827 VkPipelineObj pipe(m_device);
9828 pipe.AddColorAttachment();
9829 pipe.AddShader(&vs);
9830 pipe.AddShader(&fs);
9831
9832 VkDescriptorSetObj descriptorSet(m_device);
9833 descriptorSet.AppendDummy();
9834 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9835
9836 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009838 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009839}
9840
Karl Schultz6addd812016-02-02 17:17:23 -07009841TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009843 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009844 "output arr[2] of float32' vs 'ptr to "
9845 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009846
9847 ASSERT_NO_FATAL_FAILURE(InitState());
9848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9849
9850 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009851 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009852 "\n"
9853 "layout(location=0) out float x[2];\n"
9854 "out gl_PerVertex {\n"
9855 " vec4 gl_Position;\n"
9856 "};\n"
9857 "void main(){\n"
9858 " x[0] = 0; x[1] = 0;\n"
9859 " gl_Position = vec4(1);\n"
9860 "}\n";
9861 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009862 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009863 "\n"
9864 "layout(location=0) in float x[3];\n"
9865 "layout(location=0) out vec4 color;\n"
9866 "void main(){\n"
9867 " color = vec4(x[0] + x[1] + x[2]);\n"
9868 "}\n";
9869
9870 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9871 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9872
9873 VkPipelineObj pipe(m_device);
9874 pipe.AddColorAttachment();
9875 pipe.AddShader(&vs);
9876 pipe.AddShader(&fs);
9877
9878 VkDescriptorSetObj descriptorSet(m_device);
9879 descriptorSet.AppendDummy();
9880 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9881
9882 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9883
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009884 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009885}
9886
Karl Schultz6addd812016-02-02 17:17:23 -07009887TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009889 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009890
Chris Forbesb56af562015-05-25 11:13:17 +12009891 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009893
9894 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009895 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009896 "\n"
9897 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009898 "out gl_PerVertex {\n"
9899 " vec4 gl_Position;\n"
9900 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009901 "void main(){\n"
9902 " x = 0;\n"
9903 " gl_Position = vec4(1);\n"
9904 "}\n";
9905 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009906 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009907 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009908 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009909 "layout(location=0) out vec4 color;\n"
9910 "void main(){\n"
9911 " color = vec4(x);\n"
9912 "}\n";
9913
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009916
9917 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009918 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009919 pipe.AddShader(&vs);
9920 pipe.AddShader(&fs);
9921
Chris Forbesb56af562015-05-25 11:13:17 +12009922 VkDescriptorSetObj descriptorSet(m_device);
9923 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009925
Tony Barbour5781e8f2015-08-04 16:23:11 -06009926 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009927
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009928 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009929}
9930
Karl Schultz6addd812016-02-02 17:17:23 -07009931TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009933 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009934
9935 ASSERT_NO_FATAL_FAILURE(InitState());
9936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9937
9938 char const *vsSource =
9939 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009940 "\n"
9941 "out block { layout(location=0) int x; } outs;\n"
9942 "out gl_PerVertex {\n"
9943 " vec4 gl_Position;\n"
9944 "};\n"
9945 "void main(){\n"
9946 " outs.x = 0;\n"
9947 " gl_Position = vec4(1);\n"
9948 "}\n";
9949 char const *fsSource =
9950 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009951 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009952 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009953 "layout(location=0) out vec4 color;\n"
9954 "void main(){\n"
9955 " color = vec4(ins.x);\n"
9956 "}\n";
9957
9958 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9959 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9960
9961 VkPipelineObj pipe(m_device);
9962 pipe.AddColorAttachment();
9963 pipe.AddShader(&vs);
9964 pipe.AddShader(&fs);
9965
9966 VkDescriptorSetObj descriptorSet(m_device);
9967 descriptorSet.AppendDummy();
9968 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9969
9970 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9971
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009972 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009973}
9974
9975TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9977 "location 0.0 which is not written by vertex shader");
9978
9979 ASSERT_NO_FATAL_FAILURE(InitState());
9980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9981
9982 char const *vsSource =
9983 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009984 "\n"
9985 "out block { layout(location=1) float x; } outs;\n"
9986 "out gl_PerVertex {\n"
9987 " vec4 gl_Position;\n"
9988 "};\n"
9989 "void main(){\n"
9990 " outs.x = 0;\n"
9991 " gl_Position = vec4(1);\n"
9992 "}\n";
9993 char const *fsSource =
9994 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009995 "\n"
9996 "in block { layout(location=0) float x; } ins;\n"
9997 "layout(location=0) out vec4 color;\n"
9998 "void main(){\n"
9999 " color = vec4(ins.x);\n"
10000 "}\n";
10001
10002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10004
10005 VkPipelineObj pipe(m_device);
10006 pipe.AddColorAttachment();
10007 pipe.AddShader(&vs);
10008 pipe.AddShader(&fs);
10009
10010 VkDescriptorSetObj descriptorSet(m_device);
10011 descriptorSet.AppendDummy();
10012 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10013
10014 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10015
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010016 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130010017}
10018
10019TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
10020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10021 "location 0.1 which is not written by vertex shader");
10022
10023 ASSERT_NO_FATAL_FAILURE(InitState());
10024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10025
10026 char const *vsSource =
10027 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010028 "\n"
10029 "out block { layout(location=0, component=0) float x; } outs;\n"
10030 "out gl_PerVertex {\n"
10031 " vec4 gl_Position;\n"
10032 "};\n"
10033 "void main(){\n"
10034 " outs.x = 0;\n"
10035 " gl_Position = vec4(1);\n"
10036 "}\n";
10037 char const *fsSource =
10038 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +130010039 "\n"
10040 "in block { layout(location=0, component=1) float x; } ins;\n"
10041 "layout(location=0) out vec4 color;\n"
10042 "void main(){\n"
10043 " color = vec4(ins.x);\n"
10044 "}\n";
10045
10046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10048
10049 VkPipelineObj pipe(m_device);
10050 pipe.AddColorAttachment();
10051 pipe.AddShader(&vs);
10052 pipe.AddShader(&fs);
10053
10054 VkDescriptorSetObj descriptorSet(m_device);
10055 descriptorSet.AppendDummy();
10056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10057
10058 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10059
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010060 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130010061}
10062
Karl Schultz6addd812016-02-02 17:17:23 -070010063TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010065 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010066
Chris Forbesde136e02015-05-25 11:13:28 +120010067 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010069
10070 VkVertexInputBindingDescription input_binding;
10071 memset(&input_binding, 0, sizeof(input_binding));
10072
10073 VkVertexInputAttributeDescription input_attrib;
10074 memset(&input_attrib, 0, sizeof(input_attrib));
10075 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10076
10077 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010078 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010079 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010080 "out gl_PerVertex {\n"
10081 " vec4 gl_Position;\n"
10082 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010083 "void main(){\n"
10084 " gl_Position = vec4(1);\n"
10085 "}\n";
10086 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010087 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010088 "\n"
10089 "layout(location=0) out vec4 color;\n"
10090 "void main(){\n"
10091 " color = vec4(1);\n"
10092 "}\n";
10093
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010094 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10095 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010096
10097 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010098 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010099 pipe.AddShader(&vs);
10100 pipe.AddShader(&fs);
10101
10102 pipe.AddVertexInputBindings(&input_binding, 1);
10103 pipe.AddVertexInputAttribs(&input_attrib, 1);
10104
Chris Forbesde136e02015-05-25 11:13:28 +120010105 VkDescriptorSetObj descriptorSet(m_device);
10106 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010107 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010108
Tony Barbour5781e8f2015-08-04 16:23:11 -060010109 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010110
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010111 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010112}
10113
Karl Schultz6addd812016-02-02 17:17:23 -070010114TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010116 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010117
10118 ASSERT_NO_FATAL_FAILURE(InitState());
10119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10120
10121 VkVertexInputBindingDescription input_binding;
10122 memset(&input_binding, 0, sizeof(input_binding));
10123
10124 VkVertexInputAttributeDescription input_attrib;
10125 memset(&input_attrib, 0, sizeof(input_attrib));
10126 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10127
10128 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010129 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010130 "\n"
10131 "layout(location=1) in float x;\n"
10132 "out gl_PerVertex {\n"
10133 " vec4 gl_Position;\n"
10134 "};\n"
10135 "void main(){\n"
10136 " gl_Position = vec4(x);\n"
10137 "}\n";
10138 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010139 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010140 "\n"
10141 "layout(location=0) out vec4 color;\n"
10142 "void main(){\n"
10143 " color = vec4(1);\n"
10144 "}\n";
10145
10146 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10147 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10148
10149 VkPipelineObj pipe(m_device);
10150 pipe.AddColorAttachment();
10151 pipe.AddShader(&vs);
10152 pipe.AddShader(&fs);
10153
10154 pipe.AddVertexInputBindings(&input_binding, 1);
10155 pipe.AddVertexInputAttribs(&input_attrib, 1);
10156
10157 VkDescriptorSetObj descriptorSet(m_device);
10158 descriptorSet.AppendDummy();
10159 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10160
10161 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10162
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010163 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010164}
10165
Karl Schultz6addd812016-02-02 17:17:23 -070010166TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10167 m_errorMonitor->SetDesiredFailureMsg(
10168 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010169 "VS consumes input at location 0 but not provided");
10170
Chris Forbes62e8e502015-05-25 11:13:29 +120010171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010173
10174 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010175 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010176 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010177 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010178 "out gl_PerVertex {\n"
10179 " vec4 gl_Position;\n"
10180 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010181 "void main(){\n"
10182 " gl_Position = x;\n"
10183 "}\n";
10184 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010185 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010186 "\n"
10187 "layout(location=0) out vec4 color;\n"
10188 "void main(){\n"
10189 " color = vec4(1);\n"
10190 "}\n";
10191
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010194
10195 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010196 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010197 pipe.AddShader(&vs);
10198 pipe.AddShader(&fs);
10199
Chris Forbes62e8e502015-05-25 11:13:29 +120010200 VkDescriptorSetObj descriptorSet(m_device);
10201 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010202 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010203
Tony Barbour5781e8f2015-08-04 16:23:11 -060010204 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010205
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010206 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010207}
10208
Karl Schultz6addd812016-02-02 17:17:23 -070010209TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10210 m_errorMonitor->SetDesiredFailureMsg(
10211 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010212 "location 0 does not match VS input type");
10213
Chris Forbesc97d98e2015-05-25 11:13:31 +120010214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010216
10217 VkVertexInputBindingDescription input_binding;
10218 memset(&input_binding, 0, sizeof(input_binding));
10219
10220 VkVertexInputAttributeDescription input_attrib;
10221 memset(&input_attrib, 0, sizeof(input_attrib));
10222 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10223
10224 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010225 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010226 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010227 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010228 "out gl_PerVertex {\n"
10229 " vec4 gl_Position;\n"
10230 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010231 "void main(){\n"
10232 " gl_Position = vec4(x);\n"
10233 "}\n";
10234 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010235 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010236 "\n"
10237 "layout(location=0) out vec4 color;\n"
10238 "void main(){\n"
10239 " color = vec4(1);\n"
10240 "}\n";
10241
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010244
10245 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010246 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010247 pipe.AddShader(&vs);
10248 pipe.AddShader(&fs);
10249
10250 pipe.AddVertexInputBindings(&input_binding, 1);
10251 pipe.AddVertexInputAttribs(&input_attrib, 1);
10252
Chris Forbesc97d98e2015-05-25 11:13:31 +120010253 VkDescriptorSetObj descriptorSet(m_device);
10254 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010256
Tony Barbour5781e8f2015-08-04 16:23:11 -060010257 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010258
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010259 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010260}
10261
Chris Forbesc68b43c2016-04-06 11:18:47 +120010262TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10263 m_errorMonitor->SetDesiredFailureMsg(
10264 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10265 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10266
10267 ASSERT_NO_FATAL_FAILURE(InitState());
10268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10269
10270 char const *vsSource =
10271 "#version 450\n"
10272 "\n"
10273 "out gl_PerVertex {\n"
10274 " vec4 gl_Position;\n"
10275 "};\n"
10276 "void main(){\n"
10277 " gl_Position = vec4(1);\n"
10278 "}\n";
10279 char const *fsSource =
10280 "#version 450\n"
10281 "\n"
10282 "layout(location=0) out vec4 color;\n"
10283 "void main(){\n"
10284 " color = vec4(1);\n"
10285 "}\n";
10286
10287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10289
10290 VkPipelineObj pipe(m_device);
10291 pipe.AddColorAttachment();
10292 pipe.AddShader(&vs);
10293 pipe.AddShader(&vs);
10294 pipe.AddShader(&fs);
10295
10296 VkDescriptorSetObj descriptorSet(m_device);
10297 descriptorSet.AppendDummy();
10298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10299
10300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10301
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010302 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010303}
10304
Karl Schultz6addd812016-02-02 17:17:23 -070010305TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010306 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010307
10308 ASSERT_NO_FATAL_FAILURE(InitState());
10309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10310
10311 VkVertexInputBindingDescription input_binding;
10312 memset(&input_binding, 0, sizeof(input_binding));
10313
10314 VkVertexInputAttributeDescription input_attribs[2];
10315 memset(input_attribs, 0, sizeof(input_attribs));
10316
10317 for (int i = 0; i < 2; i++) {
10318 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10319 input_attribs[i].location = i;
10320 }
10321
10322 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010323 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010324 "\n"
10325 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010326 "out gl_PerVertex {\n"
10327 " vec4 gl_Position;\n"
10328 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010329 "void main(){\n"
10330 " gl_Position = x[0] + x[1];\n"
10331 "}\n";
10332 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010333 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010334 "\n"
10335 "layout(location=0) out vec4 color;\n"
10336 "void main(){\n"
10337 " color = vec4(1);\n"
10338 "}\n";
10339
10340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10342
10343 VkPipelineObj pipe(m_device);
10344 pipe.AddColorAttachment();
10345 pipe.AddShader(&vs);
10346 pipe.AddShader(&fs);
10347
10348 pipe.AddVertexInputBindings(&input_binding, 1);
10349 pipe.AddVertexInputAttribs(input_attribs, 2);
10350
10351 VkDescriptorSetObj descriptorSet(m_device);
10352 descriptorSet.AppendDummy();
10353 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10354
10355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10356
10357 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010358 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010359}
10360
Chris Forbes2682b242015-11-24 11:13:14 +130010361TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10362{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010363 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010364
10365 ASSERT_NO_FATAL_FAILURE(InitState());
10366 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10367
10368 VkVertexInputBindingDescription input_binding;
10369 memset(&input_binding, 0, sizeof(input_binding));
10370
10371 VkVertexInputAttributeDescription input_attribs[2];
10372 memset(input_attribs, 0, sizeof(input_attribs));
10373
10374 for (int i = 0; i < 2; i++) {
10375 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10376 input_attribs[i].location = i;
10377 }
10378
10379 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010380 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010381 "\n"
10382 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010383 "out gl_PerVertex {\n"
10384 " vec4 gl_Position;\n"
10385 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010386 "void main(){\n"
10387 " gl_Position = x[0] + x[1];\n"
10388 "}\n";
10389 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010390 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010391 "\n"
10392 "layout(location=0) out vec4 color;\n"
10393 "void main(){\n"
10394 " color = vec4(1);\n"
10395 "}\n";
10396
10397 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10398 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10399
10400 VkPipelineObj pipe(m_device);
10401 pipe.AddColorAttachment();
10402 pipe.AddShader(&vs);
10403 pipe.AddShader(&fs);
10404
10405 pipe.AddVertexInputBindings(&input_binding, 1);
10406 pipe.AddVertexInputAttribs(input_attribs, 2);
10407
10408 VkDescriptorSetObj descriptorSet(m_device);
10409 descriptorSet.AppendDummy();
10410 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10411
10412 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10413
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010414 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010415}
Chris Forbes2682b242015-11-24 11:13:14 +130010416
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010417TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10418{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010419 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010420
10421 ASSERT_NO_FATAL_FAILURE(InitState());
10422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10423
10424 char const *vsSource =
10425 "#version 450\n"
10426 "out gl_PerVertex {\n"
10427 " vec4 gl_Position;\n"
10428 "};\n"
10429 "void main(){\n"
10430 " gl_Position = vec4(0);\n"
10431 "}\n";
10432 char const *fsSource =
10433 "#version 450\n"
10434 "\n"
10435 "layout(location=0) out vec4 color;\n"
10436 "void main(){\n"
10437 " color = vec4(1);\n"
10438 "}\n";
10439
10440 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10441 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10442
10443 VkPipelineObj pipe(m_device);
10444 pipe.AddColorAttachment();
10445 pipe.AddShader(&vs);
10446 pipe.AddShader(&fs);
10447
10448 VkDescriptorSetObj descriptorSet(m_device);
10449 descriptorSet.AppendDummy();
10450 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10451
10452 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10453
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010454 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010455}
10456
Chris Forbes912c9192016-04-05 17:50:35 +120010457TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10458{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010459 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010460
10461 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10462
10463 ASSERT_NO_FATAL_FAILURE(InitState());
10464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10465
10466 char const *vsSource =
10467 "#version 450\n"
10468 "out gl_PerVertex {\n"
10469 " vec4 gl_Position;\n"
10470 "};\n"
10471 "layout(location=0) out vec3 x;\n"
10472 "layout(location=1) out ivec3 y;\n"
10473 "layout(location=2) out vec3 z;\n"
10474 "void main(){\n"
10475 " gl_Position = vec4(0);\n"
10476 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10477 "}\n";
10478 char const *fsSource =
10479 "#version 450\n"
10480 "\n"
10481 "layout(location=0) out vec4 color;\n"
10482 "layout(location=0) in float x;\n"
10483 "layout(location=1) flat in int y;\n"
10484 "layout(location=2) in vec2 z;\n"
10485 "void main(){\n"
10486 " color = vec4(1 + x + y + z.x);\n"
10487 "}\n";
10488
10489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10491
10492 VkPipelineObj pipe(m_device);
10493 pipe.AddColorAttachment();
10494 pipe.AddShader(&vs);
10495 pipe.AddShader(&fs);
10496
10497 VkDescriptorSetObj descriptorSet(m_device);
10498 descriptorSet.AppendDummy();
10499 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10500
10501 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10502
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010503 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010504}
10505
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010506TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10507{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010508 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010509
10510 ASSERT_NO_FATAL_FAILURE(InitState());
10511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10512
Chris Forbesc1e852d2016-04-04 19:26:42 +120010513 if (!m_device->phy().features().tessellationShader) {
10514 printf("Device does not support tessellation shaders; skipped.\n");
10515 return;
10516 }
10517
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010518 char const *vsSource =
10519 "#version 450\n"
10520 "void main(){}\n";
10521 char const *tcsSource =
10522 "#version 450\n"
10523 "layout(location=0) out int x[];\n"
10524 "layout(vertices=3) out;\n"
10525 "void main(){\n"
10526 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10527 " gl_TessLevelInner[0] = 1;\n"
10528 " x[gl_InvocationID] = gl_InvocationID;\n"
10529 "}\n";
10530 char const *tesSource =
10531 "#version 450\n"
10532 "layout(triangles, equal_spacing, cw) in;\n"
10533 "layout(location=0) in int x[];\n"
10534 "out gl_PerVertex { vec4 gl_Position; };\n"
10535 "void main(){\n"
10536 " gl_Position.xyz = gl_TessCoord;\n"
10537 " gl_Position.w = x[0] + x[1] + x[2];\n"
10538 "}\n";
10539 char const *fsSource =
10540 "#version 450\n"
10541 "layout(location=0) out vec4 color;\n"
10542 "void main(){\n"
10543 " color = vec4(1);\n"
10544 "}\n";
10545
10546 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10547 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10548 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10549 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10550
10551 VkPipelineInputAssemblyStateCreateInfo iasci{
10552 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10553 nullptr,
10554 0,
10555 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10556 VK_FALSE};
10557
Chris Forbesb4cacb62016-04-04 19:15:00 +120010558 VkPipelineTessellationStateCreateInfo tsci{
10559 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10560 nullptr,
10561 0,
10562 3};
10563
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010564 VkPipelineObj pipe(m_device);
10565 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010566 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010567 pipe.AddColorAttachment();
10568 pipe.AddShader(&vs);
10569 pipe.AddShader(&tcs);
10570 pipe.AddShader(&tes);
10571 pipe.AddShader(&fs);
10572
10573 VkDescriptorSetObj descriptorSet(m_device);
10574 descriptorSet.AppendDummy();
10575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10576
10577 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10578
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010579 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010580}
10581
Chris Forbesa0ab8152016-04-20 13:34:27 +120010582TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10583{
10584 m_errorMonitor->ExpectSuccess();
10585
10586 ASSERT_NO_FATAL_FAILURE(InitState());
10587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10588
10589 if (!m_device->phy().features().geometryShader) {
10590 printf("Device does not support geometry shaders; skipped.\n");
10591 return;
10592 }
10593
10594 char const *vsSource =
10595 "#version 450\n"
10596 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10597 "void main(){\n"
10598 " vs_out.x = vec4(1);\n"
10599 "}\n";
10600 char const *gsSource =
10601 "#version 450\n"
10602 "layout(triangles) in;\n"
10603 "layout(triangle_strip, max_vertices=3) out;\n"
10604 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10605 "out gl_PerVertex { vec4 gl_Position; };\n"
10606 "void main() {\n"
10607 " gl_Position = gs_in[0].x;\n"
10608 " EmitVertex();\n"
10609 "}\n";
10610 char const *fsSource =
10611 "#version 450\n"
10612 "layout(location=0) out vec4 color;\n"
10613 "void main(){\n"
10614 " color = vec4(1);\n"
10615 "}\n";
10616
10617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10618 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10619 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10620
10621 VkPipelineObj pipe(m_device);
10622 pipe.AddColorAttachment();
10623 pipe.AddShader(&vs);
10624 pipe.AddShader(&gs);
10625 pipe.AddShader(&fs);
10626
10627 VkDescriptorSetObj descriptorSet(m_device);
10628 descriptorSet.AppendDummy();
10629 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10630
10631 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10632
10633 m_errorMonitor->VerifyNotFound();
10634}
10635
Chris Forbesa0193bc2016-04-04 19:19:47 +120010636TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10637{
10638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10639 "is per-vertex in tessellation control shader stage "
10640 "but per-patch in tessellation evaluation shader stage");
10641
10642 ASSERT_NO_FATAL_FAILURE(InitState());
10643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10644
Chris Forbesc1e852d2016-04-04 19:26:42 +120010645 if (!m_device->phy().features().tessellationShader) {
10646 printf("Device does not support tessellation shaders; skipped.\n");
10647 return;
10648 }
10649
Chris Forbesa0193bc2016-04-04 19:19:47 +120010650 char const *vsSource =
10651 "#version 450\n"
10652 "void main(){}\n";
10653 char const *tcsSource =
10654 "#version 450\n"
10655 "layout(location=0) out int x[];\n"
10656 "layout(vertices=3) out;\n"
10657 "void main(){\n"
10658 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10659 " gl_TessLevelInner[0] = 1;\n"
10660 " x[gl_InvocationID] = gl_InvocationID;\n"
10661 "}\n";
10662 char const *tesSource =
10663 "#version 450\n"
10664 "layout(triangles, equal_spacing, cw) in;\n"
10665 "layout(location=0) patch in int x;\n"
10666 "out gl_PerVertex { vec4 gl_Position; };\n"
10667 "void main(){\n"
10668 " gl_Position.xyz = gl_TessCoord;\n"
10669 " gl_Position.w = x;\n"
10670 "}\n";
10671 char const *fsSource =
10672 "#version 450\n"
10673 "layout(location=0) out vec4 color;\n"
10674 "void main(){\n"
10675 " color = vec4(1);\n"
10676 "}\n";
10677
10678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10679 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10680 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10681 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10682
10683 VkPipelineInputAssemblyStateCreateInfo iasci{
10684 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10685 nullptr,
10686 0,
10687 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10688 VK_FALSE};
10689
10690 VkPipelineTessellationStateCreateInfo tsci{
10691 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10692 nullptr,
10693 0,
10694 3};
10695
10696 VkPipelineObj pipe(m_device);
10697 pipe.SetInputAssembly(&iasci);
10698 pipe.SetTessellation(&tsci);
10699 pipe.AddColorAttachment();
10700 pipe.AddShader(&vs);
10701 pipe.AddShader(&tcs);
10702 pipe.AddShader(&tes);
10703 pipe.AddShader(&fs);
10704
10705 VkDescriptorSetObj descriptorSet(m_device);
10706 descriptorSet.AppendDummy();
10707 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10708
10709 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10710
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010711 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010712}
10713
Karl Schultz6addd812016-02-02 17:17:23 -070010714TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10715 m_errorMonitor->SetDesiredFailureMsg(
10716 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010717 "Duplicate vertex input binding descriptions for binding 0");
10718
Chris Forbes280ba2c2015-06-12 11:16:41 +120010719 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010720 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010721
10722 /* Two binding descriptions for binding 0 */
10723 VkVertexInputBindingDescription input_bindings[2];
10724 memset(input_bindings, 0, sizeof(input_bindings));
10725
10726 VkVertexInputAttributeDescription input_attrib;
10727 memset(&input_attrib, 0, sizeof(input_attrib));
10728 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10729
10730 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010731 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010732 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010733 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010734 "out gl_PerVertex {\n"
10735 " vec4 gl_Position;\n"
10736 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010737 "void main(){\n"
10738 " gl_Position = vec4(x);\n"
10739 "}\n";
10740 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010741 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010742 "\n"
10743 "layout(location=0) out vec4 color;\n"
10744 "void main(){\n"
10745 " color = vec4(1);\n"
10746 "}\n";
10747
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010750
10751 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010752 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010753 pipe.AddShader(&vs);
10754 pipe.AddShader(&fs);
10755
10756 pipe.AddVertexInputBindings(input_bindings, 2);
10757 pipe.AddVertexInputAttribs(&input_attrib, 1);
10758
Chris Forbes280ba2c2015-06-12 11:16:41 +120010759 VkDescriptorSetObj descriptorSet(m_device);
10760 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010762
Tony Barbour5781e8f2015-08-04 16:23:11 -060010763 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010765 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010766}
Chris Forbes8f68b562015-05-25 11:13:32 +120010767
Chris Forbes35efec72016-04-21 14:32:08 +120010768TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10769 m_errorMonitor->ExpectSuccess();
10770
10771 ASSERT_NO_FATAL_FAILURE(InitState());
10772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10773
10774 if (!m_device->phy().features().tessellationShader) {
10775 printf("Device does not support 64bit vertex attributes; skipped.\n");
10776 return;
10777 }
10778
10779 VkVertexInputBindingDescription input_bindings[1];
10780 memset(input_bindings, 0, sizeof(input_bindings));
10781
10782 VkVertexInputAttributeDescription input_attribs[4];
10783 memset(input_attribs, 0, sizeof(input_attribs));
10784 input_attribs[0].location = 0;
10785 input_attribs[0].offset = 0;
10786 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10787 input_attribs[1].location = 2;
10788 input_attribs[1].offset = 32;
10789 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10790 input_attribs[2].location = 4;
10791 input_attribs[2].offset = 64;
10792 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10793 input_attribs[3].location = 6;
10794 input_attribs[3].offset = 96;
10795 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10796
10797 char const *vsSource =
10798 "#version 450\n"
10799 "\n"
10800 "layout(location=0) in dmat4 x;\n"
10801 "out gl_PerVertex {\n"
10802 " vec4 gl_Position;\n"
10803 "};\n"
10804 "void main(){\n"
10805 " gl_Position = vec4(x[0][0]);\n"
10806 "}\n";
10807 char const *fsSource =
10808 "#version 450\n"
10809 "\n"
10810 "layout(location=0) out vec4 color;\n"
10811 "void main(){\n"
10812 " color = vec4(1);\n"
10813 "}\n";
10814
10815 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10816 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10817
10818 VkPipelineObj pipe(m_device);
10819 pipe.AddColorAttachment();
10820 pipe.AddShader(&vs);
10821 pipe.AddShader(&fs);
10822
10823 pipe.AddVertexInputBindings(input_bindings, 1);
10824 pipe.AddVertexInputAttribs(input_attribs, 4);
10825
10826 VkDescriptorSetObj descriptorSet(m_device);
10827 descriptorSet.AppendDummy();
10828 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10829
10830 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10831
10832 m_errorMonitor->VerifyNotFound();
10833}
10834
Karl Schultz6addd812016-02-02 17:17:23 -070010835TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010837 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010838
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010839 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010840
10841 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010842 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010843 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010844 "out gl_PerVertex {\n"
10845 " vec4 gl_Position;\n"
10846 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010847 "void main(){\n"
10848 " gl_Position = vec4(1);\n"
10849 "}\n";
10850 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010851 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010852 "\n"
10853 "void main(){\n"
10854 "}\n";
10855
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010856 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10857 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010858
10859 VkPipelineObj pipe(m_device);
10860 pipe.AddShader(&vs);
10861 pipe.AddShader(&fs);
10862
Chia-I Wu08accc62015-07-07 11:50:03 +080010863 /* set up CB 0, not written */
10864 pipe.AddColorAttachment();
10865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010866
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010867 VkDescriptorSetObj descriptorSet(m_device);
10868 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010869 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010870
Tony Barbour5781e8f2015-08-04 16:23:11 -060010871 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010872
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010873 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010874}
10875
Karl Schultz6addd812016-02-02 17:17:23 -070010876TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010877 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010878 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010879 "FS writes to output location 1 with no matching attachment");
10880
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010881 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010882
10883 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010884 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010885 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010886 "out gl_PerVertex {\n"
10887 " vec4 gl_Position;\n"
10888 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010889 "void main(){\n"
10890 " gl_Position = vec4(1);\n"
10891 "}\n";
10892 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010893 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010894 "\n"
10895 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010896 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010897 "void main(){\n"
10898 " x = vec4(1);\n"
10899 " y = vec4(1);\n"
10900 "}\n";
10901
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010902 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10903 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010904
10905 VkPipelineObj pipe(m_device);
10906 pipe.AddShader(&vs);
10907 pipe.AddShader(&fs);
10908
Chia-I Wu08accc62015-07-07 11:50:03 +080010909 /* set up CB 0, not written */
10910 pipe.AddColorAttachment();
10911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010912 /* FS writes CB 1, but we don't configure it */
10913
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010914 VkDescriptorSetObj descriptorSet(m_device);
10915 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010917
Tony Barbour5781e8f2015-08-04 16:23:11 -060010918 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010919
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010920 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010921}
10922
Karl Schultz6addd812016-02-02 17:17:23 -070010923TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010925 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010926
Chris Forbesa36d69e2015-05-25 11:13:44 +120010927 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010928
10929 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010930 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010931 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010932 "out gl_PerVertex {\n"
10933 " vec4 gl_Position;\n"
10934 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010935 "void main(){\n"
10936 " gl_Position = vec4(1);\n"
10937 "}\n";
10938 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010939 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010940 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010941 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010942 "void main(){\n"
10943 " x = ivec4(1);\n"
10944 "}\n";
10945
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010946 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10947 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010948
10949 VkPipelineObj pipe(m_device);
10950 pipe.AddShader(&vs);
10951 pipe.AddShader(&fs);
10952
Chia-I Wu08accc62015-07-07 11:50:03 +080010953 /* set up CB 0; type is UNORM by default */
10954 pipe.AddColorAttachment();
10955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010956
Chris Forbesa36d69e2015-05-25 11:13:44 +120010957 VkDescriptorSetObj descriptorSet(m_device);
10958 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010959 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010960
Tony Barbour5781e8f2015-08-04 16:23:11 -060010961 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010962
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010963 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010964}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010965
Karl Schultz6addd812016-02-02 17:17:23 -070010966TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010968 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010969
Chris Forbes556c76c2015-08-14 12:04:59 +120010970 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010971
10972 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010973 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010974 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010975 "out gl_PerVertex {\n"
10976 " vec4 gl_Position;\n"
10977 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010978 "void main(){\n"
10979 " gl_Position = vec4(1);\n"
10980 "}\n";
10981 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010982 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010983 "\n"
10984 "layout(location=0) out vec4 x;\n"
10985 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10986 "void main(){\n"
10987 " x = vec4(bar.y);\n"
10988 "}\n";
10989
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010990 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10991 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010992
Chris Forbes556c76c2015-08-14 12:04:59 +120010993 VkPipelineObj pipe(m_device);
10994 pipe.AddShader(&vs);
10995 pipe.AddShader(&fs);
10996
10997 /* set up CB 0; type is UNORM by default */
10998 pipe.AddColorAttachment();
10999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11000
11001 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011002 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120011003
11004 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011006 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120011007}
11008
Chris Forbes5c59e902016-02-26 16:56:09 +130011009TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
11010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11011 "not declared in layout");
11012
11013 ASSERT_NO_FATAL_FAILURE(InitState());
11014
11015 char const *vsSource =
11016 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011017 "\n"
11018 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11019 "out gl_PerVertex {\n"
11020 " vec4 gl_Position;\n"
11021 "};\n"
11022 "void main(){\n"
11023 " gl_Position = vec4(consts.x);\n"
11024 "}\n";
11025 char const *fsSource =
11026 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130011027 "\n"
11028 "layout(location=0) out vec4 x;\n"
11029 "void main(){\n"
11030 " x = vec4(1);\n"
11031 "}\n";
11032
11033 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11034 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11035
11036 VkPipelineObj pipe(m_device);
11037 pipe.AddShader(&vs);
11038 pipe.AddShader(&fs);
11039
11040 /* set up CB 0; type is UNORM by default */
11041 pipe.AddColorAttachment();
11042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11043
11044 VkDescriptorSetObj descriptorSet(m_device);
11045 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11046
11047 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
11048
11049 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011050 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130011051}
11052
Chris Forbes10eb9ae2016-05-31 16:09:42 +120011053TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
11054 m_errorMonitor->SetDesiredFailureMsg(
11055 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11056 "Shader uses descriptor slot 0.0");
11057
11058 ASSERT_NO_FATAL_FAILURE(InitState());
11059
11060 char const *csSource =
11061 "#version 450\n"
11062 "\n"
11063 "layout(local_size_x=1) in;\n"
11064 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11065 "void main(){\n"
11066 " x = vec4(1);\n"
11067 "}\n";
11068
11069 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11070
11071 VkDescriptorSetObj descriptorSet(m_device);
11072 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11073
11074 VkComputePipelineCreateInfo cpci = {
11075 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11076 nullptr, 0, {
11077 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11078 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11079 cs.handle(), "main", nullptr
11080 },
11081 descriptorSet.GetPipelineLayout(),
11082 VK_NULL_HANDLE, -1
11083 };
11084
11085 VkPipeline pipe;
11086 VkResult err = vkCreateComputePipelines(
11087 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11088
11089 m_errorMonitor->VerifyFound();
11090
11091 if (err == VK_SUCCESS) {
11092 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11093 }
11094}
11095
11096TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11097 m_errorMonitor->ExpectSuccess();
11098
11099 ASSERT_NO_FATAL_FAILURE(InitState());
11100
11101 char const *csSource =
11102 "#version 450\n"
11103 "\n"
11104 "layout(local_size_x=1) in;\n"
11105 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11106 "void main(){\n"
11107 " // x is not used.\n"
11108 "}\n";
11109
11110 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11111
11112 VkDescriptorSetObj descriptorSet(m_device);
11113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11114
11115 VkComputePipelineCreateInfo cpci = {
11116 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11117 nullptr, 0, {
11118 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11119 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11120 cs.handle(), "main", nullptr
11121 },
11122 descriptorSet.GetPipelineLayout(),
11123 VK_NULL_HANDLE, -1
11124 };
11125
11126 VkPipeline pipe;
11127 VkResult err = vkCreateComputePipelines(
11128 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11129
11130 m_errorMonitor->VerifyNotFound();
11131
11132 if (err == VK_SUCCESS) {
11133 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11134 }
11135}
11136
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011137#endif // SHADER_CHECKER_TESTS
11138
11139#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011140TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011141 m_errorMonitor->SetDesiredFailureMsg(
11142 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011143 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011144
11145 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011146
11147 // Create an image
11148 VkImage image;
11149
Karl Schultz6addd812016-02-02 17:17:23 -070011150 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11151 const int32_t tex_width = 32;
11152 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011153
11154 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011155 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11156 image_create_info.pNext = NULL;
11157 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11158 image_create_info.format = tex_format;
11159 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011160 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011161 image_create_info.extent.depth = 1;
11162 image_create_info.mipLevels = 1;
11163 image_create_info.arrayLayers = 1;
11164 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11165 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11166 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11167 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011168
11169 // Introduce error by sending down a bogus width extent
11170 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011171 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011172
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011173 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011174}
11175
Mark Youngc48c4c12016-04-11 14:26:49 -060011176TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11177 m_errorMonitor->SetDesiredFailureMsg(
11178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11179 "CreateImage extents is 0 for at least one required dimension");
11180
11181 ASSERT_NO_FATAL_FAILURE(InitState());
11182
11183 // Create an image
11184 VkImage image;
11185
11186 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11187 const int32_t tex_width = 32;
11188 const int32_t tex_height = 32;
11189
11190 VkImageCreateInfo image_create_info = {};
11191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11192 image_create_info.pNext = NULL;
11193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11194 image_create_info.format = tex_format;
11195 image_create_info.extent.width = tex_width;
11196 image_create_info.extent.height = tex_height;
11197 image_create_info.extent.depth = 1;
11198 image_create_info.mipLevels = 1;
11199 image_create_info.arrayLayers = 1;
11200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11201 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11202 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11203 image_create_info.flags = 0;
11204
11205 // Introduce error by sending down a bogus width extent
11206 image_create_info.extent.width = 0;
11207 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11208
11209 m_errorMonitor->VerifyFound();
11210}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011211#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011212
Tobin Ehliscde08892015-09-22 10:11:37 -060011213#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011214TEST_F(VkLayerTest, InvalidImageView) {
11215 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011216
Karl Schultz6addd812016-02-02 17:17:23 -070011217 m_errorMonitor->SetDesiredFailureMsg(
11218 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011219 "vkCreateImageView called with baseMipLevel 10 ");
11220
Tobin Ehliscde08892015-09-22 10:11:37 -060011221 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011222
Mike Stroyana3082432015-09-25 13:39:21 -060011223 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011224 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011225
Karl Schultz6addd812016-02-02 17:17:23 -070011226 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11227 const int32_t tex_width = 32;
11228 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011229
11230 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011231 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11232 image_create_info.pNext = NULL;
11233 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11234 image_create_info.format = tex_format;
11235 image_create_info.extent.width = tex_width;
11236 image_create_info.extent.height = tex_height;
11237 image_create_info.extent.depth = 1;
11238 image_create_info.mipLevels = 1;
11239 image_create_info.arrayLayers = 1;
11240 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11241 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11242 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11243 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011244
Chia-I Wuf7458c52015-10-26 21:10:41 +080011245 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011246 ASSERT_VK_SUCCESS(err);
11247
11248 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011249 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11250 image_view_create_info.image = image;
11251 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11252 image_view_create_info.format = tex_format;
11253 image_view_create_info.subresourceRange.layerCount = 1;
11254 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11255 image_view_create_info.subresourceRange.levelCount = 1;
11256 image_view_create_info.subresourceRange.aspectMask =
11257 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011258
11259 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011260 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11261 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011263 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011264 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011265}
Mike Stroyana3082432015-09-25 13:39:21 -060011266
Karl Schultz6addd812016-02-02 17:17:23 -070011267TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011268 TEST_DESCRIPTION(
11269 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011271 "vkCreateImageView: Color image "
11272 "formats must have ONLY the "
11273 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011274
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011275 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011276
Karl Schultz6addd812016-02-02 17:17:23 -070011277 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011278 VkImageObj image(m_device);
11279 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11280 VK_IMAGE_TILING_LINEAR, 0);
11281 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011282
11283 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011284 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011285 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011286 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11287 image_view_create_info.format = tex_format;
11288 image_view_create_info.subresourceRange.baseMipLevel = 0;
11289 image_view_create_info.subresourceRange.levelCount = 1;
11290 // Cause an error by setting an invalid image aspect
11291 image_view_create_info.subresourceRange.aspectMask =
11292 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011293
11294 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011295 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011296
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011297 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011298}
11299
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011300TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011301 VkResult err;
11302 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011303
Karl Schultz6addd812016-02-02 17:17:23 -070011304 m_errorMonitor->SetDesiredFailureMsg(
11305 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011306 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011307
Mike Stroyana3082432015-09-25 13:39:21 -060011308 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011309
11310 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011311 VkImage srcImage;
11312 VkImage dstImage;
11313 VkDeviceMemory srcMem;
11314 VkDeviceMemory destMem;
11315 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011316
11317 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11319 image_create_info.pNext = NULL;
11320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11321 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11322 image_create_info.extent.width = 32;
11323 image_create_info.extent.height = 32;
11324 image_create_info.extent.depth = 1;
11325 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011326 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11329 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11330 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011331
Karl Schultz6addd812016-02-02 17:17:23 -070011332 err =
11333 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011334 ASSERT_VK_SUCCESS(err);
11335
Karl Schultz6addd812016-02-02 17:17:23 -070011336 err =
11337 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011338 ASSERT_VK_SUCCESS(err);
11339
11340 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011341 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011342 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11343 memAlloc.pNext = NULL;
11344 memAlloc.allocationSize = 0;
11345 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011346
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011347 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011348 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011349 pass =
11350 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011351 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011352 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011353 ASSERT_VK_SUCCESS(err);
11354
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011355 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011356 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011357 pass =
11358 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011359 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011360 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011361 ASSERT_VK_SUCCESS(err);
11362
11363 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11364 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011365 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011366 ASSERT_VK_SUCCESS(err);
11367
11368 BeginCommandBuffer();
11369 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011370 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011371 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011372 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011373 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011374 copyRegion.srcOffset.x = 0;
11375 copyRegion.srcOffset.y = 0;
11376 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011377 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011378 copyRegion.dstSubresource.mipLevel = 0;
11379 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011380 // Introduce failure by forcing the dst layerCount to differ from src
11381 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011382 copyRegion.dstOffset.x = 0;
11383 copyRegion.dstOffset.y = 0;
11384 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011385 copyRegion.extent.width = 1;
11386 copyRegion.extent.height = 1;
11387 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011388 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11389 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011390 EndCommandBuffer();
11391
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011392 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011393
Chia-I Wuf7458c52015-10-26 21:10:41 +080011394 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011395 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011396 vkFreeMemory(m_device->device(), srcMem, NULL);
11397 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011398}
11399
Tony Barbourd6673642016-05-05 14:46:39 -060011400TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11401
11402 TEST_DESCRIPTION("Creating images with unsuported formats ");
11403
11404 ASSERT_NO_FATAL_FAILURE(InitState());
11405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11406 VkImageObj image(m_device);
11407 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11408 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11409 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11410 VK_IMAGE_TILING_OPTIMAL, 0);
11411 ASSERT_TRUE(image.initialized());
11412
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011413 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11414 VkImageCreateInfo image_create_info;
11415 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11416 image_create_info.pNext = NULL;
11417 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11418 image_create_info.format = VK_FORMAT_UNDEFINED;
11419 image_create_info.extent.width = 32;
11420 image_create_info.extent.height = 32;
11421 image_create_info.extent.depth = 1;
11422 image_create_info.mipLevels = 1;
11423 image_create_info.arrayLayers = 1;
11424 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11425 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11426 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11427 image_create_info.flags = 0;
11428
11429 m_errorMonitor->SetDesiredFailureMsg(
11430 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11431 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11432
11433 VkImage localImage;
11434 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11435 m_errorMonitor->VerifyFound();
11436
Tony Barbourd6673642016-05-05 14:46:39 -060011437 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011438 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011439 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11440 VkFormat format = static_cast<VkFormat>(f);
11441 VkFormatProperties fProps = m_device->format_properties(format);
11442 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11443 fProps.optimalTilingFeatures == 0) {
11444 unsupported = format;
11445 break;
11446 }
11447 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011448
Tony Barbourd6673642016-05-05 14:46:39 -060011449 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011450 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011452 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011453
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011454 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011455 m_errorMonitor->VerifyFound();
11456 }
11457}
11458
11459TEST_F(VkLayerTest, ImageLayerViewTests) {
11460 VkResult ret;
11461 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11462
11463 ASSERT_NO_FATAL_FAILURE(InitState());
11464
11465 VkImageObj image(m_device);
11466 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11467 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11468 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11469 VK_IMAGE_TILING_OPTIMAL, 0);
11470 ASSERT_TRUE(image.initialized());
11471
11472 VkImageView imgView;
11473 VkImageViewCreateInfo imgViewInfo = {};
11474 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11475 imgViewInfo.image = image.handle();
11476 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11477 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11478 imgViewInfo.subresourceRange.layerCount = 1;
11479 imgViewInfo.subresourceRange.baseMipLevel = 0;
11480 imgViewInfo.subresourceRange.levelCount = 1;
11481 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11482
11483 m_errorMonitor->SetDesiredFailureMsg(
11484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11485 "vkCreateImageView called with baseMipLevel");
11486 // View can't have baseMipLevel >= image's mipLevels - Expect
11487 // VIEW_CREATE_ERROR
11488 imgViewInfo.subresourceRange.baseMipLevel = 1;
11489 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11490 m_errorMonitor->VerifyFound();
11491 imgViewInfo.subresourceRange.baseMipLevel = 0;
11492
11493 m_errorMonitor->SetDesiredFailureMsg(
11494 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11495 "vkCreateImageView called with baseArrayLayer");
11496 // View can't have baseArrayLayer >= image's arraySize - Expect
11497 // VIEW_CREATE_ERROR
11498 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11499 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11500 m_errorMonitor->VerifyFound();
11501 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11502
11503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11504 "vkCreateImageView called with 0 in "
11505 "pCreateInfo->subresourceRange."
11506 "levelCount");
11507 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11508 imgViewInfo.subresourceRange.levelCount = 0;
11509 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11510 m_errorMonitor->VerifyFound();
11511 imgViewInfo.subresourceRange.levelCount = 1;
11512
11513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11514 "vkCreateImageView called with 0 in "
11515 "pCreateInfo->subresourceRange."
11516 "layerCount");
11517 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11518 imgViewInfo.subresourceRange.layerCount = 0;
11519 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11520 m_errorMonitor->VerifyFound();
11521 imgViewInfo.subresourceRange.layerCount = 1;
11522
11523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11524 "but both must be color formats");
11525 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11526 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11527 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11528 m_errorMonitor->VerifyFound();
11529 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11530
11531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11532 "Formats MUST be IDENTICAL unless "
11533 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11534 "was set on image creation.");
11535 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11536 // VIEW_CREATE_ERROR
11537 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11538 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11539 m_errorMonitor->VerifyFound();
11540 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11541
11542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11543 "can support ImageViews with "
11544 "differing formats but they must be "
11545 "in the same compatibility class.");
11546 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11547 // VIEW_CREATE_ERROR
11548 VkImageCreateInfo mutImgInfo = image.create_info();
11549 VkImage mutImage;
11550 mutImgInfo.format = VK_FORMAT_R8_UINT;
11551 assert(
11552 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11553 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11554 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11555 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11556 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11557 ASSERT_VK_SUCCESS(ret);
11558 imgViewInfo.image = mutImage;
11559 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11560 m_errorMonitor->VerifyFound();
11561 imgViewInfo.image = image.handle();
11562 vkDestroyImage(m_device->handle(), mutImage, NULL);
11563}
11564
11565TEST_F(VkLayerTest, MiscImageLayerTests) {
11566
11567 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11568
11569 ASSERT_NO_FATAL_FAILURE(InitState());
11570
11571 VkImageObj image(m_device);
11572 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11573 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11574 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11575 VK_IMAGE_TILING_OPTIMAL, 0);
11576 ASSERT_TRUE(image.initialized());
11577
11578 m_errorMonitor->SetDesiredFailureMsg(
11579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11580 "number of layers in image subresource is zero");
11581 vk_testing::Buffer buffer;
11582 VkMemoryPropertyFlags reqs = 0;
11583 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11584 VkBufferImageCopy region = {};
11585 region.bufferRowLength = 128;
11586 region.bufferImageHeight = 128;
11587 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11588 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11589 region.imageSubresource.layerCount = 0;
11590 region.imageExtent.height = 4;
11591 region.imageExtent.width = 4;
11592 region.imageExtent.depth = 1;
11593 m_commandBuffer->BeginCommandBuffer();
11594 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11595 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11596 1, &region);
11597 m_errorMonitor->VerifyFound();
11598 region.imageSubresource.layerCount = 1;
11599
11600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11601 "aspectMasks for each region must "
11602 "specify only COLOR or DEPTH or "
11603 "STENCIL");
11604 // Expect MISMATCHED_IMAGE_ASPECT
11605 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11606 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11607 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11608 1, &region);
11609 m_errorMonitor->VerifyFound();
11610 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11611
11612 m_errorMonitor->SetDesiredFailureMsg(
11613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11614 "If the format of srcImage is a depth, stencil, depth stencil or "
11615 "integer-based format then filter must be VK_FILTER_NEAREST");
11616 // Expect INVALID_FILTER
11617 VkImageObj intImage1(m_device);
11618 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11619 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11620 0);
11621 VkImageObj intImage2(m_device);
11622 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11623 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11624 0);
11625 VkImageBlit blitRegion = {};
11626 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11627 blitRegion.srcSubresource.baseArrayLayer = 0;
11628 blitRegion.srcSubresource.layerCount = 1;
11629 blitRegion.srcSubresource.mipLevel = 0;
11630 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11631 blitRegion.dstSubresource.baseArrayLayer = 0;
11632 blitRegion.dstSubresource.layerCount = 1;
11633 blitRegion.dstSubresource.mipLevel = 0;
11634
11635 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11636 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11637 16, &blitRegion, VK_FILTER_LINEAR);
11638 m_errorMonitor->VerifyFound();
11639
11640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11641 "called with 0 in ppMemoryBarriers");
11642 VkImageMemoryBarrier img_barrier;
11643 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11644 img_barrier.pNext = NULL;
11645 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11646 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11647 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11648 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11649 img_barrier.image = image.handle();
11650 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11651 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11652 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11653 img_barrier.subresourceRange.baseArrayLayer = 0;
11654 img_barrier.subresourceRange.baseMipLevel = 0;
11655 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11656 img_barrier.subresourceRange.layerCount = 0;
11657 img_barrier.subresourceRange.levelCount = 1;
11658 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11659 VK_PIPELINE_STAGE_HOST_BIT,
11660 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11661 nullptr, 1, &img_barrier);
11662 m_errorMonitor->VerifyFound();
11663 img_barrier.subresourceRange.layerCount = 1;
11664}
11665
11666TEST_F(VkLayerTest, ImageFormatLimits) {
11667
11668 TEST_DESCRIPTION("Exceed the limits of image format ");
11669
11670 m_errorMonitor->SetDesiredFailureMsg(
11671 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11672 "CreateImage extents exceed allowable limits for format");
11673 VkImageCreateInfo image_create_info = {};
11674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11675 image_create_info.pNext = NULL;
11676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11677 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11678 image_create_info.extent.width = 32;
11679 image_create_info.extent.height = 32;
11680 image_create_info.extent.depth = 1;
11681 image_create_info.mipLevels = 1;
11682 image_create_info.arrayLayers = 1;
11683 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11684 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11685 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11686 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11687 image_create_info.flags = 0;
11688
11689 VkImage nullImg;
11690 VkImageFormatProperties imgFmtProps;
11691 vkGetPhysicalDeviceImageFormatProperties(
11692 gpu(), image_create_info.format, image_create_info.imageType,
11693 image_create_info.tiling, image_create_info.usage,
11694 image_create_info.flags, &imgFmtProps);
11695 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11696 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11697 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11698 m_errorMonitor->VerifyFound();
11699 image_create_info.extent.depth = 1;
11700
11701 m_errorMonitor->SetDesiredFailureMsg(
11702 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11703 "exceeds allowable maximum supported by format of");
11704 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11705 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11706 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11707 m_errorMonitor->VerifyFound();
11708 image_create_info.mipLevels = 1;
11709
11710 m_errorMonitor->SetDesiredFailureMsg(
11711 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11712 "exceeds allowable maximum supported by format of");
11713 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11714 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11715 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11716 m_errorMonitor->VerifyFound();
11717 image_create_info.arrayLayers = 1;
11718
11719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11720 "is not supported by format");
11721 int samples = imgFmtProps.sampleCounts >> 1;
11722 image_create_info.samples = (VkSampleCountFlagBits)samples;
11723 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11724 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11725 m_errorMonitor->VerifyFound();
11726 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11727
11728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11729 "pCreateInfo->initialLayout, must be "
11730 "VK_IMAGE_LAYOUT_UNDEFINED or "
11731 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11732 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11733 // Expect INVALID_LAYOUT
11734 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11735 m_errorMonitor->VerifyFound();
11736 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11737}
11738
Karl Schultz6addd812016-02-02 17:17:23 -070011739TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011740 VkResult err;
11741 bool pass;
11742
11743 // Create color images with different format sizes and try to copy between them
11744 m_errorMonitor->SetDesiredFailureMsg(
11745 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11746 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11747
11748 ASSERT_NO_FATAL_FAILURE(InitState());
11749
11750 // Create two images of different types and try to copy between them
11751 VkImage srcImage;
11752 VkImage dstImage;
11753 VkDeviceMemory srcMem;
11754 VkDeviceMemory destMem;
11755 VkMemoryRequirements memReqs;
11756
11757 VkImageCreateInfo image_create_info = {};
11758 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11759 image_create_info.pNext = NULL;
11760 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11761 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11762 image_create_info.extent.width = 32;
11763 image_create_info.extent.height = 32;
11764 image_create_info.extent.depth = 1;
11765 image_create_info.mipLevels = 1;
11766 image_create_info.arrayLayers = 1;
11767 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11768 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11769 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11770 image_create_info.flags = 0;
11771
11772 err =
11773 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11774 ASSERT_VK_SUCCESS(err);
11775
11776 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11777 // Introduce failure by creating second image with a different-sized format.
11778 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11779
11780 err =
11781 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11782 ASSERT_VK_SUCCESS(err);
11783
11784 // Allocate memory
11785 VkMemoryAllocateInfo memAlloc = {};
11786 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11787 memAlloc.pNext = NULL;
11788 memAlloc.allocationSize = 0;
11789 memAlloc.memoryTypeIndex = 0;
11790
11791 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11792 memAlloc.allocationSize = memReqs.size;
11793 pass =
11794 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11795 ASSERT_TRUE(pass);
11796 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11797 ASSERT_VK_SUCCESS(err);
11798
11799 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11800 memAlloc.allocationSize = memReqs.size;
11801 pass =
11802 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11803 ASSERT_TRUE(pass);
11804 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11805 ASSERT_VK_SUCCESS(err);
11806
11807 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11808 ASSERT_VK_SUCCESS(err);
11809 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11810 ASSERT_VK_SUCCESS(err);
11811
11812 BeginCommandBuffer();
11813 VkImageCopy copyRegion;
11814 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11815 copyRegion.srcSubresource.mipLevel = 0;
11816 copyRegion.srcSubresource.baseArrayLayer = 0;
11817 copyRegion.srcSubresource.layerCount = 0;
11818 copyRegion.srcOffset.x = 0;
11819 copyRegion.srcOffset.y = 0;
11820 copyRegion.srcOffset.z = 0;
11821 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11822 copyRegion.dstSubresource.mipLevel = 0;
11823 copyRegion.dstSubresource.baseArrayLayer = 0;
11824 copyRegion.dstSubresource.layerCount = 0;
11825 copyRegion.dstOffset.x = 0;
11826 copyRegion.dstOffset.y = 0;
11827 copyRegion.dstOffset.z = 0;
11828 copyRegion.extent.width = 1;
11829 copyRegion.extent.height = 1;
11830 copyRegion.extent.depth = 1;
11831 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11832 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11833 EndCommandBuffer();
11834
11835 m_errorMonitor->VerifyFound();
11836
11837 vkDestroyImage(m_device->device(), srcImage, NULL);
11838 vkDestroyImage(m_device->device(), dstImage, NULL);
11839 vkFreeMemory(m_device->device(), srcMem, NULL);
11840 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011841}
11842
Karl Schultz6addd812016-02-02 17:17:23 -070011843TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11844 VkResult err;
11845 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011846
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011847 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011848 m_errorMonitor->SetDesiredFailureMsg(
11849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011850 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011851
Mike Stroyana3082432015-09-25 13:39:21 -060011852 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011853
11854 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011855 VkImage srcImage;
11856 VkImage dstImage;
11857 VkDeviceMemory srcMem;
11858 VkDeviceMemory destMem;
11859 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011860
11861 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011862 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11863 image_create_info.pNext = NULL;
11864 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11865 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11866 image_create_info.extent.width = 32;
11867 image_create_info.extent.height = 32;
11868 image_create_info.extent.depth = 1;
11869 image_create_info.mipLevels = 1;
11870 image_create_info.arrayLayers = 1;
11871 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11872 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11873 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11874 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011875
Karl Schultz6addd812016-02-02 17:17:23 -070011876 err =
11877 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011878 ASSERT_VK_SUCCESS(err);
11879
Karl Schultzbdb75952016-04-19 11:36:49 -060011880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11881
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011882 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011883 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011884 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11885 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011886
Karl Schultz6addd812016-02-02 17:17:23 -070011887 err =
11888 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011889 ASSERT_VK_SUCCESS(err);
11890
11891 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011892 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011893 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11894 memAlloc.pNext = NULL;
11895 memAlloc.allocationSize = 0;
11896 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011897
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011898 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011899 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011900 pass =
11901 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011902 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011903 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011904 ASSERT_VK_SUCCESS(err);
11905
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011906 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011907 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011908 pass =
11909 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011910 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011911 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011912 ASSERT_VK_SUCCESS(err);
11913
11914 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11915 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011916 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011917 ASSERT_VK_SUCCESS(err);
11918
11919 BeginCommandBuffer();
11920 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011921 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011922 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011923 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011924 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011925 copyRegion.srcOffset.x = 0;
11926 copyRegion.srcOffset.y = 0;
11927 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011928 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011929 copyRegion.dstSubresource.mipLevel = 0;
11930 copyRegion.dstSubresource.baseArrayLayer = 0;
11931 copyRegion.dstSubresource.layerCount = 0;
11932 copyRegion.dstOffset.x = 0;
11933 copyRegion.dstOffset.y = 0;
11934 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011935 copyRegion.extent.width = 1;
11936 copyRegion.extent.height = 1;
11937 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011938 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11939 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011940 EndCommandBuffer();
11941
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011942 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011943
Chia-I Wuf7458c52015-10-26 21:10:41 +080011944 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011945 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011946 vkFreeMemory(m_device->device(), srcMem, NULL);
11947 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011948}
11949
Karl Schultz6addd812016-02-02 17:17:23 -070011950TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11951 VkResult err;
11952 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011953
Karl Schultz6addd812016-02-02 17:17:23 -070011954 m_errorMonitor->SetDesiredFailureMsg(
11955 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011956 "vkCmdResolveImage called with source sample count less than 2.");
11957
Mike Stroyana3082432015-09-25 13:39:21 -060011958 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011959
11960 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011961 VkImage srcImage;
11962 VkImage dstImage;
11963 VkDeviceMemory srcMem;
11964 VkDeviceMemory destMem;
11965 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011966
11967 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011968 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11969 image_create_info.pNext = NULL;
11970 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11971 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11972 image_create_info.extent.width = 32;
11973 image_create_info.extent.height = 1;
11974 image_create_info.extent.depth = 1;
11975 image_create_info.mipLevels = 1;
11976 image_create_info.arrayLayers = 1;
11977 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11978 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11979 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11980 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011981
Karl Schultz6addd812016-02-02 17:17:23 -070011982 err =
11983 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011984 ASSERT_VK_SUCCESS(err);
11985
Karl Schultz6addd812016-02-02 17:17:23 -070011986 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011987
Karl Schultz6addd812016-02-02 17:17:23 -070011988 err =
11989 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011990 ASSERT_VK_SUCCESS(err);
11991
11992 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011993 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011994 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11995 memAlloc.pNext = NULL;
11996 memAlloc.allocationSize = 0;
11997 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011998
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011999 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012000 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012001 pass =
12002 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012003 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012004 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012005 ASSERT_VK_SUCCESS(err);
12006
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012007 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012008 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012009 pass =
12010 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012011 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012012 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012013 ASSERT_VK_SUCCESS(err);
12014
12015 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12016 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012017 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012018 ASSERT_VK_SUCCESS(err);
12019
12020 BeginCommandBuffer();
12021 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012022 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12023 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012024 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012025 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012026 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012027 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012028 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012029 resolveRegion.srcOffset.x = 0;
12030 resolveRegion.srcOffset.y = 0;
12031 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012032 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012033 resolveRegion.dstSubresource.mipLevel = 0;
12034 resolveRegion.dstSubresource.baseArrayLayer = 0;
12035 resolveRegion.dstSubresource.layerCount = 0;
12036 resolveRegion.dstOffset.x = 0;
12037 resolveRegion.dstOffset.y = 0;
12038 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012039 resolveRegion.extent.width = 1;
12040 resolveRegion.extent.height = 1;
12041 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012042 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12043 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012044 EndCommandBuffer();
12045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012046 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012047
Chia-I Wuf7458c52015-10-26 21:10:41 +080012048 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012049 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012050 vkFreeMemory(m_device->device(), srcMem, NULL);
12051 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012052}
12053
Karl Schultz6addd812016-02-02 17:17:23 -070012054TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
12055 VkResult err;
12056 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012057
Karl Schultz6addd812016-02-02 17:17:23 -070012058 m_errorMonitor->SetDesiredFailureMsg(
12059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012060 "vkCmdResolveImage called with dest sample count greater than 1.");
12061
Mike Stroyana3082432015-09-25 13:39:21 -060012062 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012063
Chris Forbesa7530692016-05-08 12:35:39 +120012064 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070012065 VkImage srcImage;
12066 VkImage dstImage;
12067 VkDeviceMemory srcMem;
12068 VkDeviceMemory destMem;
12069 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012070
12071 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012072 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12073 image_create_info.pNext = NULL;
12074 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12075 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12076 image_create_info.extent.width = 32;
12077 image_create_info.extent.height = 1;
12078 image_create_info.extent.depth = 1;
12079 image_create_info.mipLevels = 1;
12080 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012081 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012082 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12083 // Note: Some implementations expect color attachment usage for any
12084 // multisample surface
12085 image_create_info.usage =
12086 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12087 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012088
Karl Schultz6addd812016-02-02 17:17:23 -070012089 err =
12090 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012091 ASSERT_VK_SUCCESS(err);
12092
Karl Schultz6addd812016-02-02 17:17:23 -070012093 // Note: Some implementations expect color attachment usage for any
12094 // multisample surface
12095 image_create_info.usage =
12096 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012097
Karl Schultz6addd812016-02-02 17:17:23 -070012098 err =
12099 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012100 ASSERT_VK_SUCCESS(err);
12101
12102 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012103 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012104 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12105 memAlloc.pNext = NULL;
12106 memAlloc.allocationSize = 0;
12107 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012108
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012109 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012110 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012111 pass =
12112 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012113 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012114 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012115 ASSERT_VK_SUCCESS(err);
12116
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012117 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012118 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012119 pass =
12120 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012121 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012122 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012123 ASSERT_VK_SUCCESS(err);
12124
12125 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12126 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012127 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012128 ASSERT_VK_SUCCESS(err);
12129
12130 BeginCommandBuffer();
12131 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012132 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12133 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012134 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012135 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012136 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012137 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012138 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012139 resolveRegion.srcOffset.x = 0;
12140 resolveRegion.srcOffset.y = 0;
12141 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012142 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012143 resolveRegion.dstSubresource.mipLevel = 0;
12144 resolveRegion.dstSubresource.baseArrayLayer = 0;
12145 resolveRegion.dstSubresource.layerCount = 0;
12146 resolveRegion.dstOffset.x = 0;
12147 resolveRegion.dstOffset.y = 0;
12148 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012149 resolveRegion.extent.width = 1;
12150 resolveRegion.extent.height = 1;
12151 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012152 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12153 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012154 EndCommandBuffer();
12155
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012156 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012157
Chia-I Wuf7458c52015-10-26 21:10:41 +080012158 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012159 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012160 vkFreeMemory(m_device->device(), srcMem, NULL);
12161 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012162}
12163
Karl Schultz6addd812016-02-02 17:17:23 -070012164TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12165 VkResult err;
12166 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012167
Karl Schultz6addd812016-02-02 17:17:23 -070012168 m_errorMonitor->SetDesiredFailureMsg(
12169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012170 "vkCmdResolveImage called with unmatched source and dest formats.");
12171
Mike Stroyana3082432015-09-25 13:39:21 -060012172 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012173
12174 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012175 VkImage srcImage;
12176 VkImage dstImage;
12177 VkDeviceMemory srcMem;
12178 VkDeviceMemory destMem;
12179 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012180
12181 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012182 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12183 image_create_info.pNext = NULL;
12184 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12185 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12186 image_create_info.extent.width = 32;
12187 image_create_info.extent.height = 1;
12188 image_create_info.extent.depth = 1;
12189 image_create_info.mipLevels = 1;
12190 image_create_info.arrayLayers = 1;
12191 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12192 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12193 // Note: Some implementations expect color attachment usage for any
12194 // multisample surface
12195 image_create_info.usage =
12196 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12197 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012198
Karl Schultz6addd812016-02-02 17:17:23 -070012199 err =
12200 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012201 ASSERT_VK_SUCCESS(err);
12202
Karl Schultz6addd812016-02-02 17:17:23 -070012203 // Set format to something other than source image
12204 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12205 // Note: Some implementations expect color attachment usage for any
12206 // multisample surface
12207 image_create_info.usage =
12208 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12209 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012210
Karl Schultz6addd812016-02-02 17:17:23 -070012211 err =
12212 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012213 ASSERT_VK_SUCCESS(err);
12214
12215 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012216 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012217 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12218 memAlloc.pNext = NULL;
12219 memAlloc.allocationSize = 0;
12220 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012221
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012222 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012223 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012224 pass =
12225 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012226 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012227 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012228 ASSERT_VK_SUCCESS(err);
12229
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012230 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012231 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012232 pass =
12233 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012234 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012235 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012236 ASSERT_VK_SUCCESS(err);
12237
12238 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12239 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012240 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012241 ASSERT_VK_SUCCESS(err);
12242
12243 BeginCommandBuffer();
12244 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012245 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12246 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012247 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012248 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012249 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012250 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012251 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012252 resolveRegion.srcOffset.x = 0;
12253 resolveRegion.srcOffset.y = 0;
12254 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012255 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012256 resolveRegion.dstSubresource.mipLevel = 0;
12257 resolveRegion.dstSubresource.baseArrayLayer = 0;
12258 resolveRegion.dstSubresource.layerCount = 0;
12259 resolveRegion.dstOffset.x = 0;
12260 resolveRegion.dstOffset.y = 0;
12261 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012262 resolveRegion.extent.width = 1;
12263 resolveRegion.extent.height = 1;
12264 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012265 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12266 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012267 EndCommandBuffer();
12268
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012269 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012270
Chia-I Wuf7458c52015-10-26 21:10:41 +080012271 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012272 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012273 vkFreeMemory(m_device->device(), srcMem, NULL);
12274 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012275}
12276
Karl Schultz6addd812016-02-02 17:17:23 -070012277TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12278 VkResult err;
12279 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012280
Karl Schultz6addd812016-02-02 17:17:23 -070012281 m_errorMonitor->SetDesiredFailureMsg(
12282 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012283 "vkCmdResolveImage called with unmatched source and dest image types.");
12284
Mike Stroyana3082432015-09-25 13:39:21 -060012285 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012286
12287 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012288 VkImage srcImage;
12289 VkImage dstImage;
12290 VkDeviceMemory srcMem;
12291 VkDeviceMemory destMem;
12292 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012293
12294 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012295 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12296 image_create_info.pNext = NULL;
12297 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12298 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12299 image_create_info.extent.width = 32;
12300 image_create_info.extent.height = 1;
12301 image_create_info.extent.depth = 1;
12302 image_create_info.mipLevels = 1;
12303 image_create_info.arrayLayers = 1;
12304 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12305 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12306 // Note: Some implementations expect color attachment usage for any
12307 // multisample surface
12308 image_create_info.usage =
12309 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12310 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012311
Karl Schultz6addd812016-02-02 17:17:23 -070012312 err =
12313 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012314 ASSERT_VK_SUCCESS(err);
12315
Karl Schultz6addd812016-02-02 17:17:23 -070012316 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12317 // Note: Some implementations expect color attachment usage for any
12318 // multisample surface
12319 image_create_info.usage =
12320 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012322
Karl Schultz6addd812016-02-02 17:17:23 -070012323 err =
12324 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012325 ASSERT_VK_SUCCESS(err);
12326
12327 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012328 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012329 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12330 memAlloc.pNext = NULL;
12331 memAlloc.allocationSize = 0;
12332 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012333
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012334 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012335 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012336 pass =
12337 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012338 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012339 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012340 ASSERT_VK_SUCCESS(err);
12341
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012342 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012343 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012344 pass =
12345 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012346 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012347 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012348 ASSERT_VK_SUCCESS(err);
12349
12350 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12351 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012352 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012353 ASSERT_VK_SUCCESS(err);
12354
12355 BeginCommandBuffer();
12356 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012357 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12358 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012359 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012360 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012361 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012362 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012363 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012364 resolveRegion.srcOffset.x = 0;
12365 resolveRegion.srcOffset.y = 0;
12366 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012367 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012368 resolveRegion.dstSubresource.mipLevel = 0;
12369 resolveRegion.dstSubresource.baseArrayLayer = 0;
12370 resolveRegion.dstSubresource.layerCount = 0;
12371 resolveRegion.dstOffset.x = 0;
12372 resolveRegion.dstOffset.y = 0;
12373 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012374 resolveRegion.extent.width = 1;
12375 resolveRegion.extent.height = 1;
12376 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012377 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12378 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012379 EndCommandBuffer();
12380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012381 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012382
Chia-I Wuf7458c52015-10-26 21:10:41 +080012383 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012384 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012385 vkFreeMemory(m_device->device(), srcMem, NULL);
12386 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012387}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012388
Karl Schultz6addd812016-02-02 17:17:23 -070012389TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012390 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012391 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12392 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012393 // The image format check comes 2nd in validation so we trigger it first,
12394 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012395 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012396
Karl Schultz6addd812016-02-02 17:17:23 -070012397 m_errorMonitor->SetDesiredFailureMsg(
12398 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012399 "Combination depth/stencil image formats can have only the ");
12400
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012401 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012402
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012403 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012404 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12405 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012406
12407 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012408 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12409 ds_pool_ci.pNext = NULL;
12410 ds_pool_ci.maxSets = 1;
12411 ds_pool_ci.poolSizeCount = 1;
12412 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012413
12414 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012415 err =
12416 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012417 ASSERT_VK_SUCCESS(err);
12418
12419 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012420 dsl_binding.binding = 0;
12421 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12422 dsl_binding.descriptorCount = 1;
12423 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12424 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012425
12426 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012427 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12428 ds_layout_ci.pNext = NULL;
12429 ds_layout_ci.bindingCount = 1;
12430 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012431 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012432 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12433 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012434 ASSERT_VK_SUCCESS(err);
12435
12436 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012437 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012438 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012439 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012440 alloc_info.descriptorPool = ds_pool;
12441 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012442 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12443 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012444 ASSERT_VK_SUCCESS(err);
12445
Karl Schultz6addd812016-02-02 17:17:23 -070012446 VkImage image_bad;
12447 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012448 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012449 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012450 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012451 const int32_t tex_width = 32;
12452 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012453
12454 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012455 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12456 image_create_info.pNext = NULL;
12457 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12458 image_create_info.format = tex_format_bad;
12459 image_create_info.extent.width = tex_width;
12460 image_create_info.extent.height = tex_height;
12461 image_create_info.extent.depth = 1;
12462 image_create_info.mipLevels = 1;
12463 image_create_info.arrayLayers = 1;
12464 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12465 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12466 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12467 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12468 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012469
Karl Schultz6addd812016-02-02 17:17:23 -070012470 err =
12471 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012472 ASSERT_VK_SUCCESS(err);
12473 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012474 image_create_info.usage =
12475 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12476 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12477 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012478 ASSERT_VK_SUCCESS(err);
12479
12480 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012481 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12482 image_view_create_info.image = image_bad;
12483 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12484 image_view_create_info.format = tex_format_bad;
12485 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12486 image_view_create_info.subresourceRange.baseMipLevel = 0;
12487 image_view_create_info.subresourceRange.layerCount = 1;
12488 image_view_create_info.subresourceRange.levelCount = 1;
12489 image_view_create_info.subresourceRange.aspectMask =
12490 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012491
12492 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012493 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12494 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012495
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012496 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012497
Chia-I Wuf7458c52015-10-26 21:10:41 +080012498 vkDestroyImage(m_device->device(), image_bad, NULL);
12499 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012502}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012503
12504TEST_F(VkLayerTest, ClearImageErrors) {
12505 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12506 "ClearDepthStencilImage with a color image.");
12507
12508 ASSERT_NO_FATAL_FAILURE(InitState());
12509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12510
12511 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12512 BeginCommandBuffer();
12513 m_commandBuffer->EndRenderPass();
12514
12515 // Color image
12516 VkClearColorValue clear_color;
12517 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12518 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12519 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12520 const int32_t img_width = 32;
12521 const int32_t img_height = 32;
12522 VkImageCreateInfo image_create_info = {};
12523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12524 image_create_info.pNext = NULL;
12525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12526 image_create_info.format = color_format;
12527 image_create_info.extent.width = img_width;
12528 image_create_info.extent.height = img_height;
12529 image_create_info.extent.depth = 1;
12530 image_create_info.mipLevels = 1;
12531 image_create_info.arrayLayers = 1;
12532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12533 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12535
12536 vk_testing::Image color_image;
12537 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12538 reqs);
12539
12540 const VkImageSubresourceRange color_range =
12541 vk_testing::Image::subresource_range(image_create_info,
12542 VK_IMAGE_ASPECT_COLOR_BIT);
12543
12544 // Depth/Stencil image
12545 VkClearDepthStencilValue clear_value = {0};
12546 reqs = 0; // don't need HOST_VISIBLE DS image
12547 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12548 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12549 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12550 ds_image_create_info.extent.width = 64;
12551 ds_image_create_info.extent.height = 64;
12552 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12553 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12554
12555 vk_testing::Image ds_image;
12556 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12557 reqs);
12558
12559 const VkImageSubresourceRange ds_range =
12560 vk_testing::Image::subresource_range(ds_image_create_info,
12561 VK_IMAGE_ASPECT_DEPTH_BIT);
12562
12563 m_errorMonitor->SetDesiredFailureMsg(
12564 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12565 "vkCmdClearColorImage called with depth/stencil image.");
12566
12567 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12568 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12569 &color_range);
12570
12571 m_errorMonitor->VerifyFound();
12572
Tony Barbour26434b92016-06-02 09:43:50 -060012573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12574 "vkCmdClearColorImage called with "
12575 "image created without "
12576 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12577
12578 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12579 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12580 &color_range);
12581
12582 m_errorMonitor->VerifyFound();
12583
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012584 // Call CmdClearDepthStencilImage with color image
12585 m_errorMonitor->SetDesiredFailureMsg(
12586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12587 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12588
12589 vkCmdClearDepthStencilImage(
12590 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12591 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12592 &ds_range);
12593
12594 m_errorMonitor->VerifyFound();
12595}
Tobin Ehliscde08892015-09-22 10:11:37 -060012596#endif // IMAGE_TESTS
12597
Tony Barbour300a6082015-04-07 13:44:53 -060012598int main(int argc, char **argv) {
12599 int result;
12600
Cody Northrop8e54a402016-03-08 22:25:52 -070012601#ifdef ANDROID
12602 int vulkanSupport = InitVulkan();
12603 if (vulkanSupport == 0)
12604 return 1;
12605#endif
12606
Tony Barbour300a6082015-04-07 13:44:53 -060012607 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012608 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012609
12610 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12611
12612 result = RUN_ALL_TESTS();
12613
Tony Barbour6918cd52015-04-09 12:58:51 -060012614 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012615 return result;
12616}