blob: 0afd75288f389e9b31adc582c84c0cb92c323a0f [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
1424 mmr.memory = mem;
1425 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1426 m_errorMonitor->SetDesiredFailureMsg(
1427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 ") is less than Memory Object's offset (");
1429 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1430 m_errorMonitor->VerifyFound();
1431 // Now flush range that oversteps mapped range
1432 vkUnmapMemory(m_device->device(), mem);
1433 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1434 ASSERT_VK_SUCCESS(err);
1435 mmr.offset = 16;
1436 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1437 m_errorMonitor->SetDesiredFailureMsg(
1438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 ") exceeds the Memory Object's upper-bound (");
1440 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1441 m_errorMonitor->VerifyFound();
1442
1443 pass =
1444 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1445 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1446 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1447 if (!pass) {
1448 vkFreeMemory(m_device->device(), mem, NULL);
1449 vkDestroyBuffer(m_device->device(), buffer, NULL);
1450 return;
1451 }
1452 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1453 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1454
1455 vkDestroyBuffer(m_device->device(), buffer, NULL);
1456 vkFreeMemory(m_device->device(), mem, NULL);
1457}
1458
Ian Elliott1c32c772016-04-28 14:47:13 -06001459TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1460 VkResult err;
1461 bool pass;
1462
Ian Elliott489eec02016-05-05 14:12:44 -06001463// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1464// following declaration (which is temporarily being moved below):
1465// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001466 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1467 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1468 uint32_t swapchain_image_count = 0;
1469// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1470 uint32_t image_index = 0;
1471// VkPresentInfoKHR present_info = {};
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1476#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1477 // Use the functions from the VK_KHR_android_surface extension without
1478 // enabling that extension:
1479
1480 // Create a surface:
1481 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001482 m_errorMonitor->SetDesiredFailureMsg(
1483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1484 "extension was not enabled for this");
1485 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1486 &surface);
1487 pass = (err != VK_SUCCESS);
1488 ASSERT_TRUE(pass);
1489 m_errorMonitor->VerifyFound();
1490#endif // VK_USE_PLATFORM_ANDROID_KHR
1491
1492
1493#if defined(VK_USE_PLATFORM_MIR_KHR)
1494 // Use the functions from the VK_KHR_mir_surface extension without enabling
1495 // that extension:
1496
1497 // Create a surface:
1498 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001499 m_errorMonitor->SetDesiredFailureMsg(
1500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1501 "extension was not enabled for this");
1502 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1503 pass = (err != VK_SUCCESS);
1504 ASSERT_TRUE(pass);
1505 m_errorMonitor->VerifyFound();
1506
1507 // Tell whether an mir_connection supports presentation:
1508 MirConnection *mir_connection = NULL;
1509 m_errorMonitor->SetDesiredFailureMsg(
1510 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1511 "extension was not enabled for this");
1512 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1513 visual_id);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_MIR_KHR
1516
1517
1518#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1519 // Use the functions from the VK_KHR_wayland_surface extension without
1520 // enabling that extension:
1521
1522 // Create a surface:
1523 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 m_errorMonitor->SetDesiredFailureMsg(
1525 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526 "extension was not enabled for this");
1527 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1528 &surface);
1529 pass = (err != VK_SUCCESS);
1530 ASSERT_TRUE(pass);
1531 m_errorMonitor->VerifyFound();
1532
1533 // Tell whether an wayland_display supports presentation:
1534 struct wl_display wayland_display = {};
1535 m_errorMonitor->SetDesiredFailureMsg(
1536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "extension was not enabled for this");
1538 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1539 &wayland_display);
1540 m_errorMonitor->VerifyFound();
1541#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001542#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001543
1544
1545#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001546// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1547// TO NON-LINUX PLATFORMS:
1548VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 // Use the functions from the VK_KHR_win32_surface extension without
1550 // enabling that extension:
1551
1552 // Create a surface:
1553 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 m_errorMonitor->SetDesiredFailureMsg(
1555 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "extension was not enabled for this");
1557 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1558 &surface);
1559 pass = (err != VK_SUCCESS);
1560 ASSERT_TRUE(pass);
1561 m_errorMonitor->VerifyFound();
1562
1563 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001564 m_errorMonitor->SetDesiredFailureMsg(
1565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1566 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
1573
Ian Elliott1c32c772016-04-28 14:47:13 -06001574#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001575// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1576// TO NON-LINUX PLATFORMS:
1577VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1579 // that extension:
1580
1581 // Create a surface:
1582 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 m_errorMonitor->SetDesiredFailureMsg(
1584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1585 "extension was not enabled for this");
1586 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1587 pass = (err != VK_SUCCESS);
1588 ASSERT_TRUE(pass);
1589 m_errorMonitor->VerifyFound();
1590
1591 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 xcb_visualid_t visual_id = 0;
1594 m_errorMonitor->SetDesiredFailureMsg(
1595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1596 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001598 visual_id);
1599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
1610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001611 m_errorMonitor->SetDesiredFailureMsg(
1612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1613 "extension was not enabled for this");
1614 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1615 pass = (err != VK_SUCCESS);
1616 ASSERT_TRUE(pass);
1617 m_errorMonitor->VerifyFound();
1618
1619 // Tell whether an Xlib VisualID supports presentation:
1620 Display *dpy = NULL;
1621 VisualID visual = 0;
1622 m_errorMonitor->SetDesiredFailureMsg(
1623 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1624 "extension was not enabled for this");
1625 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1626 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001627// Set this (for now, until all platforms are supported and tested):
1628#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001629#endif // VK_USE_PLATFORM_XLIB_KHR
1630
1631
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 // Use the functions from the VK_KHR_surface extension without enabling
1633 // that extension:
1634
Ian Elliott489eec02016-05-05 14:12:44 -06001635#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001636 // Destroy a surface:
1637 m_errorMonitor->SetDesiredFailureMsg(
1638 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1639 "extension was not enabled for this");
1640 vkDestroySurfaceKHR(instance(), surface, NULL);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check if surface supports presentation:
1644 VkBool32 supported = false;
1645 m_errorMonitor->SetDesiredFailureMsg(
1646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1647 "extension was not enabled for this");
1648 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1649 pass = (err != VK_SUCCESS);
1650 ASSERT_TRUE(pass);
1651 m_errorMonitor->VerifyFound();
1652
1653 // Check surface capabilities:
1654 VkSurfaceCapabilitiesKHR capabilities = {};
1655 m_errorMonitor->SetDesiredFailureMsg(
1656 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1657 "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1659 &capabilities);
1660 pass = (err != VK_SUCCESS);
1661 ASSERT_TRUE(pass);
1662 m_errorMonitor->VerifyFound();
1663
1664 // Check surface formats:
1665 uint32_t format_count = 0;
1666 VkSurfaceFormatKHR *formats = NULL;
1667 m_errorMonitor->SetDesiredFailureMsg(
1668 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1669 "extension was not enabled for this");
1670 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1671 &format_count, formats);
1672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Check surface present modes:
1677 uint32_t present_mode_count = 0;
1678 VkSurfaceFormatKHR *present_modes = NULL;
1679 m_errorMonitor->SetDesiredFailureMsg(
1680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1681 "extension was not enabled for this");
1682 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1683 &present_mode_count, present_modes);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001687#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688
1689
1690 // Use the functions from the VK_KHR_swapchain extension without enabling
1691 // that extension:
1692
1693 // Create a swapchain:
1694 m_errorMonitor->SetDesiredFailureMsg(
1695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1696 "extension was not enabled for this");
1697 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1698 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001699 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1700 NULL, &swapchain);
1701 pass = (err != VK_SUCCESS);
1702 ASSERT_TRUE(pass);
1703 m_errorMonitor->VerifyFound();
1704
1705 // Get the images from the swapchain:
1706 m_errorMonitor->SetDesiredFailureMsg(
1707 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "extension was not enabled for this");
1709 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1710 &swapchain_image_count, NULL);
1711 pass = (err != VK_SUCCESS);
1712 ASSERT_TRUE(pass);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Try to acquire an image:
1716 m_errorMonitor->SetDesiredFailureMsg(
1717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1718 "extension was not enabled for this");
1719 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1720 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1721 pass = (err != VK_SUCCESS);
1722 ASSERT_TRUE(pass);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001726 //
1727 // NOTE: Currently can't test this because a real swapchain is needed (as
1728 // opposed to the fake one we created) in order for the layer to lookup the
1729 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001730
1731 // Destroy the swapchain:
1732 m_errorMonitor->SetDesiredFailureMsg(
1733 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1734 "extension was not enabled for this");
1735 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1736 m_errorMonitor->VerifyFound();
1737}
1738
Ian Elliott2c1daf52016-05-12 09:41:46 -06001739TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740
Dustin Graves6c6d8982016-05-17 10:09:21 -06001741#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001743
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744 VkResult err;
1745 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001746 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1747 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001748 // uint32_t swapchain_image_count = 0;
1749 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1750 // uint32_t image_index = 0;
1751 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001752
1753 ASSERT_NO_FATAL_FAILURE(InitState());
1754
1755 // Use the create function from one of the VK_KHR_*_surface extension in
1756 // order to create a surface, testing all known errors in the process,
1757 // before successfully creating a surface:
1758 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001761 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1762 pass = (err != VK_SUCCESS);
1763 ASSERT_TRUE(pass);
1764 m_errorMonitor->VerifyFound();
1765
1766 // Next, try to create a surface with the wrong
1767 // VkXcbSurfaceCreateInfoKHR::sType:
1768 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1769 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1771 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001772 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
Ian Elliott2c1daf52016-05-12 09:41:46 -06001777 // Create a native window, and then correctly create a surface:
1778 xcb_connection_t *connection;
1779 xcb_screen_t *screen;
1780 xcb_window_t xcb_window;
1781 xcb_intern_atom_reply_t *atom_wm_delete_window;
1782
1783 const xcb_setup_t *setup;
1784 xcb_screen_iterator_t iter;
1785 int scr;
1786 uint32_t value_mask, value_list[32];
1787 int width = 1;
1788 int height = 1;
1789
1790 connection = xcb_connect(NULL, &scr);
1791 ASSERT_TRUE(connection != NULL);
1792 setup = xcb_get_setup(connection);
1793 iter = xcb_setup_roots_iterator(setup);
1794 while (scr-- > 0)
1795 xcb_screen_next(&iter);
1796 screen = iter.data;
1797
1798 xcb_window = xcb_generate_id(connection);
1799
1800 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1801 value_list[0] = screen->black_pixel;
1802 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1803 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1804
1805 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1806 screen->root, 0, 0, width, height, 0,
1807 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1808 value_mask, value_list);
1809
1810 /* Magic code that will send notification when window is destroyed */
1811 xcb_intern_atom_cookie_t cookie =
1812 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1813 xcb_intern_atom_reply_t *reply =
1814 xcb_intern_atom_reply(connection, cookie, 0);
1815
1816 xcb_intern_atom_cookie_t cookie2 =
1817 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001818 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001819 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1820 (*reply).atom, 4, 32, 1,
1821 &(*atom_wm_delete_window).atom);
1822 free(reply);
1823
1824 xcb_map_window(connection, xcb_window);
1825
1826 // Force the x/y coordinates to 100,100 results are identical in consecutive
1827 // runs
1828 const uint32_t coords[] = {100, 100};
1829 xcb_configure_window(connection, xcb_window,
1830 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1831
Ian Elliott2c1daf52016-05-12 09:41:46 -06001832 // Finally, try to correctly create a surface:
1833 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1834 xcb_create_info.pNext = NULL;
1835 xcb_create_info.flags = 0;
1836 xcb_create_info.connection = connection;
1837 xcb_create_info.window = xcb_window;
1838 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1839 pass = (err == VK_SUCCESS);
1840 ASSERT_TRUE(pass);
1841
Ian Elliott2c1daf52016-05-12 09:41:46 -06001842 // Check if surface supports presentation:
1843
1844 // 1st, do so without having queried the queue families:
1845 VkBool32 supported = false;
1846 // TODO: Get the following error to come out:
1847 m_errorMonitor->SetDesiredFailureMsg(
1848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1849 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1850 "function");
1851 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1852 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 // ASSERT_TRUE(pass);
1854 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855
1856 // Next, query a queue family index that's too large:
1857 m_errorMonitor->SetDesiredFailureMsg(
1858 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1859 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001860 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1861 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 pass = (err != VK_SUCCESS);
1863 ASSERT_TRUE(pass);
1864 m_errorMonitor->VerifyFound();
1865
1866 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001867 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1868 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001869 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1870 pass = (err == VK_SUCCESS);
1871 ASSERT_TRUE(pass);
1872
Ian Elliott2c1daf52016-05-12 09:41:46 -06001873 // Before proceeding, try to create a swapchain without having called
1874 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1875 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1876 swapchain_create_info.pNext = NULL;
1877 swapchain_create_info.flags = 0;
1878 m_errorMonitor->SetDesiredFailureMsg(
1879 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1880 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001881 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1882 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001883 pass = (err != VK_SUCCESS);
1884 ASSERT_TRUE(pass);
1885 m_errorMonitor->VerifyFound();
1886
Ian Elliott2c1daf52016-05-12 09:41:46 -06001887 // Get the surface capabilities:
1888 VkSurfaceCapabilitiesKHR surface_capabilities;
1889
1890 // Do so correctly (only error logged by this entrypoint is if the
1891 // extension isn't enabled):
1892 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1893 &surface_capabilities);
1894 pass = (err == VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896
Ian Elliott2c1daf52016-05-12 09:41:46 -06001897 // Get the surface formats:
1898 uint32_t surface_format_count;
1899
1900 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1902 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001903 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1904 pass = (err == VK_SUCCESS);
1905 ASSERT_TRUE(pass);
1906 m_errorMonitor->VerifyFound();
1907
1908 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1909 // correctly done a 1st try (to get the count):
1910 m_errorMonitor->SetDesiredFailureMsg(
1911 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1912 "but no prior positive value has been seen for");
1913 surface_format_count = 0;
1914 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001915 gpu(), surface, &surface_format_count,
1916 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001917 pass = (err == VK_SUCCESS);
1918 ASSERT_TRUE(pass);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001922 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1923 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001924 pass = (err == VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926
1927 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001928 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1929 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001930
1931 // Next, do a 2nd try with surface_format_count being set too high:
1932 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1934 "that is greater than the value");
1935 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001936 surface_formats);
1937 pass = (err == VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001942 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1943 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001944 pass = (err == VK_SUCCESS);
1945 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001946 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001947 surface_formats);
1948 pass = (err == VK_SUCCESS);
1949 ASSERT_TRUE(pass);
1950
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951 // Get the surface present modes:
1952 uint32_t surface_present_mode_count;
1953
1954 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1956 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001957 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1958 pass = (err == VK_SUCCESS);
1959 ASSERT_TRUE(pass);
1960 m_errorMonitor->VerifyFound();
1961
1962 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1963 // correctly done a 1st try (to get the count):
1964 m_errorMonitor->SetDesiredFailureMsg(
1965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1966 "but no prior positive value has been seen for");
1967 surface_present_mode_count = 0;
1968 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001969 gpu(), surface, &surface_present_mode_count,
1970 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001971 pass = (err == VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
1975 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001976 vkGetPhysicalDeviceSurfacePresentModesKHR(
1977 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001978 pass = (err == VK_SUCCESS);
1979 ASSERT_TRUE(pass);
1980
1981 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001982 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1983 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001984
1985 // Next, do a 2nd try with surface_format_count being set too high:
1986 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1988 "that is greater than the value");
1989 vkGetPhysicalDeviceSurfacePresentModesKHR(
1990 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001991 pass = (err == VK_SUCCESS);
1992 ASSERT_TRUE(pass);
1993 m_errorMonitor->VerifyFound();
1994
1995 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001996 vkGetPhysicalDeviceSurfacePresentModesKHR(
1997 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 pass = (err == VK_SUCCESS);
1999 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002000 vkGetPhysicalDeviceSurfacePresentModesKHR(
2001 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002002 pass = (err == VK_SUCCESS);
2003 ASSERT_TRUE(pass);
2004
Ian Elliott2c1daf52016-05-12 09:41:46 -06002005 // Create a swapchain:
2006
2007 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2009 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2011 pass = (err != VK_SUCCESS);
2012 ASSERT_TRUE(pass);
2013 m_errorMonitor->VerifyFound();
2014
2015 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2016 // sType:
2017 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2019 "called with the wrong value for");
2020 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2021 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002022 pass = (err != VK_SUCCESS);
2023 ASSERT_TRUE(pass);
2024 m_errorMonitor->VerifyFound();
2025
2026 // Next, call with a NULL swapchain pointer:
2027 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2028 swapchain_create_info.pNext = NULL;
2029 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2031 "called with NULL pointer");
2032 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2033 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002034 pass = (err != VK_SUCCESS);
2035 ASSERT_TRUE(pass);
2036 m_errorMonitor->VerifyFound();
2037
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002038 // TODO: Enhance swapchain layer so that
2039 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002040
2041 // Next, call with a queue family index that's too large:
2042 uint32_t queueFamilyIndex[2] = {100000, 0};
2043 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2044 swapchain_create_info.queueFamilyIndexCount = 2;
2045 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2046 m_errorMonitor->SetDesiredFailureMsg(
2047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2048 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002049 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2050 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002051 pass = (err != VK_SUCCESS);
2052 ASSERT_TRUE(pass);
2053 m_errorMonitor->VerifyFound();
2054
2055 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2056 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2057 swapchain_create_info.queueFamilyIndexCount = 1;
2058 m_errorMonitor->SetDesiredFailureMsg(
2059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2060 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2061 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002062 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2063 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002064 pass = (err != VK_SUCCESS);
2065 ASSERT_TRUE(pass);
2066 m_errorMonitor->VerifyFound();
2067
2068 // Next, call with an invalid imageSharingMode:
2069 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2070 swapchain_create_info.queueFamilyIndexCount = 1;
2071 m_errorMonitor->SetDesiredFailureMsg(
2072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2073 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2075 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002076 pass = (err != VK_SUCCESS);
2077 ASSERT_TRUE(pass);
2078 m_errorMonitor->VerifyFound();
2079 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002080 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2081 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002082 swapchain_create_info.queueFamilyIndexCount = 0;
2083 queueFamilyIndex[0] = 0;
2084 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2085
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002086 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002087 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Destroy the swapchain:
2091
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002092 // TODOs:
2093 //
2094 // - Try destroying the device without first destroying the swapchain
2095 //
2096 // - Try destroying the device without first destroying the surface
2097 //
2098 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002099
2100 // Destroy the surface:
2101 vkDestroySurfaceKHR(instance(), surface, NULL);
2102
Ian Elliott2c1daf52016-05-12 09:41:46 -06002103 // Tear down the window:
2104 xcb_destroy_window(connection, xcb_window);
2105 xcb_disconnect(connection);
2106
2107#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002108 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002109#endif // VK_USE_PLATFORM_XCB_KHR
2110}
2111
Karl Schultz6addd812016-02-02 17:17:23 -07002112TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2113 VkResult err;
2114 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002115
Karl Schultz6addd812016-02-02 17:17:23 -07002116 m_errorMonitor->SetDesiredFailureMsg(
2117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002118 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2119
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121
2122 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002123 VkImage image;
2124 VkDeviceMemory mem;
2125 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002126
Karl Schultz6addd812016-02-02 17:17:23 -07002127 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2128 const int32_t tex_width = 32;
2129 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002130
Tony Barboureb254902015-07-15 12:50:33 -06002131 VkImageCreateInfo image_create_info = {};
2132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002133 image_create_info.pNext = NULL;
2134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2135 image_create_info.format = tex_format;
2136 image_create_info.extent.width = tex_width;
2137 image_create_info.extent.height = tex_height;
2138 image_create_info.extent.depth = 1;
2139 image_create_info.mipLevels = 1;
2140 image_create_info.arrayLayers = 1;
2141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2144 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002145
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002146 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002147 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002148 mem_alloc.pNext = NULL;
2149 mem_alloc.allocationSize = 0;
2150 // Introduce failure, do NOT set memProps to
2151 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2152 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002153
Chia-I Wuf7458c52015-10-26 21:10:41 +08002154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002155 ASSERT_VK_SUCCESS(err);
2156
Karl Schultz6addd812016-02-02 17:17:23 -07002157 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002158
Mark Lobodzinski23065352015-05-29 09:32:35 -05002159 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002160
Karl Schultz6addd812016-02-02 17:17:23 -07002161 pass =
2162 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2163 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2164 if (!pass) { // If we can't find any unmappable memory this test doesn't
2165 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002167 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002169
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002171 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002172 ASSERT_VK_SUCCESS(err);
2173
2174 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002175 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002176 ASSERT_VK_SUCCESS(err);
2177
2178 // Map memory as if to initialize the image
2179 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002180 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2181 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002183 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002184
Chia-I Wuf7458c52015-10-26 21:10:41 +08002185 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002186 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002187}
2188
Karl Schultz6addd812016-02-02 17:17:23 -07002189TEST_F(VkLayerTest, RebindMemory) {
2190 VkResult err;
2191 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002192
Karl Schultz6addd812016-02-02 17:17:23 -07002193 m_errorMonitor->SetDesiredFailureMsg(
2194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002195 "which has already been bound to mem object");
2196
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002197 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198
2199 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002200 VkImage image;
2201 VkDeviceMemory mem1;
2202 VkDeviceMemory mem2;
2203 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002204
Karl Schultz6addd812016-02-02 17:17:23 -07002205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2206 const int32_t tex_width = 32;
2207 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002208
Tony Barboureb254902015-07-15 12:50:33 -06002209 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2211 image_create_info.pNext = NULL;
2212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2213 image_create_info.format = tex_format;
2214 image_create_info.extent.width = tex_width;
2215 image_create_info.extent.height = tex_height;
2216 image_create_info.extent.depth = 1;
2217 image_create_info.mipLevels = 1;
2218 image_create_info.arrayLayers = 1;
2219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2222 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002223
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002224 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002225 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2226 mem_alloc.pNext = NULL;
2227 mem_alloc.allocationSize = 0;
2228 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002229
Karl Schultz6addd812016-02-02 17:17:23 -07002230 // Introduce failure, do NOT set memProps to
2231 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002232 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002234 ASSERT_VK_SUCCESS(err);
2235
Karl Schultz6addd812016-02-02 17:17:23 -07002236 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002237
2238 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002239 pass =
2240 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002241 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002242
2243 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002245 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002247 ASSERT_VK_SUCCESS(err);
2248
2249 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002250 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002251 ASSERT_VK_SUCCESS(err);
2252
Karl Schultz6addd812016-02-02 17:17:23 -07002253 // Introduce validation failure, try to bind a different memory object to
2254 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002255 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002258
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 vkDestroyImage(m_device->device(), image, NULL);
2260 vkFreeMemory(m_device->device(), mem1, NULL);
2261 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002262}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002263
Karl Schultz6addd812016-02-02 17:17:23 -07002264TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002265 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002266
Karl Schultz6addd812016-02-02 17:17:23 -07002267 m_errorMonitor->SetDesiredFailureMsg(
2268 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2269 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002270
2271 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002272 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2273 fenceInfo.pNext = NULL;
2274 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002275
Tony Barbour300a6082015-04-07 13:44:53 -06002276 ASSERT_NO_FATAL_FAILURE(InitState());
2277 ASSERT_NO_FATAL_FAILURE(InitViewport());
2278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2279
Tony Barbourfe3351b2015-07-28 10:17:20 -06002280 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2282 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002283 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002284
2285 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002286
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002287 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002288 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2289 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002290 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002291 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002292 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002293 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002295 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002296 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002297
2298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002299 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002301 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002302}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002303// This is a positive test. We used to expect error in this case but spec now
2304// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002305TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002306 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002307 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002308 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002309 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2310 fenceInfo.pNext = NULL;
2311
Tony Barbour0b4d9562015-04-09 10:48:04 -06002312 ASSERT_NO_FATAL_FAILURE(InitState());
2313 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002314 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002315 VkResult result = vkResetFences(m_device->device(), 1, fences);
2316 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002317
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002318 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002319}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002320
Chris Forbes18127d12016-06-08 16:52:28 +12002321TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2322{
2323 m_errorMonitor->ExpectSuccess();
2324
2325 ASSERT_NO_FATAL_FAILURE(InitState());
2326 VkResult err;
2327
2328 // Record (empty!) command buffer that can be submitted multiple times
2329 // simultaneously.
2330 VkCommandBufferBeginInfo cbbi = {
2331 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2332 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2333 };
2334 m_commandBuffer->BeginCommandBuffer(&cbbi);
2335 m_commandBuffer->EndCommandBuffer();
2336
2337 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2338 VkFence fence;
2339 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2343 VkSemaphore s1, s2;
2344 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2345 ASSERT_VK_SUCCESS(err);
2346 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2347 ASSERT_VK_SUCCESS(err);
2348
2349 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2350 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2351 1, &m_commandBuffer->handle(), 1, &s1 };
2352 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2353 ASSERT_VK_SUCCESS(err);
2354
2355 // Submit CB again, signaling s2.
2356 si.pSignalSemaphores = &s2;
2357 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2358 ASSERT_VK_SUCCESS(err);
2359
2360 // Wait for fence.
2361 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2362 ASSERT_VK_SUCCESS(err);
2363
2364 // CB is still in flight from second submission, but semaphore s1 is no
2365 // longer in flight. delete it.
2366 vkDestroySemaphore(m_device->device(), s1, nullptr);
2367
2368 m_errorMonitor->VerifyNotFound();
2369
2370 // Force device idle and clean up remaining objects
2371 vkDeviceWaitIdle(m_device->device());
2372 vkDestroySemaphore(m_device->device(), s2, nullptr);
2373 vkDestroyFence(m_device->device(), fence, nullptr);
2374}
2375
Tobin Ehlis41376e12015-07-03 08:45:14 -06002376TEST_F(VkLayerTest, InvalidUsageBits)
2377{
Tony Barbourf92621a2016-05-02 14:28:12 -06002378 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002379 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002380 "Initialize buffer with wrong usage then perform copy expecting errors "
2381 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002383 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002384
2385 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002386 VkImageObj image(m_device);
2387 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002388 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002389 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2390 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002391
Tony Barbourf92621a2016-05-02 14:28:12 -06002392 VkImageView dsv;
2393 VkImageViewCreateInfo dsvci = {};
2394 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2395 dsvci.image = image.handle();
2396 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2397 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2398 dsvci.subresourceRange.layerCount = 1;
2399 dsvci.subresourceRange.baseMipLevel = 0;
2400 dsvci.subresourceRange.levelCount = 1;
2401 dsvci.subresourceRange.aspectMask =
2402 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002403
Tony Barbourf92621a2016-05-02 14:28:12 -06002404 // Create a view with depth / stencil aspect for image with different usage
2405 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002408
2409 // Initialize buffer with TRANSFER_DST usage
2410 vk_testing::Buffer buffer;
2411 VkMemoryPropertyFlags reqs = 0;
2412 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2413 VkBufferImageCopy region = {};
2414 region.bufferRowLength = 128;
2415 region.bufferImageHeight = 128;
2416 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2417 region.imageSubresource.layerCount = 1;
2418 region.imageExtent.height = 16;
2419 region.imageExtent.width = 16;
2420 region.imageExtent.depth = 1;
2421
2422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2423 "Invalid usage flag for buffer ");
2424 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2425 // TRANSFER_DST
2426 BeginCommandBuffer();
2427 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2428 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2429 1, &region);
2430 m_errorMonitor->VerifyFound();
2431
2432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2433 "Invalid usage flag for image ");
2434 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2435 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2436 1, &region);
2437 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002438}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002439#endif // MEM_TRACKER_TESTS
2440
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002441#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002442
2443TEST_F(VkLayerTest, LeakAnObject) {
2444 VkResult err;
2445
2446 TEST_DESCRIPTION(
2447 "Create a fence and destroy its device without first destroying the fence.");
2448
2449 // Note that we have to create a new device since destroying the
2450 // framework's device causes Teardown() to fail and just calling Teardown
2451 // will destroy the errorMonitor.
2452
2453 m_errorMonitor->SetDesiredFailureMsg(
2454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2455 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2456
2457 ASSERT_NO_FATAL_FAILURE(InitState());
2458
2459 const std::vector<VkQueueFamilyProperties> queue_props =
2460 m_device->queue_props;
2461 std::vector<VkDeviceQueueCreateInfo> queue_info;
2462 queue_info.reserve(queue_props.size());
2463 std::vector<std::vector<float>> queue_priorities;
2464 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2465 VkDeviceQueueCreateInfo qi = {};
2466 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2467 qi.pNext = NULL;
2468 qi.queueFamilyIndex = i;
2469 qi.queueCount = queue_props[i].queueCount;
2470 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2471 qi.pQueuePriorities = queue_priorities[i].data();
2472 queue_info.push_back(qi);
2473 }
2474
2475 std::vector<const char *> device_layer_names;
2476 std::vector<const char *> device_extension_names;
2477 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2478 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2479 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2480 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2481 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2482 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2483 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2484
2485 // The sacrificial device object
2486 VkDevice testDevice;
2487 VkDeviceCreateInfo device_create_info = {};
2488 auto features = m_device->phy().features();
2489 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2490 device_create_info.pNext = NULL;
2491 device_create_info.queueCreateInfoCount = queue_info.size();
2492 device_create_info.pQueueCreateInfos = queue_info.data();
2493 device_create_info.enabledLayerCount = device_layer_names.size();
2494 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2495 device_create_info.pEnabledFeatures = &features;
2496 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2497 ASSERT_VK_SUCCESS(err);
2498
2499 VkFence fence;
2500 VkFenceCreateInfo fence_create_info = {};
2501 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2502 fence_create_info.pNext = NULL;
2503 fence_create_info.flags = 0;
2504 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 // Induce failure by not calling vkDestroyFence
2508 vkDestroyDevice(testDevice, NULL);
2509 m_errorMonitor->VerifyFound();
2510}
2511
2512TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2513
2514 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2515 "attempt to delete them from another.");
2516
2517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2518 "FreeCommandBuffers is attempting to free Command Buffer");
2519
2520 VkCommandPool command_pool_one;
2521 VkCommandPool command_pool_two;
2522
2523 VkCommandPoolCreateInfo pool_create_info{};
2524 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2525 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2526 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2527
2528 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2529 &command_pool_one);
2530
2531 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2532 &command_pool_two);
2533
2534 VkCommandBuffer command_buffer[9];
2535 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2536 command_buffer_allocate_info.sType =
2537 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2538 command_buffer_allocate_info.commandPool = command_pool_one;
2539 command_buffer_allocate_info.commandBufferCount = 9;
2540 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2541 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2542 command_buffer);
2543
2544 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2545 &command_buffer[3]);
2546
2547 m_errorMonitor->VerifyFound();
2548
2549 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2550 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2551}
2552
2553TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2554 VkResult err;
2555
2556 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2557 "attempt to delete them from another.");
2558
2559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2560 "FreeDescriptorSets is attempting to free descriptorSet");
2561
2562 ASSERT_NO_FATAL_FAILURE(InitState());
2563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2564
2565 VkDescriptorPoolSize ds_type_count = {};
2566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2567 ds_type_count.descriptorCount = 1;
2568
2569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2571 ds_pool_ci.pNext = NULL;
2572 ds_pool_ci.flags = 0;
2573 ds_pool_ci.maxSets = 1;
2574 ds_pool_ci.poolSizeCount = 1;
2575 ds_pool_ci.pPoolSizes = &ds_type_count;
2576
2577 VkDescriptorPool ds_pool_one;
2578 err =
2579 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2580 ASSERT_VK_SUCCESS(err);
2581
2582 // Create a second descriptor pool
2583 VkDescriptorPool ds_pool_two;
2584 err =
2585 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2586 ASSERT_VK_SUCCESS(err);
2587
2588 VkDescriptorSetLayoutBinding dsl_binding = {};
2589 dsl_binding.binding = 0;
2590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2591 dsl_binding.descriptorCount = 1;
2592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2593 dsl_binding.pImmutableSamplers = NULL;
2594
2595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2597 ds_layout_ci.pNext = NULL;
2598 ds_layout_ci.bindingCount = 1;
2599 ds_layout_ci.pBindings = &dsl_binding;
2600
2601 VkDescriptorSetLayout ds_layout;
2602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2603 &ds_layout);
2604 ASSERT_VK_SUCCESS(err);
2605
2606 VkDescriptorSet descriptorSet;
2607 VkDescriptorSetAllocateInfo alloc_info = {};
2608 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2609 alloc_info.descriptorSetCount = 1;
2610 alloc_info.descriptorPool = ds_pool_one;
2611 alloc_info.pSetLayouts = &ds_layout;
2612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2613 &descriptorSet);
2614 ASSERT_VK_SUCCESS(err);
2615
2616 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2617
2618 m_errorMonitor->VerifyFound();
2619
2620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2621 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2622 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2623}
2624
2625TEST_F(VkLayerTest, CreateUnknownObject) {
2626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2627 "Invalid VkImage Object ");
2628
2629 TEST_DESCRIPTION(
2630 "Pass an invalid image object handle into a Vulkan API call.");
2631
2632 ASSERT_NO_FATAL_FAILURE(InitState());
2633
2634 // Pass bogus handle into GetImageMemoryRequirements
2635 VkMemoryRequirements mem_reqs;
2636 uint64_t fakeImageHandle = 0xCADECADE;
2637 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2638
2639 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2640
2641 m_errorMonitor->VerifyFound();
2642}
2643
Karl Schultz6addd812016-02-02 17:17:23 -07002644TEST_F(VkLayerTest, PipelineNotBound) {
2645 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002646
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002647 TEST_DESCRIPTION(
2648 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2649
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002651 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002655
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2658 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002659
2660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2662 ds_pool_ci.pNext = NULL;
2663 ds_pool_ci.maxSets = 1;
2664 ds_pool_ci.poolSizeCount = 1;
2665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002666
2667 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002668 err =
2669 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002670 ASSERT_VK_SUCCESS(err);
2671
2672 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002673 dsl_binding.binding = 0;
2674 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2675 dsl_binding.descriptorCount = 1;
2676 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2677 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002678
2679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2681 ds_layout_ci.pNext = NULL;
2682 ds_layout_ci.bindingCount = 1;
2683 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002684
2685 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2687 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002688 ASSERT_VK_SUCCESS(err);
2689
2690 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002691 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002693 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002694 alloc_info.descriptorPool = ds_pool;
2695 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002696 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2697 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002701 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2702 pipeline_layout_ci.pNext = NULL;
2703 pipeline_layout_ci.setLayoutCount = 1;
2704 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002705
2706 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2708 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002709 ASSERT_VK_SUCCESS(err);
2710
Mark Youngad779052016-01-06 14:26:04 -07002711 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712
2713 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2715 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002717 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002718
Chia-I Wuf7458c52015-10-26 21:10:41 +08002719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002722}
2723
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002724TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2725 VkResult err;
2726
2727 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2728 "during bind[Buffer|Image]Memory time");
2729
2730 m_errorMonitor->SetDesiredFailureMsg(
2731 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2732 "for this object type are not compatible with the memory");
2733
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // Create an image, allocate memory, set a bad typeIndex and then try to
2737 // bind it
2738 VkImage image;
2739 VkDeviceMemory mem;
2740 VkMemoryRequirements mem_reqs;
2741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
2744
2745 VkImageCreateInfo image_create_info = {};
2746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
2759
2760 VkMemoryAllocateInfo mem_alloc = {};
2761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
2765
2766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2767 ASSERT_VK_SUCCESS(err);
2768
2769 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2770 mem_alloc.allocationSize = mem_reqs.size;
2771 // Introduce Failure, select likely invalid TypeIndex
2772 mem_alloc.memoryTypeIndex = 31;
2773
2774 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2775 ASSERT_VK_SUCCESS(err);
2776
2777 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2778 (void)err;
2779
2780 m_errorMonitor->VerifyFound();
2781
2782 vkDestroyImage(m_device->device(), image, NULL);
2783 vkFreeMemory(m_device->device(), mem, NULL);
2784}
2785
Karl Schultz6addd812016-02-02 17:17:23 -07002786TEST_F(VkLayerTest, BindInvalidMemory) {
2787 VkResult err;
2788 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002789
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002791 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002792
Tobin Ehlisec598302015-09-15 15:02:17 -06002793 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002794
2795 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002796 VkImage image;
2797 VkDeviceMemory mem;
2798 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002799
Karl Schultz6addd812016-02-02 17:17:23 -07002800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2801 const int32_t tex_width = 32;
2802 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002803
2804 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2806 image_create_info.pNext = NULL;
2807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2808 image_create_info.format = tex_format;
2809 image_create_info.extent.width = tex_width;
2810 image_create_info.extent.height = tex_height;
2811 image_create_info.extent.depth = 1;
2812 image_create_info.mipLevels = 1;
2813 image_create_info.arrayLayers = 1;
2814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2815 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2816 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2817 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002818
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002819 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002820 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2821 mem_alloc.pNext = NULL;
2822 mem_alloc.allocationSize = 0;
2823 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002824
Chia-I Wuf7458c52015-10-26 21:10:41 +08002825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002826 ASSERT_VK_SUCCESS(err);
2827
Karl Schultz6addd812016-02-02 17:17:23 -07002828 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002829
2830 mem_alloc.allocationSize = mem_reqs.size;
2831
Karl Schultz6addd812016-02-02 17:17:23 -07002832 pass =
2833 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002834 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002835
2836 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002837 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002838 ASSERT_VK_SUCCESS(err);
2839
2840 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002841 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002842
2843 // Try to bind free memory that has been freed
2844 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2845 // This may very well return an error.
2846 (void)err;
2847
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002848 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002849
Chia-I Wuf7458c52015-10-26 21:10:41 +08002850 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002851}
2852
Karl Schultz6addd812016-02-02 17:17:23 -07002853TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2854 VkResult err;
2855 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002856
Karl Schultz6addd812016-02-02 17:17:23 -07002857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2858 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002859
Tobin Ehlisec598302015-09-15 15:02:17 -06002860 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002861
Karl Schultz6addd812016-02-02 17:17:23 -07002862 // Create an image object, allocate memory, destroy the object and then try
2863 // to bind it
2864 VkImage image;
2865 VkDeviceMemory mem;
2866 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002867
Karl Schultz6addd812016-02-02 17:17:23 -07002868 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2869 const int32_t tex_width = 32;
2870 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002871
2872 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002873 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2874 image_create_info.pNext = NULL;
2875 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2876 image_create_info.format = tex_format;
2877 image_create_info.extent.width = tex_width;
2878 image_create_info.extent.height = tex_height;
2879 image_create_info.extent.depth = 1;
2880 image_create_info.mipLevels = 1;
2881 image_create_info.arrayLayers = 1;
2882 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2883 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2884 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2885 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002886
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002887 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002888 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2889 mem_alloc.pNext = NULL;
2890 mem_alloc.allocationSize = 0;
2891 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002892
Chia-I Wuf7458c52015-10-26 21:10:41 +08002893 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002894 ASSERT_VK_SUCCESS(err);
2895
Karl Schultz6addd812016-02-02 17:17:23 -07002896 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002897
2898 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002899 pass =
2900 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002901 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002902
2903 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002904 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002905 ASSERT_VK_SUCCESS(err);
2906
2907 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002908 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002909 ASSERT_VK_SUCCESS(err);
2910
2911 // Now Try to bind memory to this destroyed object
2912 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2913 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002914 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002915
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002916 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002917
Chia-I Wuf7458c52015-10-26 21:10:41 +08002918 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002919}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002920
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002921#endif // OBJ_TRACKER_TESTS
2922
Tobin Ehlis0788f522015-05-26 16:11:58 -06002923#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002924
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002925// This is a positive test. No errors are expected.
2926TEST_F(VkLayerTest, StencilLoadOp) {
2927 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2928 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2929 VkResult result = VK_SUCCESS;
2930 VkImageFormatProperties formatProps;
2931 vkGetPhysicalDeviceImageFormatProperties(
2932 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2933 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2934 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2935 0, &formatProps);
2936 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2937 return;
2938 }
2939
2940 ASSERT_NO_FATAL_FAILURE(InitState());
2941 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2942 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2943 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2944 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2945 VkAttachmentDescription att = {};
2946 VkAttachmentReference ref = {};
2947 att.format = depth_stencil_fmt;
2948 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2949 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2950 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2951 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2952 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2953 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2954
2955 VkClearValue clear;
2956 clear.depthStencil.depth = 1.0;
2957 clear.depthStencil.stencil = 0;
2958 ref.attachment = 0;
2959 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2960
2961 VkSubpassDescription subpass = {};
2962 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
2963 subpass.flags = 0;
2964 subpass.inputAttachmentCount = 0;
2965 subpass.pInputAttachments = NULL;
2966 subpass.colorAttachmentCount = 0;
2967 subpass.pColorAttachments = NULL;
2968 subpass.pResolveAttachments = NULL;
2969 subpass.pDepthStencilAttachment = &ref;
2970 subpass.preserveAttachmentCount = 0;
2971 subpass.pPreserveAttachments = NULL;
2972
2973 VkRenderPass rp;
2974 VkRenderPassCreateInfo rp_info = {};
2975 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2976 rp_info.attachmentCount = 1;
2977 rp_info.pAttachments = &att;
2978 rp_info.subpassCount = 1;
2979 rp_info.pSubpasses = &subpass;
2980 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
2981 ASSERT_VK_SUCCESS(result);
2982
2983 VkImageView *depthView = m_depthStencil->BindInfo();
2984 VkFramebufferCreateInfo fb_info = {};
2985 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
2986 fb_info.pNext = NULL;
2987 fb_info.renderPass = rp;
2988 fb_info.attachmentCount = 1;
2989 fb_info.pAttachments = depthView;
2990 fb_info.width = 100;
2991 fb_info.height = 100;
2992 fb_info.layers = 1;
2993 VkFramebuffer fb;
2994 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
2995 ASSERT_VK_SUCCESS(result);
2996
2997
2998 VkRenderPassBeginInfo rpbinfo = {};
2999 rpbinfo.clearValueCount = 1;
3000 rpbinfo.pClearValues = &clear;
3001 rpbinfo.pNext = NULL;
3002 rpbinfo.renderPass = rp;
3003 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3004 rpbinfo.renderArea.extent.width = 100;
3005 rpbinfo.renderArea.extent.height = 100;
3006 rpbinfo.renderArea.offset.x = 0;
3007 rpbinfo.renderArea.offset.y = 0;
3008 rpbinfo.framebuffer = fb;
3009
3010 VkFence fence = {};
3011 VkFenceCreateInfo fence_ci = {};
3012 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3013 fence_ci.pNext = nullptr;
3014 fence_ci.flags = 0;
3015 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3016 ASSERT_VK_SUCCESS(result);
3017
3018
3019 m_commandBuffer->BeginCommandBuffer();
3020 m_commandBuffer->BeginRenderPass(rpbinfo);
3021 m_commandBuffer->EndRenderPass();
3022 m_commandBuffer->EndCommandBuffer();
3023 m_commandBuffer->QueueCommandBuffer(fence);
3024
3025 VkImageObj destImage(m_device);
3026 destImage.init(100, 100, depth_stencil_fmt,
3027 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3028 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3029 VK_IMAGE_TILING_OPTIMAL, 0);
3030 VkImageMemoryBarrier barrier = {};
3031 VkImageSubresourceRange range;
3032 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3033 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3034 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3035 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3036 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3037 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3038 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3039 barrier.image = m_depthStencil->handle();
3040 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3041 range.baseMipLevel = 0;
3042 range.levelCount = 1;
3043 range.baseArrayLayer = 0;
3044 range.layerCount = 1;
3045 barrier.subresourceRange = range;
3046 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3047 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3048 cmdbuf.BeginCommandBuffer();
3049 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3050 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3051 nullptr, 1, &barrier);
3052 barrier.srcAccessMask = 0;
3053 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3054 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3055 barrier.image = destImage.handle();
3056 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3057 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3058 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3059 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3060 nullptr, 1, &barrier);
3061 VkImageCopy cregion;
3062 cregion.srcSubresource.aspectMask =
3063 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3064 cregion.srcSubresource.mipLevel = 0;
3065 cregion.srcSubresource.baseArrayLayer = 0;
3066 cregion.srcSubresource.layerCount = 1;
3067 cregion.srcOffset.x = 0;
3068 cregion.srcOffset.y = 0;
3069 cregion.srcOffset.z = 0;
3070 cregion.dstSubresource.aspectMask =
3071 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3072 cregion.dstSubresource.mipLevel = 0;
3073 cregion.dstSubresource.baseArrayLayer = 0;
3074 cregion.dstSubresource.layerCount = 1;
3075 cregion.dstOffset.x = 0;
3076 cregion.dstOffset.y = 0;
3077 cregion.dstOffset.z = 0;
3078 cregion.extent.width = 100;
3079 cregion.extent.height = 100;
3080 cregion.extent.depth = 1;
3081 cmdbuf.CopyImage(m_depthStencil->handle(),
3082 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3083 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3084 cmdbuf.EndCommandBuffer();
3085
3086 VkSubmitInfo submit_info;
3087 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3088 submit_info.pNext = NULL;
3089 submit_info.waitSemaphoreCount = 0;
3090 submit_info.pWaitSemaphores = NULL;
3091 submit_info.pWaitDstStageMask = NULL;
3092 submit_info.commandBufferCount = 1;
3093 submit_info.pCommandBuffers = &cmdbuf.handle();
3094 submit_info.signalSemaphoreCount = 0;
3095 submit_info.pSignalSemaphores = NULL;
3096
3097 m_errorMonitor->ExpectSuccess();
3098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3099 m_errorMonitor->VerifyNotFound();
3100
3101 vkDestroyFence(m_device->device(), fence, nullptr);
3102 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3103 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3104}
3105
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003106TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3107 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3108 "attachment reference of VK_ATTACHMENT_UNUSED");
3109
3110 ASSERT_NO_FATAL_FAILURE(InitState());
3111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3112
3113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "must not be VK_ATTACHMENT_UNUSED");
3115
3116 VkAttachmentReference color_attach = {};
3117 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3118 color_attach.attachment = 0;
3119 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3120 VkSubpassDescription subpass = {};
3121 subpass.colorAttachmentCount = 1;
3122 subpass.pColorAttachments = &color_attach;
3123 subpass.preserveAttachmentCount = 1;
3124 subpass.pPreserveAttachments = &preserve_attachment;
3125
3126 VkRenderPassCreateInfo rpci = {};
3127 rpci.subpassCount = 1;
3128 rpci.pSubpasses = &subpass;
3129 rpci.attachmentCount = 1;
3130 VkAttachmentDescription attach_desc = {};
3131 attach_desc.format = VK_FORMAT_UNDEFINED;
3132 rpci.pAttachments = &attach_desc;
3133 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3134 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003135 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003136
3137 m_errorMonitor->VerifyFound();
3138
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003139 if (result == VK_SUCCESS) {
3140 vkDestroyRenderPass(m_device->device(), rp, NULL);
3141 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003142}
3143
3144TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3145 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3146 "in the depthStencil attachment point");
3147
3148 ASSERT_NO_FATAL_FAILURE(InitState());
3149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3150
3151 m_errorMonitor->SetDesiredFailureMsg(
3152 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3153 "conflicts with the image's IMAGE_USAGE flags");
3154
3155 // Create a renderPass with a depth-stencil attachment created with
3156 // IMAGE_USAGE_COLOR_ATTACHMENT
3157 VkAttachmentReference attach = {};
3158 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3159 VkSubpassDescription subpass = {};
3160 // Add our color attachment to pDepthStencilAttachment
3161 subpass.pDepthStencilAttachment = &attach;
3162 VkRenderPassCreateInfo rpci = {};
3163 rpci.subpassCount = 1;
3164 rpci.pSubpasses = &subpass;
3165 rpci.attachmentCount = 1;
3166 VkAttachmentDescription attach_desc = {};
3167 attach_desc.format = VK_FORMAT_UNDEFINED;
3168 rpci.pAttachments = &attach_desc;
3169 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3170 VkRenderPass rp;
3171 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3172 ASSERT_VK_SUCCESS(err);
3173
3174 VkImageView imageView =
3175 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3176 VkFramebufferCreateInfo fb_info = {};
3177 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3178 fb_info.pNext = NULL;
3179 fb_info.renderPass = rp;
3180 fb_info.attachmentCount = 1;
3181 fb_info.pAttachments = &imageView;
3182 fb_info.width = 100;
3183 fb_info.height = 100;
3184 fb_info.layers = 1;
3185
3186 VkFramebuffer fb;
3187 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3188
3189 m_errorMonitor->VerifyFound();
3190
3191 if (err == VK_SUCCESS) {
3192 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3193 }
3194 vkDestroyRenderPass(m_device->device(), rp, NULL);
3195}
3196
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003197// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003198TEST_F(VkLayerTest, WaitEventThenSet) {
3199 TEST_DESCRIPTION(
3200 "Wait on a event then set it after the wait has been submitted.");
3201
Michael Lentine860b0fe2016-05-20 10:14:00 -05003202 m_errorMonitor->ExpectSuccess();
3203
3204 VkEvent event;
3205 VkEventCreateInfo event_create_info{};
3206 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3207 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3208
3209 VkCommandPool command_pool;
3210 VkCommandPoolCreateInfo pool_create_info{};
3211 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3212 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3213 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3214 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3215 &command_pool);
3216
3217 VkCommandBuffer command_buffer;
3218 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3219 command_buffer_allocate_info.sType =
3220 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3221 command_buffer_allocate_info.commandPool = command_pool;
3222 command_buffer_allocate_info.commandBufferCount = 1;
3223 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3224 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3225 &command_buffer);
3226
3227 VkQueue queue = VK_NULL_HANDLE;
3228 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003229 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003230
3231 {
3232 VkCommandBufferBeginInfo begin_info{};
3233 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3234 vkBeginCommandBuffer(command_buffer, &begin_info);
3235
3236 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3237 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3238 nullptr, 0, nullptr);
3239 vkCmdResetEvent(command_buffer, event,
3240 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3241 vkEndCommandBuffer(command_buffer);
3242 }
3243 {
3244 VkSubmitInfo submit_info{};
3245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3246 submit_info.commandBufferCount = 1;
3247 submit_info.pCommandBuffers = &command_buffer;
3248 submit_info.signalSemaphoreCount = 0;
3249 submit_info.pSignalSemaphores = nullptr;
3250 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3251 }
3252 { vkSetEvent(m_device->device(), event); }
3253
3254 vkQueueWaitIdle(queue);
3255
3256 vkDestroyEvent(m_device->device(), event, nullptr);
3257 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3258 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3259
3260 m_errorMonitor->VerifyNotFound();
3261}
Michael Lentine5627e692016-05-20 17:45:02 -05003262// This is a positive test. No errors should be generated.
3263TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3264 TEST_DESCRIPTION(
3265 "Issue a query and copy from it on a second command buffer.");
3266
3267 if ((m_device->queue_props.empty()) ||
3268 (m_device->queue_props[0].queueCount < 2))
3269 return;
3270
3271 m_errorMonitor->ExpectSuccess();
3272
3273 VkQueryPool query_pool;
3274 VkQueryPoolCreateInfo query_pool_create_info{};
3275 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3276 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3277 query_pool_create_info.queryCount = 1;
3278 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3279 &query_pool);
3280
3281 VkCommandPool command_pool;
3282 VkCommandPoolCreateInfo pool_create_info{};
3283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3286 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3287 &command_pool);
3288
3289 VkCommandBuffer command_buffer[2];
3290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3291 command_buffer_allocate_info.sType =
3292 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3293 command_buffer_allocate_info.commandPool = command_pool;
3294 command_buffer_allocate_info.commandBufferCount = 2;
3295 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3296 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3297 command_buffer);
3298
3299 VkQueue queue = VK_NULL_HANDLE;
3300 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3301 1, &queue);
3302
3303 uint32_t qfi = 0;
3304 VkBufferCreateInfo buff_create_info = {};
3305 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3306 buff_create_info.size = 1024;
3307 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3308 buff_create_info.queueFamilyIndexCount = 1;
3309 buff_create_info.pQueueFamilyIndices = &qfi;
3310
3311 VkResult err;
3312 VkBuffer buffer;
3313 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3314 ASSERT_VK_SUCCESS(err);
3315 VkMemoryAllocateInfo mem_alloc = {};
3316 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3317 mem_alloc.pNext = NULL;
3318 mem_alloc.allocationSize = 1024;
3319 mem_alloc.memoryTypeIndex = 0;
3320
3321 VkMemoryRequirements memReqs;
3322 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3323 bool pass =
3324 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3325 if (!pass) {
3326 vkDestroyBuffer(m_device->device(), buffer, NULL);
3327 return;
3328 }
3329
3330 VkDeviceMemory mem;
3331 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3332 ASSERT_VK_SUCCESS(err);
3333 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3334 ASSERT_VK_SUCCESS(err);
3335
3336 {
3337 VkCommandBufferBeginInfo begin_info{};
3338 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3339 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3340
3341 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3342 vkCmdWriteTimestamp(command_buffer[0],
3343 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3344
3345 vkEndCommandBuffer(command_buffer[0]);
3346
3347 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3348
3349 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3350 0, 0, 0);
3351
3352 vkEndCommandBuffer(command_buffer[1]);
3353 }
3354 {
3355 VkSubmitInfo submit_info{};
3356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3357 submit_info.commandBufferCount = 2;
3358 submit_info.pCommandBuffers = command_buffer;
3359 submit_info.signalSemaphoreCount = 0;
3360 submit_info.pSignalSemaphores = nullptr;
3361 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3362 }
3363
3364 vkQueueWaitIdle(queue);
3365
3366 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3367 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3368 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003369 vkDestroyBuffer(m_device->device(), buffer, NULL);
3370 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003371
3372 m_errorMonitor->VerifyNotFound();
3373}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003374
3375TEST_F(VkLayerTest, ResetEventThenSet) {
3376 TEST_DESCRIPTION(
3377 "Reset an event then set it after the reset has been submitted.");
3378
Michael Lentine860b0fe2016-05-20 10:14:00 -05003379 m_errorMonitor->ExpectSuccess();
3380
3381 VkEvent event;
3382 VkEventCreateInfo event_create_info{};
3383 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3384 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3385
3386 VkCommandPool command_pool;
3387 VkCommandPoolCreateInfo pool_create_info{};
3388 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3389 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3390 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3391 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3392 &command_pool);
3393
3394 VkCommandBuffer command_buffer;
3395 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3396 command_buffer_allocate_info.sType =
3397 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3398 command_buffer_allocate_info.commandPool = command_pool;
3399 command_buffer_allocate_info.commandBufferCount = 1;
3400 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3401 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3402 &command_buffer);
3403
3404 VkQueue queue = VK_NULL_HANDLE;
3405 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003406 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003407
3408 {
3409 VkCommandBufferBeginInfo begin_info{};
3410 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3411 vkBeginCommandBuffer(command_buffer, &begin_info);
3412
3413 vkCmdResetEvent(command_buffer, event,
3414 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3415 vkCmdWaitEvents(command_buffer, 1, &event,
3416 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3417 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3418 nullptr, 0, nullptr);
3419 vkEndCommandBuffer(command_buffer);
3420 }
3421 {
3422 VkSubmitInfo submit_info{};
3423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3424 submit_info.commandBufferCount = 1;
3425 submit_info.pCommandBuffers = &command_buffer;
3426 submit_info.signalSemaphoreCount = 0;
3427 submit_info.pSignalSemaphores = nullptr;
3428 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3429 }
3430 {
3431 m_errorMonitor->SetDesiredFailureMsg(
3432 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3433 "0x1 that is already in use by a "
3434 "command buffer.");
3435 vkSetEvent(m_device->device(), event);
3436 m_errorMonitor->VerifyFound();
3437 }
3438
3439 vkQueueWaitIdle(queue);
3440
3441 vkDestroyEvent(m_device->device(), event, nullptr);
3442 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3443 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3444}
3445
3446// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003447TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3448 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3449 "run through a Submit & WaitForFences cycle 3 times. This "
3450 "previously revealed a bug so running this positive test "
3451 "to prevent a regression.");
3452 m_errorMonitor->ExpectSuccess();
3453
3454 ASSERT_NO_FATAL_FAILURE(InitState());
3455 VkQueue queue = VK_NULL_HANDLE;
3456 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3457 0, &queue);
3458
3459 static const uint32_t NUM_OBJECTS = 2;
3460 static const uint32_t NUM_FRAMES = 3;
3461 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3462 VkFence fences[NUM_OBJECTS] = {};
3463
3464 VkCommandPool cmd_pool;
3465 VkCommandPoolCreateInfo cmd_pool_ci = {};
3466 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3467 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3468 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3469 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3470 nullptr, &cmd_pool);
3471 ASSERT_VK_SUCCESS(err);
3472
3473 VkCommandBufferAllocateInfo cmd_buf_info = {};
3474 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3475 cmd_buf_info.commandPool = cmd_pool;
3476 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3477 cmd_buf_info.commandBufferCount = 1;
3478
3479 VkFenceCreateInfo fence_ci = {};
3480 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3481 fence_ci.pNext = nullptr;
3482 fence_ci.flags = 0;
3483
3484 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3485 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3486 &cmd_buffers[i]);
3487 ASSERT_VK_SUCCESS(err);
3488 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3489 ASSERT_VK_SUCCESS(err);
3490 }
3491
3492 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003493 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3494 // Create empty cmd buffer
3495 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3496 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003497
Tobin Ehlisf9025162016-05-26 06:55:21 -06003498 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3499 ASSERT_VK_SUCCESS(err);
3500 err = vkEndCommandBuffer(cmd_buffers[obj]);
3501 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003502
Tobin Ehlisf9025162016-05-26 06:55:21 -06003503 VkSubmitInfo submit_info = {};
3504 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3505 submit_info.commandBufferCount = 1;
3506 submit_info.pCommandBuffers = &cmd_buffers[obj];
3507 // Submit cmd buffer and wait for fence
3508 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3509 ASSERT_VK_SUCCESS(err);
3510 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3511 UINT64_MAX);
3512 ASSERT_VK_SUCCESS(err);
3513 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3514 ASSERT_VK_SUCCESS(err);
3515 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003516 }
3517 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003518 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3519 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3520 vkDestroyFence(m_device->device(), fences[i], nullptr);
3521 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003522}
3523// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003524TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3525
3526 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3527 "submitted on separate queues followed by a QueueWaitIdle.");
3528
Dustin Graves48458142016-04-29 16:11:55 -06003529 if ((m_device->queue_props.empty()) ||
3530 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003531 return;
3532
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003533 m_errorMonitor->ExpectSuccess();
3534
3535 VkSemaphore semaphore;
3536 VkSemaphoreCreateInfo semaphore_create_info{};
3537 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3538 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3539 &semaphore);
3540
3541 VkCommandPool command_pool;
3542 VkCommandPoolCreateInfo pool_create_info{};
3543 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3544 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3545 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3546 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3547 &command_pool);
3548
3549 VkCommandBuffer command_buffer[2];
3550 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3551 command_buffer_allocate_info.sType =
3552 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3553 command_buffer_allocate_info.commandPool = command_pool;
3554 command_buffer_allocate_info.commandBufferCount = 2;
3555 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3556 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3557 command_buffer);
3558
3559 VkQueue queue = VK_NULL_HANDLE;
3560 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3561 1, &queue);
3562
3563 {
3564 VkCommandBufferBeginInfo begin_info{};
3565 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3566 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3567
3568 vkCmdPipelineBarrier(command_buffer[0],
3569 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3570 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3571 0, nullptr, 0, nullptr);
3572
3573 VkViewport viewport{};
3574 viewport.maxDepth = 1.0f;
3575 viewport.minDepth = 0.0f;
3576 viewport.width = 512;
3577 viewport.height = 512;
3578 viewport.x = 0;
3579 viewport.y = 0;
3580 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3581 vkEndCommandBuffer(command_buffer[0]);
3582 }
3583 {
3584 VkCommandBufferBeginInfo begin_info{};
3585 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3586 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3587
3588 VkViewport viewport{};
3589 viewport.maxDepth = 1.0f;
3590 viewport.minDepth = 0.0f;
3591 viewport.width = 512;
3592 viewport.height = 512;
3593 viewport.x = 0;
3594 viewport.y = 0;
3595 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3596 vkEndCommandBuffer(command_buffer[1]);
3597 }
3598 {
3599 VkSubmitInfo submit_info{};
3600 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3601 submit_info.commandBufferCount = 1;
3602 submit_info.pCommandBuffers = &command_buffer[0];
3603 submit_info.signalSemaphoreCount = 1;
3604 submit_info.pSignalSemaphores = &semaphore;
3605 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3606 }
3607 {
3608 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3609 VkSubmitInfo submit_info{};
3610 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3611 submit_info.commandBufferCount = 1;
3612 submit_info.pCommandBuffers = &command_buffer[1];
3613 submit_info.waitSemaphoreCount = 1;
3614 submit_info.pWaitSemaphores = &semaphore;
3615 submit_info.pWaitDstStageMask = flags;
3616 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3617 }
3618
3619 vkQueueWaitIdle(m_device->m_queue);
3620
3621 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3622 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3623 &command_buffer[0]);
3624 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3625
3626 m_errorMonitor->VerifyNotFound();
3627}
3628
3629// This is a positive test. No errors should be generated.
3630TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3631
3632 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3633 "submitted on separate queues, the second having a fence"
3634 "followed by a QueueWaitIdle.");
3635
Dustin Graves48458142016-04-29 16:11:55 -06003636 if ((m_device->queue_props.empty()) ||
3637 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003638 return;
3639
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003640 m_errorMonitor->ExpectSuccess();
3641
3642 VkFence fence;
3643 VkFenceCreateInfo fence_create_info{};
3644 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3645 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3646
3647 VkSemaphore semaphore;
3648 VkSemaphoreCreateInfo semaphore_create_info{};
3649 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3650 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3651 &semaphore);
3652
3653 VkCommandPool command_pool;
3654 VkCommandPoolCreateInfo pool_create_info{};
3655 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3656 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3657 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3658 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3659 &command_pool);
3660
3661 VkCommandBuffer command_buffer[2];
3662 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3663 command_buffer_allocate_info.sType =
3664 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3665 command_buffer_allocate_info.commandPool = command_pool;
3666 command_buffer_allocate_info.commandBufferCount = 2;
3667 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3668 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3669 command_buffer);
3670
3671 VkQueue queue = VK_NULL_HANDLE;
3672 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3673 1, &queue);
3674
3675 {
3676 VkCommandBufferBeginInfo begin_info{};
3677 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3678 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3679
3680 vkCmdPipelineBarrier(command_buffer[0],
3681 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3682 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3683 0, nullptr, 0, nullptr);
3684
3685 VkViewport viewport{};
3686 viewport.maxDepth = 1.0f;
3687 viewport.minDepth = 0.0f;
3688 viewport.width = 512;
3689 viewport.height = 512;
3690 viewport.x = 0;
3691 viewport.y = 0;
3692 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3693 vkEndCommandBuffer(command_buffer[0]);
3694 }
3695 {
3696 VkCommandBufferBeginInfo begin_info{};
3697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3698 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3699
3700 VkViewport viewport{};
3701 viewport.maxDepth = 1.0f;
3702 viewport.minDepth = 0.0f;
3703 viewport.width = 512;
3704 viewport.height = 512;
3705 viewport.x = 0;
3706 viewport.y = 0;
3707 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3708 vkEndCommandBuffer(command_buffer[1]);
3709 }
3710 {
3711 VkSubmitInfo submit_info{};
3712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3713 submit_info.commandBufferCount = 1;
3714 submit_info.pCommandBuffers = &command_buffer[0];
3715 submit_info.signalSemaphoreCount = 1;
3716 submit_info.pSignalSemaphores = &semaphore;
3717 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3718 }
3719 {
3720 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3721 VkSubmitInfo submit_info{};
3722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3723 submit_info.commandBufferCount = 1;
3724 submit_info.pCommandBuffers = &command_buffer[1];
3725 submit_info.waitSemaphoreCount = 1;
3726 submit_info.pWaitSemaphores = &semaphore;
3727 submit_info.pWaitDstStageMask = flags;
3728 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3729 }
3730
3731 vkQueueWaitIdle(m_device->m_queue);
3732
3733 vkDestroyFence(m_device->device(), fence, nullptr);
3734 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3735 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3736 &command_buffer[0]);
3737 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3738
3739 m_errorMonitor->VerifyNotFound();
3740}
3741
3742// This is a positive test. No errors should be generated.
3743TEST_F(VkLayerTest,
3744 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3745
3746 TEST_DESCRIPTION(
3747 "Two command buffers, each in a separate QueueSubmit call "
3748 "submitted on separate queues, the second having a fence"
3749 "followed by two consecutive WaitForFences calls on the same fence.");
3750
Dustin Graves48458142016-04-29 16:11:55 -06003751 if ((m_device->queue_props.empty()) ||
3752 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003753 return;
3754
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003755 m_errorMonitor->ExpectSuccess();
3756
3757 VkFence fence;
3758 VkFenceCreateInfo fence_create_info{};
3759 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3760 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3761
3762 VkSemaphore semaphore;
3763 VkSemaphoreCreateInfo semaphore_create_info{};
3764 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3765 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3766 &semaphore);
3767
3768 VkCommandPool command_pool;
3769 VkCommandPoolCreateInfo pool_create_info{};
3770 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3771 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3772 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3773 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3774 &command_pool);
3775
3776 VkCommandBuffer command_buffer[2];
3777 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3778 command_buffer_allocate_info.sType =
3779 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3780 command_buffer_allocate_info.commandPool = command_pool;
3781 command_buffer_allocate_info.commandBufferCount = 2;
3782 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3783 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3784 command_buffer);
3785
3786 VkQueue queue = VK_NULL_HANDLE;
3787 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3788 1, &queue);
3789
3790 {
3791 VkCommandBufferBeginInfo begin_info{};
3792 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3793 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3794
3795 vkCmdPipelineBarrier(command_buffer[0],
3796 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3797 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3798 0, nullptr, 0, nullptr);
3799
3800 VkViewport viewport{};
3801 viewport.maxDepth = 1.0f;
3802 viewport.minDepth = 0.0f;
3803 viewport.width = 512;
3804 viewport.height = 512;
3805 viewport.x = 0;
3806 viewport.y = 0;
3807 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3808 vkEndCommandBuffer(command_buffer[0]);
3809 }
3810 {
3811 VkCommandBufferBeginInfo begin_info{};
3812 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3813 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3814
3815 VkViewport viewport{};
3816 viewport.maxDepth = 1.0f;
3817 viewport.minDepth = 0.0f;
3818 viewport.width = 512;
3819 viewport.height = 512;
3820 viewport.x = 0;
3821 viewport.y = 0;
3822 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3823 vkEndCommandBuffer(command_buffer[1]);
3824 }
3825 {
3826 VkSubmitInfo submit_info{};
3827 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3828 submit_info.commandBufferCount = 1;
3829 submit_info.pCommandBuffers = &command_buffer[0];
3830 submit_info.signalSemaphoreCount = 1;
3831 submit_info.pSignalSemaphores = &semaphore;
3832 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3833 }
3834 {
3835 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3836 VkSubmitInfo submit_info{};
3837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3838 submit_info.commandBufferCount = 1;
3839 submit_info.pCommandBuffers = &command_buffer[1];
3840 submit_info.waitSemaphoreCount = 1;
3841 submit_info.pWaitSemaphores = &semaphore;
3842 submit_info.pWaitDstStageMask = flags;
3843 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3844 }
3845
3846 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3847 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3848
3849 vkDestroyFence(m_device->device(), fence, nullptr);
3850 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3851 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3852 &command_buffer[0]);
3853 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3854
3855 m_errorMonitor->VerifyNotFound();
3856}
3857
3858// This is a positive test. No errors should be generated.
3859TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3860
3861 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3862 "submitted on separate queues, the second having a fence, "
3863 "followed by a WaitForFences call.");
3864
Dustin Graves48458142016-04-29 16:11:55 -06003865 if ((m_device->queue_props.empty()) ||
3866 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003867 return;
3868
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003869 m_errorMonitor->ExpectSuccess();
3870
3871 VkFence fence;
3872 VkFenceCreateInfo fence_create_info{};
3873 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3874 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3875
3876 VkSemaphore semaphore;
3877 VkSemaphoreCreateInfo semaphore_create_info{};
3878 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3879 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3880 &semaphore);
3881
3882 VkCommandPool command_pool;
3883 VkCommandPoolCreateInfo pool_create_info{};
3884 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3885 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3886 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3887 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3888 &command_pool);
3889
3890 VkCommandBuffer command_buffer[2];
3891 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3892 command_buffer_allocate_info.sType =
3893 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3894 command_buffer_allocate_info.commandPool = command_pool;
3895 command_buffer_allocate_info.commandBufferCount = 2;
3896 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3897 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3898 command_buffer);
3899
3900 VkQueue queue = VK_NULL_HANDLE;
3901 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3902 1, &queue);
3903
3904
3905 {
3906 VkCommandBufferBeginInfo begin_info{};
3907 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3908 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3909
3910 vkCmdPipelineBarrier(command_buffer[0],
3911 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3912 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3913 0, nullptr, 0, nullptr);
3914
3915 VkViewport viewport{};
3916 viewport.maxDepth = 1.0f;
3917 viewport.minDepth = 0.0f;
3918 viewport.width = 512;
3919 viewport.height = 512;
3920 viewport.x = 0;
3921 viewport.y = 0;
3922 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3923 vkEndCommandBuffer(command_buffer[0]);
3924 }
3925 {
3926 VkCommandBufferBeginInfo begin_info{};
3927 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3928 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3929
3930 VkViewport viewport{};
3931 viewport.maxDepth = 1.0f;
3932 viewport.minDepth = 0.0f;
3933 viewport.width = 512;
3934 viewport.height = 512;
3935 viewport.x = 0;
3936 viewport.y = 0;
3937 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3938 vkEndCommandBuffer(command_buffer[1]);
3939 }
3940 {
3941 VkSubmitInfo submit_info{};
3942 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3943 submit_info.commandBufferCount = 1;
3944 submit_info.pCommandBuffers = &command_buffer[0];
3945 submit_info.signalSemaphoreCount = 1;
3946 submit_info.pSignalSemaphores = &semaphore;
3947 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3948 }
3949 {
3950 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3951 VkSubmitInfo submit_info{};
3952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3953 submit_info.commandBufferCount = 1;
3954 submit_info.pCommandBuffers = &command_buffer[1];
3955 submit_info.waitSemaphoreCount = 1;
3956 submit_info.pWaitSemaphores = &semaphore;
3957 submit_info.pWaitDstStageMask = flags;
3958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3959 }
3960
3961 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3962
3963 vkDestroyFence(m_device->device(), fence, nullptr);
3964 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3965 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3966 &command_buffer[0]);
3967 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3968
3969 m_errorMonitor->VerifyNotFound();
3970}
3971
3972// This is a positive test. No errors should be generated.
3973TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3974
3975 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3976 "on the same queue, sharing a signal/wait semaphore, the "
3977 "second having a fence, "
3978 "followed by a WaitForFences call.");
3979
3980 m_errorMonitor->ExpectSuccess();
3981
3982 VkFence fence;
3983 VkFenceCreateInfo fence_create_info{};
3984 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3985 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3986
3987 VkSemaphore semaphore;
3988 VkSemaphoreCreateInfo semaphore_create_info{};
3989 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3990 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3991 &semaphore);
3992
3993 VkCommandPool command_pool;
3994 VkCommandPoolCreateInfo pool_create_info{};
3995 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3996 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3997 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3998 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3999 &command_pool);
4000
4001 VkCommandBuffer command_buffer[2];
4002 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4003 command_buffer_allocate_info.sType =
4004 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4005 command_buffer_allocate_info.commandPool = command_pool;
4006 command_buffer_allocate_info.commandBufferCount = 2;
4007 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4008 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4009 command_buffer);
4010
4011 {
4012 VkCommandBufferBeginInfo begin_info{};
4013 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4014 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4015
4016 vkCmdPipelineBarrier(command_buffer[0],
4017 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4018 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4019 0, nullptr, 0, nullptr);
4020
4021 VkViewport viewport{};
4022 viewport.maxDepth = 1.0f;
4023 viewport.minDepth = 0.0f;
4024 viewport.width = 512;
4025 viewport.height = 512;
4026 viewport.x = 0;
4027 viewport.y = 0;
4028 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4029 vkEndCommandBuffer(command_buffer[0]);
4030 }
4031 {
4032 VkCommandBufferBeginInfo begin_info{};
4033 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4034 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4035
4036 VkViewport viewport{};
4037 viewport.maxDepth = 1.0f;
4038 viewport.minDepth = 0.0f;
4039 viewport.width = 512;
4040 viewport.height = 512;
4041 viewport.x = 0;
4042 viewport.y = 0;
4043 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4044 vkEndCommandBuffer(command_buffer[1]);
4045 }
4046 {
4047 VkSubmitInfo submit_info{};
4048 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4049 submit_info.commandBufferCount = 1;
4050 submit_info.pCommandBuffers = &command_buffer[0];
4051 submit_info.signalSemaphoreCount = 1;
4052 submit_info.pSignalSemaphores = &semaphore;
4053 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4054 }
4055 {
4056 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4057 VkSubmitInfo submit_info{};
4058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4059 submit_info.commandBufferCount = 1;
4060 submit_info.pCommandBuffers = &command_buffer[1];
4061 submit_info.waitSemaphoreCount = 1;
4062 submit_info.pWaitSemaphores = &semaphore;
4063 submit_info.pWaitDstStageMask = flags;
4064 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4065 }
4066
4067 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4068
4069 vkDestroyFence(m_device->device(), fence, nullptr);
4070 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4071 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4072 &command_buffer[0]);
4073 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4074
4075 m_errorMonitor->VerifyNotFound();
4076}
4077
4078// This is a positive test. No errors should be generated.
4079TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4080
4081 TEST_DESCRIPTION(
4082 "Two command buffers, each in a separate QueueSubmit call "
4083 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4084 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4085
4086 m_errorMonitor->ExpectSuccess();
4087
4088 VkFence fence;
4089 VkFenceCreateInfo fence_create_info{};
4090 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4091 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4092
4093 VkCommandPool command_pool;
4094 VkCommandPoolCreateInfo pool_create_info{};
4095 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4096 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4097 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4098 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4099 &command_pool);
4100
4101 VkCommandBuffer command_buffer[2];
4102 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4103 command_buffer_allocate_info.sType =
4104 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4105 command_buffer_allocate_info.commandPool = command_pool;
4106 command_buffer_allocate_info.commandBufferCount = 2;
4107 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4108 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4109 command_buffer);
4110
4111 {
4112 VkCommandBufferBeginInfo begin_info{};
4113 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4114 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4115
4116 vkCmdPipelineBarrier(command_buffer[0],
4117 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4118 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4119 0, nullptr, 0, nullptr);
4120
4121 VkViewport viewport{};
4122 viewport.maxDepth = 1.0f;
4123 viewport.minDepth = 0.0f;
4124 viewport.width = 512;
4125 viewport.height = 512;
4126 viewport.x = 0;
4127 viewport.y = 0;
4128 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4129 vkEndCommandBuffer(command_buffer[0]);
4130 }
4131 {
4132 VkCommandBufferBeginInfo begin_info{};
4133 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4134 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4135
4136 VkViewport viewport{};
4137 viewport.maxDepth = 1.0f;
4138 viewport.minDepth = 0.0f;
4139 viewport.width = 512;
4140 viewport.height = 512;
4141 viewport.x = 0;
4142 viewport.y = 0;
4143 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4144 vkEndCommandBuffer(command_buffer[1]);
4145 }
4146 {
4147 VkSubmitInfo submit_info{};
4148 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4149 submit_info.commandBufferCount = 1;
4150 submit_info.pCommandBuffers = &command_buffer[0];
4151 submit_info.signalSemaphoreCount = 0;
4152 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4153 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4154 }
4155 {
4156 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4157 VkSubmitInfo submit_info{};
4158 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4159 submit_info.commandBufferCount = 1;
4160 submit_info.pCommandBuffers = &command_buffer[1];
4161 submit_info.waitSemaphoreCount = 0;
4162 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4163 submit_info.pWaitDstStageMask = flags;
4164 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4165 }
4166
4167 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4168
4169 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4170
4171 vkDestroyFence(m_device->device(), fence, nullptr);
4172 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4173 &command_buffer[0]);
4174 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4175
4176 m_errorMonitor->VerifyNotFound();
4177}
4178
4179// This is a positive test. No errors should be generated.
4180TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4181
4182 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4183 "on the same queue, the second having a fence, followed "
4184 "by a WaitForFences call.");
4185
4186 m_errorMonitor->ExpectSuccess();
4187
4188 VkFence fence;
4189 VkFenceCreateInfo fence_create_info{};
4190 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4191 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4192
4193 VkCommandPool command_pool;
4194 VkCommandPoolCreateInfo pool_create_info{};
4195 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4196 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4197 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4198 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4199 &command_pool);
4200
4201 VkCommandBuffer command_buffer[2];
4202 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4203 command_buffer_allocate_info.sType =
4204 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4205 command_buffer_allocate_info.commandPool = command_pool;
4206 command_buffer_allocate_info.commandBufferCount = 2;
4207 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4208 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4209 command_buffer);
4210
4211 {
4212 VkCommandBufferBeginInfo begin_info{};
4213 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4214 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4215
4216 vkCmdPipelineBarrier(command_buffer[0],
4217 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4218 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4219 0, nullptr, 0, nullptr);
4220
4221 VkViewport viewport{};
4222 viewport.maxDepth = 1.0f;
4223 viewport.minDepth = 0.0f;
4224 viewport.width = 512;
4225 viewport.height = 512;
4226 viewport.x = 0;
4227 viewport.y = 0;
4228 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4229 vkEndCommandBuffer(command_buffer[0]);
4230 }
4231 {
4232 VkCommandBufferBeginInfo begin_info{};
4233 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4234 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4235
4236 VkViewport viewport{};
4237 viewport.maxDepth = 1.0f;
4238 viewport.minDepth = 0.0f;
4239 viewport.width = 512;
4240 viewport.height = 512;
4241 viewport.x = 0;
4242 viewport.y = 0;
4243 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4244 vkEndCommandBuffer(command_buffer[1]);
4245 }
4246 {
4247 VkSubmitInfo submit_info{};
4248 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4249 submit_info.commandBufferCount = 1;
4250 submit_info.pCommandBuffers = &command_buffer[0];
4251 submit_info.signalSemaphoreCount = 0;
4252 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4253 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4254 }
4255 {
4256 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4257 VkSubmitInfo submit_info{};
4258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4259 submit_info.commandBufferCount = 1;
4260 submit_info.pCommandBuffers = &command_buffer[1];
4261 submit_info.waitSemaphoreCount = 0;
4262 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4263 submit_info.pWaitDstStageMask = flags;
4264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4265 }
4266
4267 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4268
4269 vkDestroyFence(m_device->device(), fence, nullptr);
4270 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4271 &command_buffer[0]);
4272 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4273
4274 m_errorMonitor->VerifyNotFound();
4275}
4276
4277// This is a positive test. No errors should be generated.
4278TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4279
4280 TEST_DESCRIPTION(
4281 "Two command buffers each in a separate SubmitInfo sent in a single "
4282 "QueueSubmit call followed by a WaitForFences call.");
4283
4284 m_errorMonitor->ExpectSuccess();
4285
4286 VkFence fence;
4287 VkFenceCreateInfo fence_create_info{};
4288 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4289 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4290
4291 VkSemaphore semaphore;
4292 VkSemaphoreCreateInfo semaphore_create_info{};
4293 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4294 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4295 &semaphore);
4296
4297 VkCommandPool command_pool;
4298 VkCommandPoolCreateInfo pool_create_info{};
4299 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4300 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4301 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4302 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4303 &command_pool);
4304
4305 VkCommandBuffer command_buffer[2];
4306 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4307 command_buffer_allocate_info.sType =
4308 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4309 command_buffer_allocate_info.commandPool = command_pool;
4310 command_buffer_allocate_info.commandBufferCount = 2;
4311 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4312 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4313 command_buffer);
4314
4315 {
4316 VkCommandBufferBeginInfo begin_info{};
4317 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4318 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4319
4320 vkCmdPipelineBarrier(command_buffer[0],
4321 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4322 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4323 0, nullptr, 0, nullptr);
4324
4325 VkViewport viewport{};
4326 viewport.maxDepth = 1.0f;
4327 viewport.minDepth = 0.0f;
4328 viewport.width = 512;
4329 viewport.height = 512;
4330 viewport.x = 0;
4331 viewport.y = 0;
4332 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4333 vkEndCommandBuffer(command_buffer[0]);
4334 }
4335 {
4336 VkCommandBufferBeginInfo begin_info{};
4337 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4338 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4339
4340 VkViewport viewport{};
4341 viewport.maxDepth = 1.0f;
4342 viewport.minDepth = 0.0f;
4343 viewport.width = 512;
4344 viewport.height = 512;
4345 viewport.x = 0;
4346 viewport.y = 0;
4347 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4348 vkEndCommandBuffer(command_buffer[1]);
4349 }
4350 {
4351 VkSubmitInfo submit_info[2];
4352 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4353
4354 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4355 submit_info[0].pNext = NULL;
4356 submit_info[0].commandBufferCount = 1;
4357 submit_info[0].pCommandBuffers = &command_buffer[0];
4358 submit_info[0].signalSemaphoreCount = 1;
4359 submit_info[0].pSignalSemaphores = &semaphore;
4360 submit_info[0].waitSemaphoreCount = 0;
4361 submit_info[0].pWaitSemaphores = NULL;
4362 submit_info[0].pWaitDstStageMask = 0;
4363
4364 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4365 submit_info[1].pNext = NULL;
4366 submit_info[1].commandBufferCount = 1;
4367 submit_info[1].pCommandBuffers = &command_buffer[1];
4368 submit_info[1].waitSemaphoreCount = 1;
4369 submit_info[1].pWaitSemaphores = &semaphore;
4370 submit_info[1].pWaitDstStageMask = flags;
4371 submit_info[1].signalSemaphoreCount = 0;
4372 submit_info[1].pSignalSemaphores = NULL;
4373 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4374 }
4375
4376 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4377
4378 vkDestroyFence(m_device->device(), fence, nullptr);
4379 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4380 &command_buffer[0]);
4381 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004382 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004383
4384 m_errorMonitor->VerifyNotFound();
4385}
4386
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004387TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004388 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004389 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4390 "state is required but not correctly bound.");
4391
4392 // Dynamic depth bias
4393 m_errorMonitor->SetDesiredFailureMsg(
4394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4395 "Dynamic depth bias state not set for this command buffer");
4396 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4397 BsoFailDepthBias);
4398 m_errorMonitor->VerifyFound();
4399}
4400
4401TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4402 TEST_DESCRIPTION(
4403 "Run a simple draw calls to validate failure when Line Width dynamic "
4404 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004405
4406 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004407 m_errorMonitor->SetDesiredFailureMsg(
4408 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004409 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004410 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4411 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004412 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004413}
4414
4415TEST_F(VkLayerTest, DynamicViewportNotBound) {
4416 TEST_DESCRIPTION(
4417 "Run a simple draw calls to validate failure when Viewport dynamic "
4418 "state is required but not correctly bound.");
4419
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004420 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004421 m_errorMonitor->SetDesiredFailureMsg(
4422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004423 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004424 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4425 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004426 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004427}
4428
4429TEST_F(VkLayerTest, DynamicScissorNotBound) {
4430 TEST_DESCRIPTION(
4431 "Run a simple draw calls to validate failure when Scissor dynamic "
4432 "state is required but not correctly bound.");
4433
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004434 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004435 m_errorMonitor->SetDesiredFailureMsg(
4436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004437 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004438 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4439 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004440 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004441}
4442
Tobin Ehlis21c88352016-05-26 06:15:45 -06004443TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004444 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004445 "Run a simple draw calls to validate failure when Blend Constants "
4446 "dynamic state is required but not correctly bound.");
4447 // Dynamic blend constant state
4448 m_errorMonitor->SetDesiredFailureMsg(
4449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4450 "Dynamic blend constants state not set for this command buffer");
4451 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4452 BsoFailBlend);
4453 m_errorMonitor->VerifyFound();
4454}
4455
4456TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4457 TEST_DESCRIPTION(
4458 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004459 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004460 if (!m_device->phy().features().depthBounds) {
4461 printf("Device does not support depthBounds test; skipped.\n");
4462 return;
4463 }
4464 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004465 m_errorMonitor->SetDesiredFailureMsg(
4466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004467 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004468 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4469 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004470 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004471}
4472
4473TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4474 TEST_DESCRIPTION(
4475 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4476 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004477 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004478 m_errorMonitor->SetDesiredFailureMsg(
4479 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004480 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004481 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4482 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004483 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004484}
4485
4486TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4487 TEST_DESCRIPTION(
4488 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4489 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004490 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004491 m_errorMonitor->SetDesiredFailureMsg(
4492 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004493 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004494 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4495 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004496 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004497}
4498
4499TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4500 TEST_DESCRIPTION(
4501 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4502 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004503 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004504 m_errorMonitor->SetDesiredFailureMsg(
4505 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004506 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004507 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4508 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004509 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004510}
4511
Karl Schultz6addd812016-02-02 17:17:23 -07004512TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004513 m_errorMonitor->SetDesiredFailureMsg(
4514 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4515 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4516 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004517
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004518 ASSERT_NO_FATAL_FAILURE(InitState());
4519 ASSERT_NO_FATAL_FAILURE(InitViewport());
4520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4521
Karl Schultz6addd812016-02-02 17:17:23 -07004522 // We luck out b/c by default the framework creates CB w/ the
4523 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004524 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004525 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4526 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004527 EndCommandBuffer();
4528
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004529 // Bypass framework since it does the waits automatically
4530 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004531 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004532 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4533 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004534 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004535 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004536 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004537 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004538 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004539 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004540 submit_info.pSignalSemaphores = NULL;
4541
Chris Forbes40028e22016-06-13 09:59:34 +12004542 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004543 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004544
Karl Schultz6addd812016-02-02 17:17:23 -07004545 // Cause validation error by re-submitting cmd buffer that should only be
4546 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004547 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004548
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004549 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004550}
4551
Karl Schultz6addd812016-02-02 17:17:23 -07004552TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004553 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004554 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004555
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004557 "Unable to allocate 1 descriptors of "
4558 "type "
4559 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004560
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004561 ASSERT_NO_FATAL_FAILURE(InitState());
4562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004563
Karl Schultz6addd812016-02-02 17:17:23 -07004564 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4565 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004566 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004567 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4568 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004569
4570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4572 ds_pool_ci.pNext = NULL;
4573 ds_pool_ci.flags = 0;
4574 ds_pool_ci.maxSets = 1;
4575 ds_pool_ci.poolSizeCount = 1;
4576 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004577
4578 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004579 err =
4580 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004581 ASSERT_VK_SUCCESS(err);
4582
4583 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004584 dsl_binding.binding = 0;
4585 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4586 dsl_binding.descriptorCount = 1;
4587 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4588 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004589
4590 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004591 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4592 ds_layout_ci.pNext = NULL;
4593 ds_layout_ci.bindingCount = 1;
4594 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004595
4596 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004597 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4598 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004599 ASSERT_VK_SUCCESS(err);
4600
4601 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004602 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004604 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004605 alloc_info.descriptorPool = ds_pool;
4606 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4608 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004609
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004610 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004611
Chia-I Wuf7458c52015-10-26 21:10:41 +08004612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4613 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004614}
4615
Karl Schultz6addd812016-02-02 17:17:23 -07004616TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4617 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004618
Karl Schultz6addd812016-02-02 17:17:23 -07004619 m_errorMonitor->SetDesiredFailureMsg(
4620 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4621 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4622 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004623
Tobin Ehlise735c692015-10-08 13:13:50 -06004624 ASSERT_NO_FATAL_FAILURE(InitState());
4625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004626
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004627 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004628 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4629 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004630
4631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4633 ds_pool_ci.pNext = NULL;
4634 ds_pool_ci.maxSets = 1;
4635 ds_pool_ci.poolSizeCount = 1;
4636 ds_pool_ci.flags = 0;
4637 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4638 // app can only call vkResetDescriptorPool on this pool.;
4639 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004640
4641 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004642 err =
4643 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004644 ASSERT_VK_SUCCESS(err);
4645
4646 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004647 dsl_binding.binding = 0;
4648 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4649 dsl_binding.descriptorCount = 1;
4650 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4651 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004652
4653 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004654 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4655 ds_layout_ci.pNext = NULL;
4656 ds_layout_ci.bindingCount = 1;
4657 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004658
4659 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4661 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004662 ASSERT_VK_SUCCESS(err);
4663
4664 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004665 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004666 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004667 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004668 alloc_info.descriptorPool = ds_pool;
4669 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004670 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4671 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004672 ASSERT_VK_SUCCESS(err);
4673
4674 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004675 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004676
Chia-I Wuf7458c52015-10-26 21:10:41 +08004677 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4678 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004679}
4680
Karl Schultz6addd812016-02-02 17:17:23 -07004681TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004682 // Attempt to clear Descriptor Pool with bad object.
4683 // ObjectTracker should catch this.
4684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4685 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004686 uint64_t fake_pool_handle = 0xbaad6001;
4687 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4688 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004689 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004690}
4691
Karl Schultz6addd812016-02-02 17:17:23 -07004692TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004693 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4694 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004695 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004696 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004697
4698 uint64_t fake_set_handle = 0xbaad6001;
4699 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004700 VkResult err;
4701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4702 "Invalid VkDescriptorSet Object 0xbaad6001");
4703
4704 ASSERT_NO_FATAL_FAILURE(InitState());
4705
4706 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4707 layout_bindings[0].binding = 0;
4708 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4709 layout_bindings[0].descriptorCount = 1;
4710 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4711 layout_bindings[0].pImmutableSamplers = NULL;
4712
4713 VkDescriptorSetLayout descriptor_set_layout;
4714 VkDescriptorSetLayoutCreateInfo dslci = {};
4715 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4716 dslci.pNext = NULL;
4717 dslci.bindingCount = 1;
4718 dslci.pBindings = layout_bindings;
4719 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004720 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004721
4722 VkPipelineLayout pipeline_layout;
4723 VkPipelineLayoutCreateInfo plci = {};
4724 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4725 plci.pNext = NULL;
4726 plci.setLayoutCount = 1;
4727 plci.pSetLayouts = &descriptor_set_layout;
4728 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004729 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004730
4731 BeginCommandBuffer();
4732 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004733 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004734 m_errorMonitor->VerifyFound();
4735 EndCommandBuffer();
4736 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4737 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004738}
4739
Karl Schultz6addd812016-02-02 17:17:23 -07004740TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004741 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4742 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004743 uint64_t fake_layout_handle = 0xbaad6001;
4744 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4746 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4747
4748 VkPipelineLayout pipeline_layout;
4749 VkPipelineLayoutCreateInfo plci = {};
4750 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4751 plci.pNext = NULL;
4752 plci.setLayoutCount = 1;
4753 plci.pSetLayouts = &bad_layout;
4754 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4755
4756 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004757}
4758
Mark Muellerd4914412016-06-13 17:52:06 -06004759TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4760 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4761 "1) A uniform buffer update must have a valid buffer index."
4762 "2) When using an array of descriptors in a single WriteDescriptor,"
4763 " the descriptor types and stageflags must all be the same."
4764 "3) Immutable Sampler state must match across descriptors");
4765
4766 const char *invalid_BufferInfo_ErrorMessage =
4767 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4768 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4769 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4770 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004771 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004772 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004773 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004774
Mark Muellerd4914412016-06-13 17:52:06 -06004775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4776
4777 ASSERT_NO_FATAL_FAILURE(InitState());
4778 VkDescriptorPoolSize ds_type_count[4] = {};
4779 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4780 ds_type_count[0].descriptorCount = 1;
4781 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4782 ds_type_count[1].descriptorCount = 1;
4783 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4784 ds_type_count[2].descriptorCount = 1;
4785 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4786 ds_type_count[3].descriptorCount = 1;
4787
4788 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4789 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4790 ds_pool_ci.maxSets = 1;
4791 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4792 ds_pool_ci.pPoolSizes = ds_type_count;
4793
4794 VkDescriptorPool ds_pool;
4795 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4796 ASSERT_VK_SUCCESS(err);
4797
Mark Muellerb9896722016-06-16 09:54:29 -06004798 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004799 layout_binding[0].binding = 0;
4800 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4801 layout_binding[0].descriptorCount = 1;
4802 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4803 layout_binding[0].pImmutableSamplers = NULL;
4804
4805 layout_binding[1].binding = 1;
4806 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4807 layout_binding[1].descriptorCount = 1;
4808 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4809 layout_binding[1].pImmutableSamplers = NULL;
4810
4811 VkSamplerCreateInfo sampler_ci = {};
4812 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4813 sampler_ci.pNext = NULL;
4814 sampler_ci.magFilter = VK_FILTER_NEAREST;
4815 sampler_ci.minFilter = VK_FILTER_NEAREST;
4816 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4817 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4818 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4819 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4820 sampler_ci.mipLodBias = 1.0;
4821 sampler_ci.anisotropyEnable = VK_FALSE;
4822 sampler_ci.maxAnisotropy = 1;
4823 sampler_ci.compareEnable = VK_FALSE;
4824 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4825 sampler_ci.minLod = 1.0;
4826 sampler_ci.maxLod = 1.0;
4827 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4828 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4829 VkSampler sampler;
4830
4831 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4832 ASSERT_VK_SUCCESS(err);
4833
4834 layout_binding[2].binding = 2;
4835 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4836 layout_binding[2].descriptorCount = 1;
4837 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4838 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4839
Mark Muellerd4914412016-06-13 17:52:06 -06004840 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4841 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4842 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4843 ds_layout_ci.pBindings = layout_binding;
4844 VkDescriptorSetLayout ds_layout;
4845 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4846 ASSERT_VK_SUCCESS(err);
4847
4848 VkDescriptorSetAllocateInfo alloc_info = {};
4849 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4850 alloc_info.descriptorSetCount = 1;
4851 alloc_info.descriptorPool = ds_pool;
4852 alloc_info.pSetLayouts = &ds_layout;
4853 VkDescriptorSet descriptorSet;
4854 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4855 ASSERT_VK_SUCCESS(err);
4856
4857 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4858 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4859 pipeline_layout_ci.pNext = NULL;
4860 pipeline_layout_ci.setLayoutCount = 1;
4861 pipeline_layout_ci.pSetLayouts = &ds_layout;
4862
4863 VkPipelineLayout pipeline_layout;
4864 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4865 ASSERT_VK_SUCCESS(err);
4866
Mark Mueller5c838ce2016-06-16 09:54:29 -06004867 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004868 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4869 descriptor_write.dstSet = descriptorSet;
4870 descriptor_write.dstBinding = 0;
4871 descriptor_write.descriptorCount = 1;
4872 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4873
Mark Mueller5c838ce2016-06-16 09:54:29 -06004874 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004875 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4876 m_errorMonitor->VerifyFound();
4877
4878 // Create a buffer to update the descriptor with
4879 uint32_t qfi = 0;
4880 VkBufferCreateInfo buffCI = {};
4881 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4882 buffCI.size = 1024;
4883 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4884 buffCI.queueFamilyIndexCount = 1;
4885 buffCI.pQueueFamilyIndices = &qfi;
4886
4887 VkBuffer dyub;
4888 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4889 ASSERT_VK_SUCCESS(err);
4890 VkDescriptorBufferInfo buffInfo = {};
4891 buffInfo.buffer = dyub;
4892 buffInfo.offset = 0;
4893 buffInfo.range = 1024;
4894
4895 descriptor_write.pBufferInfo = &buffInfo;
4896 descriptor_write.descriptorCount = 2;
4897
Mark Mueller5c838ce2016-06-16 09:54:29 -06004898 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4900 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4901 m_errorMonitor->VerifyFound();
4902
Mark Mueller5c838ce2016-06-16 09:54:29 -06004903 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4904 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004905 descriptor_write.dstBinding = 1;
4906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004907
4908
4909 // Make pImageInfo index non-null to avoid complaints of it missing
4910 VkDescriptorImageInfo imageInfo = {};
4911 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4912 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4914 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4915 m_errorMonitor->VerifyFound();
4916
Mark Muellerd4914412016-06-13 17:52:06 -06004917 vkDestroyBuffer(m_device->device(), dyub, NULL);
4918 vkDestroySampler(m_device->device(), sampler, NULL);
4919 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4920 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4921 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4922}
4923
Karl Schultz6addd812016-02-02 17:17:23 -07004924TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004925 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4926 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004927 // Create a valid cmd buffer
4928 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004929 uint64_t fake_pipeline_handle = 0xbaad6001;
4930 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4932 "Invalid VkPipeline Object 0xbaad6001");
4933 ASSERT_NO_FATAL_FAILURE(InitState());
4934 BeginCommandBuffer();
4935 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4936 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4937 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004938 // Now issue a draw call with no pipeline bound
4939 m_errorMonitor->SetDesiredFailureMsg(
4940 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4941 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004942
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004943 BeginCommandBuffer();
4944 Draw(1, 0, 0, 0);
4945 m_errorMonitor->VerifyFound();
4946 // Finally same check once more but with Dispatch/Compute
4947 m_errorMonitor->SetDesiredFailureMsg(
4948 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4949 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004950 BeginCommandBuffer();
4951 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4952 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004953}
4954
Karl Schultz6addd812016-02-02 17:17:23 -07004955TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4956 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4957 // CommandBuffer
4958 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004959
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004961 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004962
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004963 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004964 ASSERT_NO_FATAL_FAILURE(InitViewport());
4965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004966 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4968 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004969
4970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4972 ds_pool_ci.pNext = NULL;
4973 ds_pool_ci.maxSets = 1;
4974 ds_pool_ci.poolSizeCount = 1;
4975 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004976
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004977 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004978 err =
4979 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004980 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004981
Tony Barboureb254902015-07-15 12:50:33 -06004982 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004983 dsl_binding.binding = 0;
4984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4985 dsl_binding.descriptorCount = 1;
4986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4987 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004988
Tony Barboureb254902015-07-15 12:50:33 -06004989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4991 ds_layout_ci.pNext = NULL;
4992 ds_layout_ci.bindingCount = 1;
4993 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004994 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004995 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4996 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004997 ASSERT_VK_SUCCESS(err);
4998
4999 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005000 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005001 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005002 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005003 alloc_info.descriptorPool = ds_pool;
5004 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5006 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005007 ASSERT_VK_SUCCESS(err);
5008
Tony Barboureb254902015-07-15 12:50:33 -06005009 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005010 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5011 pipeline_layout_ci.pNext = NULL;
5012 pipeline_layout_ci.setLayoutCount = 1;
5013 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005014
5015 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005016 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5017 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005018 ASSERT_VK_SUCCESS(err);
5019
Karl Schultz6addd812016-02-02 17:17:23 -07005020 VkShaderObj vs(m_device, bindStateVertShaderText,
5021 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005022 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005023 // on more devices
5024 VkShaderObj fs(m_device, bindStateFragShaderText,
5025 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005026
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005027 VkPipelineObj pipe(m_device);
5028 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005029 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005030 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005031 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005032
5033 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005034 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5035 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5036 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5037 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5038 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005041
Chia-I Wuf7458c52015-10-26 21:10:41 +08005042 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5043 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5044 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005045}
5046
Karl Schultz6addd812016-02-02 17:17:23 -07005047TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005048 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005049 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005050
Karl Schultz6addd812016-02-02 17:17:23 -07005051 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005052 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5053 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005054
5055 ASSERT_NO_FATAL_FAILURE(InitState());
5056 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005057 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5058 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005059
5060 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005061 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5062 ds_pool_ci.pNext = NULL;
5063 ds_pool_ci.maxSets = 1;
5064 ds_pool_ci.poolSizeCount = 1;
5065 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005066
5067 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005068 err =
5069 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005070 ASSERT_VK_SUCCESS(err);
5071
5072 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005073 dsl_binding.binding = 0;
5074 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5075 dsl_binding.descriptorCount = 1;
5076 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5077 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005078
5079 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005080 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5081 ds_layout_ci.pNext = NULL;
5082 ds_layout_ci.bindingCount = 1;
5083 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005084 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5086 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005087 ASSERT_VK_SUCCESS(err);
5088
5089 VkDescriptorSet descriptorSet;
5090 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005091 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005092 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005093 alloc_info.descriptorPool = ds_pool;
5094 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005095 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5096 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005097 ASSERT_VK_SUCCESS(err);
5098
Karl Schultz6addd812016-02-02 17:17:23 -07005099 VkBufferView view =
5100 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005101 VkWriteDescriptorSet descriptor_write;
5102 memset(&descriptor_write, 0, sizeof(descriptor_write));
5103 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5104 descriptor_write.dstSet = descriptorSet;
5105 descriptor_write.dstBinding = 0;
5106 descriptor_write.descriptorCount = 1;
5107 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5108 descriptor_write.pTexelBufferView = &view;
5109
5110 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5111
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005112 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005113
5114 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5116}
5117
Karl Schultz6addd812016-02-02 17:17:23 -07005118TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5119 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5120 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005121 // 1. No dynamicOffset supplied
5122 // 2. Too many dynamicOffsets supplied
5123 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005124 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005126 " requires 1 dynamicOffsets, but only "
5127 "0 dynamicOffsets are left in "
5128 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005129
5130 ASSERT_NO_FATAL_FAILURE(InitState());
5131 ASSERT_NO_FATAL_FAILURE(InitViewport());
5132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5133
5134 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005135 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5136 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005137
5138 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005139 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5140 ds_pool_ci.pNext = NULL;
5141 ds_pool_ci.maxSets = 1;
5142 ds_pool_ci.poolSizeCount = 1;
5143 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005144
5145 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005146 err =
5147 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005148 ASSERT_VK_SUCCESS(err);
5149
5150 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005151 dsl_binding.binding = 0;
5152 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5153 dsl_binding.descriptorCount = 1;
5154 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5155 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005156
5157 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005158 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5159 ds_layout_ci.pNext = NULL;
5160 ds_layout_ci.bindingCount = 1;
5161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005162 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5164 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005165 ASSERT_VK_SUCCESS(err);
5166
5167 VkDescriptorSet descriptorSet;
5168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005170 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005171 alloc_info.descriptorPool = ds_pool;
5172 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5174 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005175 ASSERT_VK_SUCCESS(err);
5176
5177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5179 pipeline_layout_ci.pNext = NULL;
5180 pipeline_layout_ci.setLayoutCount = 1;
5181 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005182
5183 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5185 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005186 ASSERT_VK_SUCCESS(err);
5187
5188 // Create a buffer to update the descriptor with
5189 uint32_t qfi = 0;
5190 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005191 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5192 buffCI.size = 1024;
5193 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5194 buffCI.queueFamilyIndexCount = 1;
5195 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005196
5197 VkBuffer dyub;
5198 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5199 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005200 // Allocate memory and bind to buffer so we can make it to the appropriate
5201 // error
5202 VkMemoryAllocateInfo mem_alloc = {};
5203 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5204 mem_alloc.pNext = NULL;
5205 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005206 mem_alloc.memoryTypeIndex = 0;
5207
5208 VkMemoryRequirements memReqs;
5209 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5210 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5211 0);
5212 if (!pass) {
5213 vkDestroyBuffer(m_device->device(), dyub, NULL);
5214 return;
5215 }
5216
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005217 VkDeviceMemory mem;
5218 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5219 ASSERT_VK_SUCCESS(err);
5220 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5221 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005222 // Correctly update descriptor to avoid "NOT_UPDATED" error
5223 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005224 buffInfo.buffer = dyub;
5225 buffInfo.offset = 0;
5226 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005227
5228 VkWriteDescriptorSet descriptor_write;
5229 memset(&descriptor_write, 0, sizeof(descriptor_write));
5230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5231 descriptor_write.dstSet = descriptorSet;
5232 descriptor_write.dstBinding = 0;
5233 descriptor_write.descriptorCount = 1;
5234 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5235 descriptor_write.pBufferInfo = &buffInfo;
5236
5237 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5238
5239 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005240 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5241 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5242 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005243 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005244 uint32_t pDynOff[2] = {512, 756};
5245 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005246 m_errorMonitor->SetDesiredFailureMsg(
5247 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005248 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5250 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5251 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005252 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005253 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5255 " dynamic offset 512 combined with "
5256 "offset 0 and range 1024 that "
5257 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005258 // Create PSO to be used for draw-time errors below
5259 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005260 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005261 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005262 "out gl_PerVertex { \n"
5263 " vec4 gl_Position;\n"
5264 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005265 "void main(){\n"
5266 " gl_Position = vec4(1);\n"
5267 "}\n";
5268 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005269 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005270 "\n"
5271 "layout(location=0) out vec4 x;\n"
5272 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5273 "void main(){\n"
5274 " x = vec4(bar.y);\n"
5275 "}\n";
5276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5278 VkPipelineObj pipe(m_device);
5279 pipe.AddShader(&vs);
5280 pipe.AddShader(&fs);
5281 pipe.AddColorAttachment();
5282 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5283
Karl Schultz6addd812016-02-02 17:17:23 -07005284 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5285 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5286 // This update should succeed, but offset size of 512 will overstep buffer
5287 // /w range 1024 & size 1024
5288 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5289 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5290 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005291 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005292 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005293
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005294 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005295 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005296
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005298 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005299 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5300}
5301
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005302TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005303 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005304 ASSERT_NO_FATAL_FAILURE(InitState());
5305 ASSERT_NO_FATAL_FAILURE(InitViewport());
5306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5307
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005308 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005309 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005310 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5311 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5312 pipeline_layout_ci.pushConstantRangeCount = 1;
5313 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5314
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005315 //
5316 // Check for invalid push constant ranges in pipeline layouts.
5317 //
5318 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005319 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005320 char const *msg;
5321 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005322
Karl Schultzc81037d2016-05-12 08:11:23 -06005323 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5324 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5325 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5326 "vkCreatePipelineLayout() call has push constants index 0 with "
5327 "size 0."},
5328 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5329 "vkCreatePipelineLayout() call has push constants index 0 with "
5330 "size 1."},
5331 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5332 "vkCreatePipelineLayout() call has push constants index 0 with "
5333 "size 1."},
5334 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5335 "vkCreatePipelineLayout() call has push constants index 0 with "
5336 "size 0."},
5337 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5338 "vkCreatePipelineLayout() call has push constants index 0 with "
5339 "offset 1. Offset must"},
5340 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5341 "vkCreatePipelineLayout() call has push constants index 0 "
5342 "with offset "},
5343 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5344 "vkCreatePipelineLayout() call has push constants "
5345 "index 0 with offset "},
5346 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5347 "vkCreatePipelineLayout() call has push constants index 0 "
5348 "with offset "},
5349 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5350 "vkCreatePipelineLayout() call has push "
5351 "constants index 0 with offset "},
5352 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5353 "vkCreatePipelineLayout() call has push "
5354 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005355 }};
5356
5357 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005358 for (const auto &iter : range_tests) {
5359 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5361 iter.msg);
5362 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5363 NULL, &pipeline_layout);
5364 m_errorMonitor->VerifyFound();
5365 if (VK_SUCCESS == err) {
5366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5367 }
5368 }
5369
5370 // Check for invalid stage flag
5371 pc_range.offset = 0;
5372 pc_range.size = 16;
5373 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005374 m_errorMonitor->SetDesiredFailureMsg(
5375 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005376 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005377 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5378 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005379 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005380 if (VK_SUCCESS == err) {
5381 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5382 }
5383
5384 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005385 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005386 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005387 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005388 char const *msg;
5389 };
5390
Karl Schultzc81037d2016-05-12 08:11:23 -06005391 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005392 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5393 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5394 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5395 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5396 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5397 "vkCreatePipelineLayout() call has push constants with overlapping "
5398 "ranges: 0:[0, 4), 1:[0, 4)"},
5399 {
5400 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5401 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5402 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5403 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5404 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5405 "vkCreatePipelineLayout() call has push constants with "
5406 "overlapping "
5407 "ranges: 3:[12, 20), 4:[16, 20)",
5408 },
5409 {
5410 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5411 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5412 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5413 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5414 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5415 "vkCreatePipelineLayout() call has push constants with "
5416 "overlapping "
5417 "ranges: 0:[16, 20), 1:[12, 20)",
5418 },
5419 {
5420 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5421 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5422 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5423 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5424 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5425 "vkCreatePipelineLayout() call has push constants with "
5426 "overlapping "
5427 "ranges: 0:[16, 20), 3:[12, 20)",
5428 },
5429 {
5430 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5431 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5432 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5433 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5434 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5435 "vkCreatePipelineLayout() call has push constants with "
5436 "overlapping "
5437 "ranges: 0:[16, 20), 2:[4, 100)",
5438 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005439
Karl Schultzc81037d2016-05-12 08:11:23 -06005440 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005441 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005442 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005444 iter.msg);
5445 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5446 NULL, &pipeline_layout);
5447 m_errorMonitor->VerifyFound();
5448 if (VK_SUCCESS == err) {
5449 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5450 }
5451 }
5452
5453 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005454 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5455 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5456 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5457 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5458 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5459 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5460 ""},
5461 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5462 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5463 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5464 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5465 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5466 ""}}};
5467 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005468 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5469 m_errorMonitor->ExpectSuccess();
5470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5471 NULL, &pipeline_layout);
5472 m_errorMonitor->VerifyNotFound();
5473 if (VK_SUCCESS == err) {
5474 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5475 }
5476 }
5477
5478 //
5479 // CmdPushConstants tests
5480 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005481 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005482
5483 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005484 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5485 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5486 "vkCmdPushConstants() call has push constants with size 0. Size "
5487 "must be greater than zero and a multiple of 4."},
5488 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5489 "vkCmdPushConstants() call has push constants with size 1. Size "
5490 "must be greater than zero and a multiple of 4."},
5491 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5492 "vkCmdPushConstants() call has push constants with size 1. Size "
5493 "must be greater than zero and a multiple of 4."},
5494 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5495 "vkCmdPushConstants() call has push constants with offset 1. "
5496 "Offset must be a multiple of 4."},
5497 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5498 "vkCmdPushConstants() call has push constants with offset 1. "
5499 "Offset must be a multiple of 4."},
5500 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5501 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5502 "0x1 not within flag-matching ranges in pipeline layout"},
5503 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5504 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5505 "0x1 not within flag-matching ranges in pipeline layout"},
5506 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5507 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5508 "0x1 not within flag-matching ranges in pipeline layout"},
5509 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5510 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5511 "0x1 not within flag-matching ranges in pipeline layout"},
5512 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5513 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5514 "any of the ranges in pipeline layout"},
5515 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5516 0, 16},
5517 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5518 "any of the ranges in pipeline layout"},
5519 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005520 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005521 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005522 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005523 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005524 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005525 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005526 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005527 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005528 "vkCmdPushConstants() call has push constants with offset "},
5529 }};
5530
5531 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005532 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005533 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005534 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005535 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005536 pipeline_layout_ci.pushConstantRangeCount =
5537 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005538 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5540 &pipeline_layout);
5541 ASSERT_VK_SUCCESS(err);
5542 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005543 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5545 iter.msg);
5546 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005547 iter.range.stageFlags, iter.range.offset,
5548 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005549 m_errorMonitor->VerifyFound();
5550 }
5551
5552 // Check for invalid stage flag
5553 m_errorMonitor->SetDesiredFailureMsg(
5554 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5555 "vkCmdPushConstants() call has no stageFlags set.");
5556 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005557 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005558 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005559 EndCommandBuffer();
5560 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5561 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005562
Karl Schultzc81037d2016-05-12 08:11:23 -06005563 // overlapping range tests with cmd
5564 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5565 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5566 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5567 "0x1 not within flag-matching ranges in pipeline layout"},
5568 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5569 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5570 "0x1 not within flag-matching ranges in pipeline layout"},
5571 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5572 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5573 "0x1 not within flag-matching ranges in pipeline layout"},
5574 }};
5575 const VkPushConstantRange pc_range3[] = {
5576 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5577 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5578 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5579 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5580 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5581 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5582 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5583 };
5584 pipeline_layout_ci.pushConstantRangeCount =
5585 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5586 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5587 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5588 &pipeline_layout);
5589 ASSERT_VK_SUCCESS(err);
5590 BeginCommandBuffer();
5591 for (const auto &iter : cmd_overlap_tests) {
5592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5593 iter.msg);
5594 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5595 iter.range.stageFlags, iter.range.offset,
5596 iter.range.size, dummy_values);
5597 m_errorMonitor->VerifyFound();
5598 }
5599 EndCommandBuffer();
5600 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5602
5603 // positive overlapping range tests with cmd
5604 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5605 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5606 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5607 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5608 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5609 }};
5610 const VkPushConstantRange pc_range4[] = {
5611 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5612 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5613 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5614 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5615 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5616 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5617 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5618 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5619 };
5620 pipeline_layout_ci.pushConstantRangeCount =
5621 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5622 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5623 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5624 &pipeline_layout);
5625 ASSERT_VK_SUCCESS(err);
5626 BeginCommandBuffer();
5627 for (const auto &iter : cmd_overlap_tests_pos) {
5628 m_errorMonitor->ExpectSuccess();
5629 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5630 iter.range.stageFlags, iter.range.offset,
5631 iter.range.size, dummy_values);
5632 m_errorMonitor->VerifyNotFound();
5633 }
5634 EndCommandBuffer();
5635 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005636 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5637}
5638
Karl Schultz6addd812016-02-02 17:17:23 -07005639TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005640 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005641 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005642
5643 ASSERT_NO_FATAL_FAILURE(InitState());
5644 ASSERT_NO_FATAL_FAILURE(InitViewport());
5645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5646
5647 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5648 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005649 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5650 ds_type_count[0].descriptorCount = 10;
5651 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5652 ds_type_count[1].descriptorCount = 2;
5653 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5654 ds_type_count[2].descriptorCount = 2;
5655 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5656 ds_type_count[3].descriptorCount = 5;
5657 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5658 // type
5659 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5660 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5661 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005662
5663 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005664 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5665 ds_pool_ci.pNext = NULL;
5666 ds_pool_ci.maxSets = 5;
5667 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5668 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005669
5670 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005671 err =
5672 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005673 ASSERT_VK_SUCCESS(err);
5674
5675 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5676 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005677 dsl_binding[0].binding = 0;
5678 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5679 dsl_binding[0].descriptorCount = 5;
5680 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5681 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005682
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005683 // Create layout identical to set0 layout but w/ different stageFlags
5684 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005685 dsl_fs_stage_only.binding = 0;
5686 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5687 dsl_fs_stage_only.descriptorCount = 5;
5688 dsl_fs_stage_only.stageFlags =
5689 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5690 // bind time
5691 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5694 ds_layout_ci.pNext = NULL;
5695 ds_layout_ci.bindingCount = 1;
5696 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005697 static const uint32_t NUM_LAYOUTS = 4;
5698 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005699 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005700 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5701 // layout for error case
5702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5703 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005704 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005705 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5707 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005708 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005709 dsl_binding[0].binding = 0;
5710 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005711 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005712 dsl_binding[1].binding = 1;
5713 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5714 dsl_binding[1].descriptorCount = 2;
5715 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5716 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005717 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005718 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005719 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5720 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005721 ASSERT_VK_SUCCESS(err);
5722 dsl_binding[0].binding = 0;
5723 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005724 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005725 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005726 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5727 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005728 ASSERT_VK_SUCCESS(err);
5729 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005730 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5732 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005733 ASSERT_VK_SUCCESS(err);
5734
5735 static const uint32_t NUM_SETS = 4;
5736 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5737 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005739 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005740 alloc_info.descriptorPool = ds_pool;
5741 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5743 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005744 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005745 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005746 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005747 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005748 err =
5749 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005750 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005751
5752 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005753 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5754 pipeline_layout_ci.pNext = NULL;
5755 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5756 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005757
5758 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005759 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5760 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005761 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005762 // Create pipelineLayout with only one setLayout
5763 pipeline_layout_ci.setLayoutCount = 1;
5764 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005765 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5766 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005767 ASSERT_VK_SUCCESS(err);
5768 // Create pipelineLayout with 2 descriptor setLayout at index 0
5769 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5770 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005771 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5772 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005773 ASSERT_VK_SUCCESS(err);
5774 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5775 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5776 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005777 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5778 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005779 ASSERT_VK_SUCCESS(err);
5780 // Create pipelineLayout with UB type, but stageFlags for FS only
5781 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5782 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5784 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005785 ASSERT_VK_SUCCESS(err);
5786 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5787 VkDescriptorSetLayout pl_bad_s0[2] = {};
5788 pl_bad_s0[0] = ds_layout_fs_only;
5789 pl_bad_s0[1] = ds_layout[1];
5790 pipeline_layout_ci.setLayoutCount = 2;
5791 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5792 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5794 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005796
5797 // Create a buffer to update the descriptor with
5798 uint32_t qfi = 0;
5799 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005800 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5801 buffCI.size = 1024;
5802 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5803 buffCI.queueFamilyIndexCount = 1;
5804 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005805
5806 VkBuffer dyub;
5807 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5808 ASSERT_VK_SUCCESS(err);
5809 // Correctly update descriptor to avoid "NOT_UPDATED" error
5810 static const uint32_t NUM_BUFFS = 5;
5811 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005812 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005813 buffInfo[i].buffer = dyub;
5814 buffInfo[i].offset = 0;
5815 buffInfo[i].range = 1024;
5816 }
Karl Schultz6addd812016-02-02 17:17:23 -07005817 VkImage image;
5818 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5819 const int32_t tex_width = 32;
5820 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005821 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005822 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5823 image_create_info.pNext = NULL;
5824 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5825 image_create_info.format = tex_format;
5826 image_create_info.extent.width = tex_width;
5827 image_create_info.extent.height = tex_height;
5828 image_create_info.extent.depth = 1;
5829 image_create_info.mipLevels = 1;
5830 image_create_info.arrayLayers = 1;
5831 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5832 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5833 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5834 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5836 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005837
Karl Schultz6addd812016-02-02 17:17:23 -07005838 VkMemoryRequirements memReqs;
5839 VkDeviceMemory imageMem;
5840 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005841 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005842 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5843 memAlloc.pNext = NULL;
5844 memAlloc.allocationSize = 0;
5845 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005846 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5847 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005848 pass =
5849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005850 ASSERT_TRUE(pass);
5851 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5852 ASSERT_VK_SUCCESS(err);
5853 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5854 ASSERT_VK_SUCCESS(err);
5855
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005856 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005857 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5858 image_view_create_info.image = image;
5859 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5860 image_view_create_info.format = tex_format;
5861 image_view_create_info.subresourceRange.layerCount = 1;
5862 image_view_create_info.subresourceRange.baseMipLevel = 0;
5863 image_view_create_info.subresourceRange.levelCount = 1;
5864 image_view_create_info.subresourceRange.aspectMask =
5865 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005866
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005867 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005868 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5869 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005870 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005871 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005872 imageInfo[0].imageView = view;
5873 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5874 imageInfo[1].imageView = view;
5875 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005876 imageInfo[2].imageView = view;
5877 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5878 imageInfo[3].imageView = view;
5879 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005880
5881 static const uint32_t NUM_SET_UPDATES = 3;
5882 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5883 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5884 descriptor_write[0].dstSet = descriptorSet[0];
5885 descriptor_write[0].dstBinding = 0;
5886 descriptor_write[0].descriptorCount = 5;
5887 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5888 descriptor_write[0].pBufferInfo = buffInfo;
5889 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5890 descriptor_write[1].dstSet = descriptorSet[1];
5891 descriptor_write[1].dstBinding = 0;
5892 descriptor_write[1].descriptorCount = 2;
5893 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5894 descriptor_write[1].pImageInfo = imageInfo;
5895 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5896 descriptor_write[2].dstSet = descriptorSet[1];
5897 descriptor_write[2].dstBinding = 1;
5898 descriptor_write[2].descriptorCount = 2;
5899 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005900 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005901
5902 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005903
Tobin Ehlis88452832015-12-03 09:40:56 -07005904 // Create PSO to be used for draw-time errors below
5905 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005906 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005907 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005908 "out gl_PerVertex {\n"
5909 " vec4 gl_Position;\n"
5910 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005911 "void main(){\n"
5912 " gl_Position = vec4(1);\n"
5913 "}\n";
5914 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005915 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005916 "\n"
5917 "layout(location=0) out vec4 x;\n"
5918 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5919 "void main(){\n"
5920 " x = vec4(bar.y);\n"
5921 "}\n";
5922 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5923 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005924 VkPipelineObj pipe(m_device);
5925 pipe.AddShader(&vs);
5926 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005927 pipe.AddColorAttachment();
5928 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005929
5930 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005931
Karl Schultz6addd812016-02-02 17:17:23 -07005932 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5933 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5934 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5935 // of PSO
5936 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5937 // cmd_pipeline.c
5938 // due to the fact that cmd_alloc_dset_data() has not been called in
5939 // cmd_bind_graphics_pipeline()
5940 // TODO : Want to cause various binding incompatibility issues here to test
5941 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005942 // First cause various verify_layout_compatibility() fails
5943 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005944 // verify_set_layout_compatibility fail cases:
5945 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5947 " due to: invalid VkPipelineLayout ");
5948 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5949 VK_PIPELINE_BIND_POINT_GRAPHICS,
5950 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5951 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005952 m_errorMonitor->VerifyFound();
5953
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005954 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5956 " attempting to bind set to index 1");
5957 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5958 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5959 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005960 m_errorMonitor->VerifyFound();
5961
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005962 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005963 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5964 // descriptors
5965 m_errorMonitor->SetDesiredFailureMsg(
5966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005967 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005968 vkCmdBindDescriptorSets(
5969 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5970 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005971 m_errorMonitor->VerifyFound();
5972
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005973 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5974 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005975 m_errorMonitor->SetDesiredFailureMsg(
5976 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005977 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005978 vkCmdBindDescriptorSets(
5979 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5980 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005981 m_errorMonitor->VerifyFound();
5982
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005983 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5984 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005985 m_errorMonitor->SetDesiredFailureMsg(
5986 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005987 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005988 vkCmdBindDescriptorSets(
5989 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5990 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005991 m_errorMonitor->VerifyFound();
5992
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005993 // Cause INFO messages due to disturbing previously bound Sets
5994 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005995 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5996 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5997 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005998 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005999 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006000 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006001 " previously bound as set #0 was disturbed ");
6002 vkCmdBindDescriptorSets(
6003 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6004 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006005 m_errorMonitor->VerifyFound();
6006
Karl Schultz6addd812016-02-02 17:17:23 -07006007 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6008 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6009 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006010 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006012 " newly bound as set #0 so set #1 and "
6013 "any subsequent sets were disturbed ");
6014 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6015 VK_PIPELINE_BIND_POINT_GRAPHICS,
6016 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006017 m_errorMonitor->VerifyFound();
6018
Tobin Ehlis88452832015-12-03 09:40:56 -07006019 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006020 // 1. Error due to not binding required set (we actually use same code as
6021 // above to disturb set0)
6022 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6023 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6024 2, &descriptorSet[0], 0, NULL);
6025 vkCmdBindDescriptorSets(
6026 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6027 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6028 m_errorMonitor->SetDesiredFailureMsg(
6029 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6030 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006031 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006032 m_errorMonitor->VerifyFound();
6033
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006034 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006035 // 2. Error due to bound set not being compatible with PSO's
6036 // VkPipelineLayout (diff stageFlags in this case)
6037 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6038 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6039 2, &descriptorSet[0], 0, NULL);
6040 m_errorMonitor->SetDesiredFailureMsg(
6041 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6042 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006043 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006044 m_errorMonitor->VerifyFound();
6045
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006046 // Remaining clean-up
6047 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006048 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006049 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6050 }
6051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006052 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6053 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006054 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6056 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006057 vkFreeMemory(m_device->device(), imageMem, NULL);
6058 vkDestroyImage(m_device->device(), image, NULL);
6059 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006060}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006061
Karl Schultz6addd812016-02-02 17:17:23 -07006062TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006063
Karl Schultz6addd812016-02-02 17:17:23 -07006064 m_errorMonitor->SetDesiredFailureMsg(
6065 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006066 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006067
6068 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006069 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006070 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006071 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006072
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006073 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006074}
6075
Karl Schultz6addd812016-02-02 17:17:23 -07006076TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6077 VkResult err;
6078 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006079
Karl Schultz6addd812016-02-02 17:17:23 -07006080 m_errorMonitor->SetDesiredFailureMsg(
6081 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006082 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006083
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006084 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006085
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006086 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006087 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006088 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006089 cmd.commandPool = m_commandPool;
6090 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006091 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006092
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006093 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006094 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006095
6096 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006097 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006098 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006099 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006100 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006101 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6102 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006103 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006104
6105 // The error should be caught by validation of the BeginCommandBuffer call
6106 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6107
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006108 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006109 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006110}
6111
Karl Schultz6addd812016-02-02 17:17:23 -07006112TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006113 // Cause error due to Begin while recording CB
6114 // Then cause 2 errors for attempting to reset CB w/o having
6115 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6116 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006118 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006119
6120 ASSERT_NO_FATAL_FAILURE(InitState());
6121
6122 // Calls AllocateCommandBuffers
6123 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6124
Karl Schultz6addd812016-02-02 17:17:23 -07006125 // Force the failure by setting the Renderpass and Framebuffer fields with
6126 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006127 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006128 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006129 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6130 cmd_buf_info.pNext = NULL;
6131 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006132 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006133
6134 // Begin CB to transition to recording state
6135 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6136 // Can't re-begin. This should trigger error
6137 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006138 m_errorMonitor->VerifyFound();
6139
Karl Schultz6addd812016-02-02 17:17:23 -07006140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6141 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006142 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6143 // Reset attempt will trigger error due to incorrect CommandPool state
6144 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006145 m_errorMonitor->VerifyFound();
6146
Karl Schultz6addd812016-02-02 17:17:23 -07006147 m_errorMonitor->SetDesiredFailureMsg(
6148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6149 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006150 // Transition CB to RECORDED state
6151 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6152 // Now attempting to Begin will implicitly reset, which triggers error
6153 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006154 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006155}
6156
Karl Schultz6addd812016-02-02 17:17:23 -07006157TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006158 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006159 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006160
Karl Schultz6addd812016-02-02 17:17:23 -07006161 m_errorMonitor->SetDesiredFailureMsg(
6162 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006163 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6164
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006167
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006168 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006169 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6170 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006171
6172 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006173 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6174 ds_pool_ci.pNext = NULL;
6175 ds_pool_ci.maxSets = 1;
6176 ds_pool_ci.poolSizeCount = 1;
6177 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006178
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006179 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006180 err =
6181 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006182 ASSERT_VK_SUCCESS(err);
6183
Tony Barboureb254902015-07-15 12:50:33 -06006184 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006185 dsl_binding.binding = 0;
6186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6187 dsl_binding.descriptorCount = 1;
6188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6189 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006190
Tony Barboureb254902015-07-15 12:50:33 -06006191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6193 ds_layout_ci.pNext = NULL;
6194 ds_layout_ci.bindingCount = 1;
6195 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006196
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006197 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6199 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006200 ASSERT_VK_SUCCESS(err);
6201
6202 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006203 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006205 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006206 alloc_info.descriptorPool = ds_pool;
6207 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6209 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006210 ASSERT_VK_SUCCESS(err);
6211
Tony Barboureb254902015-07-15 12:50:33 -06006212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6214 pipeline_layout_ci.setLayoutCount = 1;
6215 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006216
6217 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6219 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006220 ASSERT_VK_SUCCESS(err);
6221
Tobin Ehlise68360f2015-10-01 11:15:13 -06006222 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006223 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006224
6225 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006226 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6227 vp_state_ci.scissorCount = 1;
6228 vp_state_ci.pScissors = &sc;
6229 vp_state_ci.viewportCount = 1;
6230 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006231
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006232 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6233 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6234 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6235 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6236 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6237 rs_state_ci.depthClampEnable = VK_FALSE;
6238 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6239 rs_state_ci.depthBiasEnable = VK_FALSE;
6240
Tony Barboureb254902015-07-15 12:50:33 -06006241 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006242 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6243 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006244 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006245 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6246 gp_ci.layout = pipeline_layout;
6247 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006248
6249 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006250 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6251 pc_ci.initialDataSize = 0;
6252 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006253
6254 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006255 VkPipelineCache pipelineCache;
6256
Karl Schultz6addd812016-02-02 17:17:23 -07006257 err =
6258 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006259 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006260 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6261 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006263 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006264
Chia-I Wuf7458c52015-10-26 21:10:41 +08006265 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6266 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6267 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6268 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006269}
Tobin Ehlis912df022015-09-17 08:46:18 -06006270/*// TODO : This test should be good, but needs Tess support in compiler to run
6271TEST_F(VkLayerTest, InvalidPatchControlPoints)
6272{
6273 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006274 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006277 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6278primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006279
Tobin Ehlis912df022015-09-17 08:46:18 -06006280 ASSERT_NO_FATAL_FAILURE(InitState());
6281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006282
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006283 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006284 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006285 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006286
6287 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6288 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6289 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006290 ds_pool_ci.poolSizeCount = 1;
6291 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006292
6293 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006294 err = vkCreateDescriptorPool(m_device->device(),
6295VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006296 ASSERT_VK_SUCCESS(err);
6297
6298 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006299 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006300 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006301 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006302 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6303 dsl_binding.pImmutableSamplers = NULL;
6304
6305 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006306 ds_layout_ci.sType =
6307VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006308 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006309 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006310 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006311
6312 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006313 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6314&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006315 ASSERT_VK_SUCCESS(err);
6316
6317 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006318 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6319VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006320 ASSERT_VK_SUCCESS(err);
6321
6322 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006323 pipeline_layout_ci.sType =
6324VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006325 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006326 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006327 pipeline_layout_ci.pSetLayouts = &ds_layout;
6328
6329 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6331&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006332 ASSERT_VK_SUCCESS(err);
6333
6334 VkPipelineShaderStageCreateInfo shaderStages[3];
6335 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6336
Karl Schultz6addd812016-02-02 17:17:23 -07006337 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6338this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006339 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006340 VkShaderObj
6341tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6342this);
6343 VkShaderObj
6344te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6345this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006346
Karl Schultz6addd812016-02-02 17:17:23 -07006347 shaderStages[0].sType =
6348VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006349 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006350 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006351 shaderStages[1].sType =
6352VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006353 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006354 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006355 shaderStages[2].sType =
6356VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006357 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006358 shaderStages[2].shader = te.handle();
6359
6360 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006361 iaCI.sType =
6362VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006363 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006364
6365 VkPipelineTessellationStateCreateInfo tsCI = {};
6366 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6367 tsCI.patchControlPoints = 0; // This will cause an error
6368
6369 VkGraphicsPipelineCreateInfo gp_ci = {};
6370 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6371 gp_ci.pNext = NULL;
6372 gp_ci.stageCount = 3;
6373 gp_ci.pStages = shaderStages;
6374 gp_ci.pVertexInputState = NULL;
6375 gp_ci.pInputAssemblyState = &iaCI;
6376 gp_ci.pTessellationState = &tsCI;
6377 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006378 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006379 gp_ci.pMultisampleState = NULL;
6380 gp_ci.pDepthStencilState = NULL;
6381 gp_ci.pColorBlendState = NULL;
6382 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6383 gp_ci.layout = pipeline_layout;
6384 gp_ci.renderPass = renderPass();
6385
6386 VkPipelineCacheCreateInfo pc_ci = {};
6387 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6388 pc_ci.pNext = NULL;
6389 pc_ci.initialSize = 0;
6390 pc_ci.initialData = 0;
6391 pc_ci.maxSize = 0;
6392
6393 VkPipeline pipeline;
6394 VkPipelineCache pipelineCache;
6395
Karl Schultz6addd812016-02-02 17:17:23 -07006396 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6397&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006398 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006399 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6400&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006401
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006402 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006403
Chia-I Wuf7458c52015-10-26 21:10:41 +08006404 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6405 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6406 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6407 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006408}
6409*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006410// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006411TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006412 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006413
Karl Schultz6addd812016-02-02 17:17:23 -07006414 m_errorMonitor->SetDesiredFailureMsg(
6415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006416 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6417
Tobin Ehlise68360f2015-10-01 11:15:13 -06006418 ASSERT_NO_FATAL_FAILURE(InitState());
6419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006420
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006421 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6423 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006424
6425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6427 ds_pool_ci.maxSets = 1;
6428 ds_pool_ci.poolSizeCount = 1;
6429 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006430
6431 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006432 err =
6433 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006434 ASSERT_VK_SUCCESS(err);
6435
6436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006437 dsl_binding.binding = 0;
6438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6439 dsl_binding.descriptorCount = 1;
6440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006441
6442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6444 ds_layout_ci.bindingCount = 1;
6445 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006446
6447 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006448 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6449 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006450 ASSERT_VK_SUCCESS(err);
6451
6452 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006453 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006454 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006455 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006456 alloc_info.descriptorPool = ds_pool;
6457 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006458 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6459 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006460 ASSERT_VK_SUCCESS(err);
6461
6462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6464 pipeline_layout_ci.setLayoutCount = 1;
6465 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006466
6467 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6469 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006470 ASSERT_VK_SUCCESS(err);
6471
6472 VkViewport vp = {}; // Just need dummy vp to point to
6473
6474 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006475 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6476 vp_state_ci.scissorCount = 0;
6477 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6478 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006479
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006480 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6481 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6482 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6483 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6484 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6485 rs_state_ci.depthClampEnable = VK_FALSE;
6486 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6487 rs_state_ci.depthBiasEnable = VK_FALSE;
6488
Cody Northropeb3a6c12015-10-05 14:44:45 -06006489 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006490 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006491
Karl Schultz6addd812016-02-02 17:17:23 -07006492 VkShaderObj vs(m_device, bindStateVertShaderText,
6493 VK_SHADER_STAGE_VERTEX_BIT, this);
6494 VkShaderObj fs(m_device, bindStateFragShaderText,
6495 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006496 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006497 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006498 shaderStages[0] = vs.GetStageCreateInfo();
6499 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006500
6501 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6503 gp_ci.stageCount = 2;
6504 gp_ci.pStages = shaderStages;
6505 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006506 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006507 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6508 gp_ci.layout = pipeline_layout;
6509 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006510
6511 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006512 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006513
6514 VkPipeline pipeline;
6515 VkPipelineCache pipelineCache;
6516
Karl Schultz6addd812016-02-02 17:17:23 -07006517 err =
6518 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006519 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006520 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6521 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006522
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006523 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006524
Chia-I Wuf7458c52015-10-26 21:10:41 +08006525 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6528 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006529}
Karl Schultz6addd812016-02-02 17:17:23 -07006530// Don't set viewport state in PSO. This is an error b/c we always need this
6531// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006532// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006533TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006534 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006535 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006536
Karl Schultz6addd812016-02-02 17:17:23 -07006537 m_errorMonitor->SetDesiredFailureMsg(
6538 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006539 "Gfx Pipeline pViewportState is null. Even if ");
6540
Tobin Ehlise68360f2015-10-01 11:15:13 -06006541 ASSERT_NO_FATAL_FAILURE(InitState());
6542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006543
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006544 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6546 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006547
6548 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006549 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6550 ds_pool_ci.maxSets = 1;
6551 ds_pool_ci.poolSizeCount = 1;
6552 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006553
6554 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006555 err =
6556 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006557 ASSERT_VK_SUCCESS(err);
6558
6559 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006560 dsl_binding.binding = 0;
6561 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6562 dsl_binding.descriptorCount = 1;
6563 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006564
6565 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006566 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6567 ds_layout_ci.bindingCount = 1;
6568 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006569
6570 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6572 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006573 ASSERT_VK_SUCCESS(err);
6574
6575 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006576 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006577 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006578 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006579 alloc_info.descriptorPool = ds_pool;
6580 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006581 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6582 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006583 ASSERT_VK_SUCCESS(err);
6584
6585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6587 pipeline_layout_ci.setLayoutCount = 1;
6588 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006589
6590 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6592 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006593 ASSERT_VK_SUCCESS(err);
6594
6595 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6596 // Set scissor as dynamic to avoid second error
6597 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006598 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6599 dyn_state_ci.dynamicStateCount = 1;
6600 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006601
Cody Northropeb3a6c12015-10-05 14:44:45 -06006602 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006603 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006604
Karl Schultz6addd812016-02-02 17:17:23 -07006605 VkShaderObj vs(m_device, bindStateVertShaderText,
6606 VK_SHADER_STAGE_VERTEX_BIT, this);
6607 VkShaderObj fs(m_device, bindStateFragShaderText,
6608 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006609 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006610 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006611 shaderStages[0] = vs.GetStageCreateInfo();
6612 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006613
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006614
6615 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6616 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6617 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6618 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6619 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6620 rs_state_ci.depthClampEnable = VK_FALSE;
6621 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6622 rs_state_ci.depthBiasEnable = VK_FALSE;
6623
Tobin Ehlise68360f2015-10-01 11:15:13 -06006624 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006625 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6626 gp_ci.stageCount = 2;
6627 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006628 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006629 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6630 // should cause validation error
6631 gp_ci.pDynamicState = &dyn_state_ci;
6632 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6633 gp_ci.layout = pipeline_layout;
6634 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006635
6636 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006637 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006638
6639 VkPipeline pipeline;
6640 VkPipelineCache pipelineCache;
6641
Karl Schultz6addd812016-02-02 17:17:23 -07006642 err =
6643 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006644 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006645 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6646 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006647
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006648 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006649
Chia-I Wuf7458c52015-10-26 21:10:41 +08006650 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6652 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6653 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006654}
6655// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006656// Then run second test where dynamic scissor count doesn't match PSO scissor
6657// count
6658TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6659 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006660
Karl Schultz6addd812016-02-02 17:17:23 -07006661 m_errorMonitor->SetDesiredFailureMsg(
6662 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006663 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6664
Tobin Ehlise68360f2015-10-01 11:15:13 -06006665 ASSERT_NO_FATAL_FAILURE(InitState());
6666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006667
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006668 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006669 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6670 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006671
6672 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006673 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6674 ds_pool_ci.maxSets = 1;
6675 ds_pool_ci.poolSizeCount = 1;
6676 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006677
6678 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006679 err =
6680 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006681 ASSERT_VK_SUCCESS(err);
6682
6683 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006684 dsl_binding.binding = 0;
6685 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6686 dsl_binding.descriptorCount = 1;
6687 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006688
6689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6691 ds_layout_ci.bindingCount = 1;
6692 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006693
6694 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006695 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6696 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006697 ASSERT_VK_SUCCESS(err);
6698
6699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006702 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006703 alloc_info.descriptorPool = ds_pool;
6704 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6706 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006707 ASSERT_VK_SUCCESS(err);
6708
6709 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006710 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6711 pipeline_layout_ci.setLayoutCount = 1;
6712 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006713
6714 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006715 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6716 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006717 ASSERT_VK_SUCCESS(err);
6718
6719 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006720 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6721 vp_state_ci.viewportCount = 1;
6722 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6723 vp_state_ci.scissorCount = 1;
6724 vp_state_ci.pScissors =
6725 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006726
6727 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6728 // Set scissor as dynamic to avoid that error
6729 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006730 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6731 dyn_state_ci.dynamicStateCount = 1;
6732 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006733
Cody Northropeb3a6c12015-10-05 14:44:45 -06006734 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006735 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006736
Karl Schultz6addd812016-02-02 17:17:23 -07006737 VkShaderObj vs(m_device, bindStateVertShaderText,
6738 VK_SHADER_STAGE_VERTEX_BIT, this);
6739 VkShaderObj fs(m_device, bindStateFragShaderText,
6740 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006741 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006742 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006743 shaderStages[0] = vs.GetStageCreateInfo();
6744 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006745
Cody Northropf6622dc2015-10-06 10:33:21 -06006746 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6747 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6748 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006749 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006750 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006751 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006752 vi_ci.pVertexAttributeDescriptions = nullptr;
6753
6754 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6755 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6756 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6757
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006758 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006759 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006760 rs_ci.pNext = nullptr;
6761
Mark Youngc89c6312016-03-31 16:03:20 -06006762 VkPipelineColorBlendAttachmentState att = {};
6763 att.blendEnable = VK_FALSE;
6764 att.colorWriteMask = 0xf;
6765
Cody Northropf6622dc2015-10-06 10:33:21 -06006766 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6767 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6768 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006769 cb_ci.attachmentCount = 1;
6770 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006771
Tobin Ehlise68360f2015-10-01 11:15:13 -06006772 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006773 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6774 gp_ci.stageCount = 2;
6775 gp_ci.pStages = shaderStages;
6776 gp_ci.pVertexInputState = &vi_ci;
6777 gp_ci.pInputAssemblyState = &ia_ci;
6778 gp_ci.pViewportState = &vp_state_ci;
6779 gp_ci.pRasterizationState = &rs_ci;
6780 gp_ci.pColorBlendState = &cb_ci;
6781 gp_ci.pDynamicState = &dyn_state_ci;
6782 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6783 gp_ci.layout = pipeline_layout;
6784 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006785
6786 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006787 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006788
6789 VkPipeline pipeline;
6790 VkPipelineCache pipelineCache;
6791
Karl Schultz6addd812016-02-02 17:17:23 -07006792 err =
6793 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006794 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006795 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6796 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006797
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006798 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006799
Tobin Ehlisd332f282015-10-02 11:00:56 -06006800 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006801 // First need to successfully create the PSO from above by setting
6802 // pViewports
6803 m_errorMonitor->SetDesiredFailureMsg(
6804 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6805 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6806 "scissorCount is 1. These counts must match.");
6807
6808 VkViewport vp = {}; // Just need dummy vp to point to
6809 vp_state_ci.pViewports = &vp;
6810 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6811 &gp_ci, NULL, &pipeline);
6812 ASSERT_VK_SUCCESS(err);
6813 BeginCommandBuffer();
6814 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6815 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6816 VkRect2D scissors[2] = {}; // don't care about data
6817 // Count of 2 doesn't match PSO count of 1
6818 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6819 Draw(1, 0, 0, 0);
6820
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006821 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006822
6823 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6824 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006827 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006828}
6829// Create PSO w/o non-zero scissorCount but no scissor data
6830// Then run second test where dynamic viewportCount doesn't match PSO
6831// viewportCount
6832TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6833 VkResult err;
6834
6835 m_errorMonitor->SetDesiredFailureMsg(
6836 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6837 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6838
6839 ASSERT_NO_FATAL_FAILURE(InitState());
6840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6841
6842 VkDescriptorPoolSize ds_type_count = {};
6843 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6844 ds_type_count.descriptorCount = 1;
6845
6846 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6847 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6848 ds_pool_ci.maxSets = 1;
6849 ds_pool_ci.poolSizeCount = 1;
6850 ds_pool_ci.pPoolSizes = &ds_type_count;
6851
6852 VkDescriptorPool ds_pool;
6853 err =
6854 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6855 ASSERT_VK_SUCCESS(err);
6856
6857 VkDescriptorSetLayoutBinding dsl_binding = {};
6858 dsl_binding.binding = 0;
6859 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6860 dsl_binding.descriptorCount = 1;
6861 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6862
6863 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6864 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6865 ds_layout_ci.bindingCount = 1;
6866 ds_layout_ci.pBindings = &dsl_binding;
6867
6868 VkDescriptorSetLayout ds_layout;
6869 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6870 &ds_layout);
6871 ASSERT_VK_SUCCESS(err);
6872
6873 VkDescriptorSet descriptorSet;
6874 VkDescriptorSetAllocateInfo alloc_info = {};
6875 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6876 alloc_info.descriptorSetCount = 1;
6877 alloc_info.descriptorPool = ds_pool;
6878 alloc_info.pSetLayouts = &ds_layout;
6879 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6880 &descriptorSet);
6881 ASSERT_VK_SUCCESS(err);
6882
6883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6885 pipeline_layout_ci.setLayoutCount = 1;
6886 pipeline_layout_ci.pSetLayouts = &ds_layout;
6887
6888 VkPipelineLayout pipeline_layout;
6889 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6890 &pipeline_layout);
6891 ASSERT_VK_SUCCESS(err);
6892
6893 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6894 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6895 vp_state_ci.scissorCount = 1;
6896 vp_state_ci.pScissors =
6897 NULL; // Null scissor w/ count of 1 should cause error
6898 vp_state_ci.viewportCount = 1;
6899 vp_state_ci.pViewports =
6900 NULL; // vp is dynamic (below) so this won't cause error
6901
6902 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6903 // Set scissor as dynamic to avoid that error
6904 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6905 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6906 dyn_state_ci.dynamicStateCount = 1;
6907 dyn_state_ci.pDynamicStates = &vp_state;
6908
6909 VkPipelineShaderStageCreateInfo shaderStages[2];
6910 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6911
6912 VkShaderObj vs(m_device, bindStateVertShaderText,
6913 VK_SHADER_STAGE_VERTEX_BIT, this);
6914 VkShaderObj fs(m_device, bindStateFragShaderText,
6915 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006916 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006917 // but add it to be able to run on more devices
6918 shaderStages[0] = vs.GetStageCreateInfo();
6919 shaderStages[1] = fs.GetStageCreateInfo();
6920
6921 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6922 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6923 vi_ci.pNext = nullptr;
6924 vi_ci.vertexBindingDescriptionCount = 0;
6925 vi_ci.pVertexBindingDescriptions = nullptr;
6926 vi_ci.vertexAttributeDescriptionCount = 0;
6927 vi_ci.pVertexAttributeDescriptions = nullptr;
6928
6929 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6930 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6931 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6932
6933 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6934 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6935 rs_ci.pNext = nullptr;
6936
Mark Youngc89c6312016-03-31 16:03:20 -06006937 VkPipelineColorBlendAttachmentState att = {};
6938 att.blendEnable = VK_FALSE;
6939 att.colorWriteMask = 0xf;
6940
Karl Schultz6addd812016-02-02 17:17:23 -07006941 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6942 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6943 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006944 cb_ci.attachmentCount = 1;
6945 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006946
6947 VkGraphicsPipelineCreateInfo gp_ci = {};
6948 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6949 gp_ci.stageCount = 2;
6950 gp_ci.pStages = shaderStages;
6951 gp_ci.pVertexInputState = &vi_ci;
6952 gp_ci.pInputAssemblyState = &ia_ci;
6953 gp_ci.pViewportState = &vp_state_ci;
6954 gp_ci.pRasterizationState = &rs_ci;
6955 gp_ci.pColorBlendState = &cb_ci;
6956 gp_ci.pDynamicState = &dyn_state_ci;
6957 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6958 gp_ci.layout = pipeline_layout;
6959 gp_ci.renderPass = renderPass();
6960
6961 VkPipelineCacheCreateInfo pc_ci = {};
6962 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6963
6964 VkPipeline pipeline;
6965 VkPipelineCache pipelineCache;
6966
6967 err =
6968 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6969 ASSERT_VK_SUCCESS(err);
6970 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6971 &gp_ci, NULL, &pipeline);
6972
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006973 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006974
6975 // Now hit second fail case where we set scissor w/ different count than PSO
6976 // First need to successfully create the PSO from above by setting
6977 // pViewports
6978 m_errorMonitor->SetDesiredFailureMsg(
6979 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6980 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6981 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006982
Tobin Ehlisd332f282015-10-02 11:00:56 -06006983 VkRect2D sc = {}; // Just need dummy vp to point to
6984 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006985 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6986 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006987 ASSERT_VK_SUCCESS(err);
6988 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006989 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6990 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006991 VkViewport viewports[2] = {}; // don't care about data
6992 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006993 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006994 Draw(1, 0, 0, 0);
6995
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997
Chia-I Wuf7458c52015-10-26 21:10:41 +08006998 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6999 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7000 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7001 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007002 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007003}
7004
Mark Young7394fdd2016-03-31 14:56:43 -06007005TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7006 VkResult err;
7007
7008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007009 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007010
7011 ASSERT_NO_FATAL_FAILURE(InitState());
7012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7013
7014 VkDescriptorPoolSize ds_type_count = {};
7015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7016 ds_type_count.descriptorCount = 1;
7017
7018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7020 ds_pool_ci.maxSets = 1;
7021 ds_pool_ci.poolSizeCount = 1;
7022 ds_pool_ci.pPoolSizes = &ds_type_count;
7023
7024 VkDescriptorPool ds_pool;
7025 err =
7026 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7027 ASSERT_VK_SUCCESS(err);
7028
7029 VkDescriptorSetLayoutBinding dsl_binding = {};
7030 dsl_binding.binding = 0;
7031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7032 dsl_binding.descriptorCount = 1;
7033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7034
7035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7037 ds_layout_ci.bindingCount = 1;
7038 ds_layout_ci.pBindings = &dsl_binding;
7039
7040 VkDescriptorSetLayout ds_layout;
7041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7042 &ds_layout);
7043 ASSERT_VK_SUCCESS(err);
7044
7045 VkDescriptorSet descriptorSet;
7046 VkDescriptorSetAllocateInfo alloc_info = {};
7047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7048 alloc_info.descriptorSetCount = 1;
7049 alloc_info.descriptorPool = ds_pool;
7050 alloc_info.pSetLayouts = &ds_layout;
7051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7052 &descriptorSet);
7053 ASSERT_VK_SUCCESS(err);
7054
7055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7057 pipeline_layout_ci.setLayoutCount = 1;
7058 pipeline_layout_ci.pSetLayouts = &ds_layout;
7059
7060 VkPipelineLayout pipeline_layout;
7061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7062 &pipeline_layout);
7063 ASSERT_VK_SUCCESS(err);
7064
7065 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7066 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7067 vp_state_ci.scissorCount = 1;
7068 vp_state_ci.pScissors = NULL;
7069 vp_state_ci.viewportCount = 1;
7070 vp_state_ci.pViewports = NULL;
7071
7072 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7073 VK_DYNAMIC_STATE_SCISSOR,
7074 VK_DYNAMIC_STATE_LINE_WIDTH};
7075 // Set scissor as dynamic to avoid that error
7076 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7077 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7078 dyn_state_ci.dynamicStateCount = 2;
7079 dyn_state_ci.pDynamicStates = dynamic_states;
7080
7081 VkPipelineShaderStageCreateInfo shaderStages[2];
7082 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7083
7084 VkShaderObj vs(m_device, bindStateVertShaderText,
7085 VK_SHADER_STAGE_VERTEX_BIT, this);
7086 VkShaderObj fs(m_device, bindStateFragShaderText,
7087 VK_SHADER_STAGE_FRAGMENT_BIT,
7088 this); // TODO - We shouldn't need a fragment shader
7089 // but add it to be able to run on more devices
7090 shaderStages[0] = vs.GetStageCreateInfo();
7091 shaderStages[1] = fs.GetStageCreateInfo();
7092
7093 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7094 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7095 vi_ci.pNext = nullptr;
7096 vi_ci.vertexBindingDescriptionCount = 0;
7097 vi_ci.pVertexBindingDescriptions = nullptr;
7098 vi_ci.vertexAttributeDescriptionCount = 0;
7099 vi_ci.pVertexAttributeDescriptions = nullptr;
7100
7101 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7102 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7103 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7104
7105 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7106 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7107 rs_ci.pNext = nullptr;
7108
Mark Young47107952016-05-02 15:59:55 -06007109 // Check too low (line width of -1.0f).
7110 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007111
7112 VkPipelineColorBlendAttachmentState att = {};
7113 att.blendEnable = VK_FALSE;
7114 att.colorWriteMask = 0xf;
7115
7116 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7117 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7118 cb_ci.pNext = nullptr;
7119 cb_ci.attachmentCount = 1;
7120 cb_ci.pAttachments = &att;
7121
7122 VkGraphicsPipelineCreateInfo gp_ci = {};
7123 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7124 gp_ci.stageCount = 2;
7125 gp_ci.pStages = shaderStages;
7126 gp_ci.pVertexInputState = &vi_ci;
7127 gp_ci.pInputAssemblyState = &ia_ci;
7128 gp_ci.pViewportState = &vp_state_ci;
7129 gp_ci.pRasterizationState = &rs_ci;
7130 gp_ci.pColorBlendState = &cb_ci;
7131 gp_ci.pDynamicState = &dyn_state_ci;
7132 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7133 gp_ci.layout = pipeline_layout;
7134 gp_ci.renderPass = renderPass();
7135
7136 VkPipelineCacheCreateInfo pc_ci = {};
7137 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7138
7139 VkPipeline pipeline;
7140 VkPipelineCache pipelineCache;
7141
7142 err =
7143 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7144 ASSERT_VK_SUCCESS(err);
7145 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7146 &gp_ci, NULL, &pipeline);
7147
7148 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007150
7151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7152 "Attempt to set lineWidth to 65536");
7153
7154 // Check too high (line width of 65536.0f).
7155 rs_ci.lineWidth = 65536.0f;
7156
7157 err =
7158 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7159 ASSERT_VK_SUCCESS(err);
7160 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7161 &gp_ci, NULL, &pipeline);
7162
7163 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007164 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007165
7166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007167 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007168
7169 dyn_state_ci.dynamicStateCount = 3;
7170
7171 rs_ci.lineWidth = 1.0f;
7172
7173 err =
7174 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7175 ASSERT_VK_SUCCESS(err);
7176 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7177 &gp_ci, NULL, &pipeline);
7178 BeginCommandBuffer();
7179 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7180 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7181
7182 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007183 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007184 m_errorMonitor->VerifyFound();
7185
7186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7187 "Attempt to set lineWidth to 65536");
7188
7189 // Check too high with dynamic setting.
7190 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7191 m_errorMonitor->VerifyFound();
7192 EndCommandBuffer();
7193
7194 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7195 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7196 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007198 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007199}
7200
Karl Schultz6addd812016-02-02 17:17:23 -07007201TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007202 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007203 m_errorMonitor->SetDesiredFailureMsg(
7204 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007205 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007206
7207 ASSERT_NO_FATAL_FAILURE(InitState());
7208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007209
Tony Barbourfe3351b2015-07-28 10:17:20 -06007210 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007211 // Don't care about RenderPass handle b/c error should be flagged before
7212 // that
7213 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7214 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007215
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007216 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007217}
7218
Karl Schultz6addd812016-02-02 17:17:23 -07007219TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007220 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007221 m_errorMonitor->SetDesiredFailureMsg(
7222 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007223 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007224
7225 ASSERT_NO_FATAL_FAILURE(InitState());
7226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007227
Tony Barbourfe3351b2015-07-28 10:17:20 -06007228 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007229 // Just create a dummy Renderpass that's non-NULL so we can get to the
7230 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007231 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007232 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7233 rp_begin.pNext = NULL;
7234 rp_begin.renderPass = renderPass();
7235 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007236
Karl Schultz6addd812016-02-02 17:17:23 -07007237 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7238 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007239
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007240 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007241}
7242
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007243TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7244 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7245 "the number of renderPass attachments that use loadOp"
7246 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7247
7248 ASSERT_NO_FATAL_FAILURE(InitState());
7249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7250
7251 // Create a renderPass with a single attachment that uses loadOp CLEAR
7252 VkAttachmentReference attach = {};
7253 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7254 VkSubpassDescription subpass = {};
7255 subpass.inputAttachmentCount = 1;
7256 subpass.pInputAttachments = &attach;
7257 VkRenderPassCreateInfo rpci = {};
7258 rpci.subpassCount = 1;
7259 rpci.pSubpasses = &subpass;
7260 rpci.attachmentCount = 1;
7261 VkAttachmentDescription attach_desc = {};
7262 attach_desc.format = VK_FORMAT_UNDEFINED;
7263 // Set loadOp to CLEAR
7264 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7265 rpci.pAttachments = &attach_desc;
7266 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7267 VkRenderPass rp;
7268 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7269
7270 VkCommandBufferInheritanceInfo hinfo = {};
7271 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7272 hinfo.renderPass = VK_NULL_HANDLE;
7273 hinfo.subpass = 0;
7274 hinfo.framebuffer = VK_NULL_HANDLE;
7275 hinfo.occlusionQueryEnable = VK_FALSE;
7276 hinfo.queryFlags = 0;
7277 hinfo.pipelineStatistics = 0;
7278 VkCommandBufferBeginInfo info = {};
7279 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7280 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7281 info.pInheritanceInfo = &hinfo;
7282
7283 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7284 VkRenderPassBeginInfo rp_begin = {};
7285 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7286 rp_begin.pNext = NULL;
7287 rp_begin.renderPass = renderPass();
7288 rp_begin.framebuffer = framebuffer();
7289 rp_begin.clearValueCount = 0; // Should be 1
7290
7291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7292 " has a clearValueCount of 0 but the "
7293 "actual number of attachments in "
7294 "renderPass ");
7295
7296 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7297 VK_SUBPASS_CONTENTS_INLINE);
7298
7299 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007300
7301 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007302}
7303
Cody Northrop3bb4d962016-05-09 16:15:57 -06007304TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7305
7306 TEST_DESCRIPTION("End a command buffer with an active render pass");
7307
7308 m_errorMonitor->SetDesiredFailureMsg(
7309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7310 "It is invalid to issue this call inside an active render pass");
7311
7312 ASSERT_NO_FATAL_FAILURE(InitState());
7313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7314
7315 // The framework's BeginCommandBuffer calls CreateRenderPass
7316 BeginCommandBuffer();
7317
7318 // Call directly into vkEndCommandBuffer instead of the
7319 // the framework's EndCommandBuffer, which inserts a
7320 // vkEndRenderPass
7321 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7322
7323 m_errorMonitor->VerifyFound();
7324
7325 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7326 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7327}
7328
Karl Schultz6addd812016-02-02 17:17:23 -07007329TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007330 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007331 m_errorMonitor->SetDesiredFailureMsg(
7332 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007333 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007334
7335 ASSERT_NO_FATAL_FAILURE(InitState());
7336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007337
7338 // Renderpass is started here
7339 BeginCommandBuffer();
7340
7341 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007342 vk_testing::Buffer dstBuffer;
7343 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007344
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007346
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007347 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007348}
7349
Karl Schultz6addd812016-02-02 17:17:23 -07007350TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007351 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007352 m_errorMonitor->SetDesiredFailureMsg(
7353 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007354 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007355
7356 ASSERT_NO_FATAL_FAILURE(InitState());
7357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007358
7359 // Renderpass is started here
7360 BeginCommandBuffer();
7361
7362 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007363 vk_testing::Buffer dstBuffer;
7364 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007365
Karl Schultz6addd812016-02-02 17:17:23 -07007366 VkDeviceSize dstOffset = 0;
7367 VkDeviceSize dataSize = 1024;
7368 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007369
Karl Schultz6addd812016-02-02 17:17:23 -07007370 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7371 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007372
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007373 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007374}
7375
Karl Schultz6addd812016-02-02 17:17:23 -07007376TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007377 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007378 m_errorMonitor->SetDesiredFailureMsg(
7379 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007380 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007381
7382 ASSERT_NO_FATAL_FAILURE(InitState());
7383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007384
7385 // Renderpass is started here
7386 BeginCommandBuffer();
7387
Michael Lentine0a369f62016-02-03 16:51:46 -06007388 VkClearColorValue clear_color;
7389 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007390 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7391 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7392 const int32_t tex_width = 32;
7393 const int32_t tex_height = 32;
7394 VkImageCreateInfo image_create_info = {};
7395 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7396 image_create_info.pNext = NULL;
7397 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7398 image_create_info.format = tex_format;
7399 image_create_info.extent.width = tex_width;
7400 image_create_info.extent.height = tex_height;
7401 image_create_info.extent.depth = 1;
7402 image_create_info.mipLevels = 1;
7403 image_create_info.arrayLayers = 1;
7404 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7405 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7406 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007407
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007408 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007409 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7410 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007411
Karl Schultz6addd812016-02-02 17:17:23 -07007412 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7413 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007414
Karl Schultz6addd812016-02-02 17:17:23 -07007415 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7416 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007418 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007419}
7420
Karl Schultz6addd812016-02-02 17:17:23 -07007421TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007422 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007423 m_errorMonitor->SetDesiredFailureMsg(
7424 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007425 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007426
7427 ASSERT_NO_FATAL_FAILURE(InitState());
7428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007429
7430 // Renderpass is started here
7431 BeginCommandBuffer();
7432
7433 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007434 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007435 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7436 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7437 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7438 image_create_info.extent.width = 64;
7439 image_create_info.extent.height = 64;
7440 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7441 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007442
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007443 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007444 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7445 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007446
Karl Schultz6addd812016-02-02 17:17:23 -07007447 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7448 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007449
Karl Schultz6addd812016-02-02 17:17:23 -07007450 vkCmdClearDepthStencilImage(
7451 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7452 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7453 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007454
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007455 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007456}
7457
Karl Schultz6addd812016-02-02 17:17:23 -07007458TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007459 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007460 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007461
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007463 "vkCmdClearAttachments: This call "
7464 "must be issued inside an active "
7465 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007466
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007467 ASSERT_NO_FATAL_FAILURE(InitState());
7468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007469
7470 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007471 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007472 ASSERT_VK_SUCCESS(err);
7473
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007474 VkClearAttachment color_attachment;
7475 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7476 color_attachment.clearValue.color.float32[0] = 0;
7477 color_attachment.clearValue.color.float32[1] = 0;
7478 color_attachment.clearValue.color.float32[2] = 0;
7479 color_attachment.clearValue.color.float32[3] = 0;
7480 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007481 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7482 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7483 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007484
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007485 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007486}
7487
Karl Schultz9e66a292016-04-21 15:57:51 -06007488TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7489 // Try to add a buffer memory barrier with no buffer.
7490 m_errorMonitor->SetDesiredFailureMsg(
7491 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7492 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7493
7494 ASSERT_NO_FATAL_FAILURE(InitState());
7495 BeginCommandBuffer();
7496
7497 VkBufferMemoryBarrier buf_barrier = {};
7498 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7499 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7500 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7501 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7502 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7503 buf_barrier.buffer = VK_NULL_HANDLE;
7504 buf_barrier.offset = 0;
7505 buf_barrier.size = VK_WHOLE_SIZE;
7506 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7507 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7508 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7509
7510 m_errorMonitor->VerifyFound();
7511}
7512
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007513TEST_F(VkLayerTest, InvalidBarriers) {
7514 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7515
7516 m_errorMonitor->SetDesiredFailureMsg(
7517 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7518
7519 ASSERT_NO_FATAL_FAILURE(InitState());
7520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7521
7522 VkMemoryBarrier mem_barrier = {};
7523 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7524 mem_barrier.pNext = NULL;
7525 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7526 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7527 BeginCommandBuffer();
7528 // BeginCommandBuffer() starts a render pass
7529 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7530 VK_PIPELINE_STAGE_HOST_BIT,
7531 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7532 &mem_barrier, 0, nullptr, 0, nullptr);
7533 m_errorMonitor->VerifyFound();
7534
7535 m_errorMonitor->SetDesiredFailureMsg(
7536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7537 "Image Layout cannot be transitioned to UNDEFINED");
7538 VkImageObj image(m_device);
7539 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7540 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7541 ASSERT_TRUE(image.initialized());
7542 VkImageMemoryBarrier img_barrier = {};
7543 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7544 img_barrier.pNext = NULL;
7545 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7546 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7547 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7548 // New layout can't be UNDEFINED
7549 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7550 img_barrier.image = image.handle();
7551 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7552 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7553 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7554 img_barrier.subresourceRange.baseArrayLayer = 0;
7555 img_barrier.subresourceRange.baseMipLevel = 0;
7556 img_barrier.subresourceRange.layerCount = 1;
7557 img_barrier.subresourceRange.levelCount = 1;
7558 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7559 VK_PIPELINE_STAGE_HOST_BIT,
7560 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7561 nullptr, 1, &img_barrier);
7562 m_errorMonitor->VerifyFound();
7563 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7564
7565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7566 "Subresource must have the sum of the "
7567 "baseArrayLayer");
7568 // baseArrayLayer + layerCount must be <= image's arrayLayers
7569 img_barrier.subresourceRange.baseArrayLayer = 1;
7570 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7571 VK_PIPELINE_STAGE_HOST_BIT,
7572 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7573 nullptr, 1, &img_barrier);
7574 m_errorMonitor->VerifyFound();
7575 img_barrier.subresourceRange.baseArrayLayer = 0;
7576
7577 m_errorMonitor->SetDesiredFailureMsg(
7578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7579 "Subresource must have the sum of the baseMipLevel");
7580 // baseMipLevel + levelCount must be <= image's mipLevels
7581 img_barrier.subresourceRange.baseMipLevel = 1;
7582 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7583 VK_PIPELINE_STAGE_HOST_BIT,
7584 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7585 nullptr, 1, &img_barrier);
7586 m_errorMonitor->VerifyFound();
7587 img_barrier.subresourceRange.baseMipLevel = 0;
7588
7589 m_errorMonitor->SetDesiredFailureMsg(
7590 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7591 "Buffer Barriers cannot be used during a render pass");
7592 vk_testing::Buffer buffer;
7593 buffer.init(*m_device, 256);
7594 VkBufferMemoryBarrier buf_barrier = {};
7595 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7596 buf_barrier.pNext = NULL;
7597 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7598 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7599 buf_barrier.buffer = buffer.handle();
7600 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7601 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7602 buf_barrier.offset = 0;
7603 buf_barrier.size = VK_WHOLE_SIZE;
7604 // Can't send buffer barrier during a render pass
7605 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7606 VK_PIPELINE_STAGE_HOST_BIT,
7607 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7608 &buf_barrier, 0, nullptr);
7609 m_errorMonitor->VerifyFound();
7610 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7611
7612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7613 "which is not less than total size");
7614 buf_barrier.offset = 257;
7615 // Offset greater than total size
7616 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7617 VK_PIPELINE_STAGE_HOST_BIT,
7618 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7619 &buf_barrier, 0, nullptr);
7620 m_errorMonitor->VerifyFound();
7621 buf_barrier.offset = 0;
7622
7623 m_errorMonitor->SetDesiredFailureMsg(
7624 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7625 buf_barrier.size = 257;
7626 // Size greater than total size
7627 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7628 VK_PIPELINE_STAGE_HOST_BIT,
7629 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7630 &buf_barrier, 0, nullptr);
7631 m_errorMonitor->VerifyFound();
7632 buf_barrier.size = VK_WHOLE_SIZE;
7633
7634 m_errorMonitor->SetDesiredFailureMsg(
7635 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7636 "Image is a depth and stencil format and thus must "
7637 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7638 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7639 VkDepthStencilObj ds_image(m_device);
7640 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7641 ASSERT_TRUE(ds_image.initialized());
7642 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7643 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7644 img_barrier.image = ds_image.handle();
7645 // Leave aspectMask at COLOR on purpose
7646 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7647 VK_PIPELINE_STAGE_HOST_BIT,
7648 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7649 nullptr, 1, &img_barrier);
7650 m_errorMonitor->VerifyFound();
7651}
7652
Karl Schultz6addd812016-02-02 17:17:23 -07007653TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007654 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007655 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007656
Karl Schultz6addd812016-02-02 17:17:23 -07007657 m_errorMonitor->SetDesiredFailureMsg(
7658 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007659 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7660
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007661 ASSERT_NO_FATAL_FAILURE(InitState());
7662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007663 uint32_t qfi = 0;
7664 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007665 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7666 buffCI.size = 1024;
7667 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7668 buffCI.queueFamilyIndexCount = 1;
7669 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007670
7671 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007672 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007673 ASSERT_VK_SUCCESS(err);
7674
7675 BeginCommandBuffer();
7676 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007677 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7678 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007679 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007680 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7681 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007682
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007683 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007684
Chia-I Wuf7458c52015-10-26 21:10:41 +08007685 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007686}
7687
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007688TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7689 // Create an out-of-range queueFamilyIndex
7690 m_errorMonitor->SetDesiredFailureMsg(
7691 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007692 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7693 "of the indices specified when the device was created, via the "
7694 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007695
7696 ASSERT_NO_FATAL_FAILURE(InitState());
7697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7698 VkBufferCreateInfo buffCI = {};
7699 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7700 buffCI.size = 1024;
7701 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7702 buffCI.queueFamilyIndexCount = 1;
7703 // Introduce failure by specifying invalid queue_family_index
7704 uint32_t qfi = 777;
7705 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007706 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007707
7708 VkBuffer ib;
7709 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7710
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007711 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007712 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007713}
7714
Karl Schultz6addd812016-02-02 17:17:23 -07007715TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7716 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7717 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007718
Karl Schultz6addd812016-02-02 17:17:23 -07007719 m_errorMonitor->SetDesiredFailureMsg(
7720 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007721 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007722
7723 ASSERT_NO_FATAL_FAILURE(InitState());
7724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007725
7726 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007727 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007728 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7729 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007730
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007731 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007732}
7733
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007734TEST_F(VkLayerTest, DSUsageBitsErrors) {
7735 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7736 "that do not have correct usage bits sets.");
7737 VkResult err;
7738
7739 ASSERT_NO_FATAL_FAILURE(InitState());
7740 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7741 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7742 ds_type_count[i].type = VkDescriptorType(i);
7743 ds_type_count[i].descriptorCount = 1;
7744 }
7745 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7746 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7747 ds_pool_ci.pNext = NULL;
7748 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7749 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7750 ds_pool_ci.pPoolSizes = ds_type_count;
7751
7752 VkDescriptorPool ds_pool;
7753 err =
7754 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7755 ASSERT_VK_SUCCESS(err);
7756
7757 // Create 10 layouts where each has a single descriptor of different type
7758 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7759 {};
7760 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7761 dsl_binding[i].binding = 0;
7762 dsl_binding[i].descriptorType = VkDescriptorType(i);
7763 dsl_binding[i].descriptorCount = 1;
7764 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7765 dsl_binding[i].pImmutableSamplers = NULL;
7766 }
7767
7768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7770 ds_layout_ci.pNext = NULL;
7771 ds_layout_ci.bindingCount = 1;
7772 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7773 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7774 ds_layout_ci.pBindings = dsl_binding + i;
7775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7776 NULL, ds_layouts + i);
7777 ASSERT_VK_SUCCESS(err);
7778 }
7779 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7780 VkDescriptorSetAllocateInfo alloc_info = {};
7781 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7782 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7783 alloc_info.descriptorPool = ds_pool;
7784 alloc_info.pSetLayouts = ds_layouts;
7785 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7786 descriptor_sets);
7787 ASSERT_VK_SUCCESS(err);
7788
7789 // Create a buffer & bufferView to be used for invalid updates
7790 VkBufferCreateInfo buff_ci = {};
7791 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7792 // This usage is not valid for any descriptor type
7793 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7794 buff_ci.size = 256;
7795 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7796 VkBuffer buffer;
7797 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7798 ASSERT_VK_SUCCESS(err);
7799
7800 VkBufferViewCreateInfo buff_view_ci = {};
7801 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7802 buff_view_ci.buffer = buffer;
7803 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7804 buff_view_ci.range = VK_WHOLE_SIZE;
7805 VkBufferView buff_view;
7806 err =
7807 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7808 ASSERT_VK_SUCCESS(err);
7809
7810 // Create an image to be used for invalid updates
7811 VkImageCreateInfo image_ci = {};
7812 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7813 image_ci.imageType = VK_IMAGE_TYPE_2D;
7814 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7815 image_ci.extent.width = 64;
7816 image_ci.extent.height = 64;
7817 image_ci.extent.depth = 1;
7818 image_ci.mipLevels = 1;
7819 image_ci.arrayLayers = 1;
7820 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7821 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7822 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7823 // This usage is not valid for any descriptor type
7824 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7825 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7826 VkImage image;
7827 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7828 ASSERT_VK_SUCCESS(err);
7829 // Bind memory to image
7830 VkMemoryRequirements mem_reqs;
7831 VkDeviceMemory image_mem;
7832 bool pass;
7833 VkMemoryAllocateInfo mem_alloc = {};
7834 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7835 mem_alloc.pNext = NULL;
7836 mem_alloc.allocationSize = 0;
7837 mem_alloc.memoryTypeIndex = 0;
7838 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7839 mem_alloc.allocationSize = mem_reqs.size;
7840 pass =
7841 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7842 ASSERT_TRUE(pass);
7843 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7844 ASSERT_VK_SUCCESS(err);
7845 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7846 ASSERT_VK_SUCCESS(err);
7847 // Now create view for image
7848 VkImageViewCreateInfo image_view_ci = {};
7849 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7850 image_view_ci.image = image;
7851 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7852 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7853 image_view_ci.subresourceRange.layerCount = 1;
7854 image_view_ci.subresourceRange.baseArrayLayer = 0;
7855 image_view_ci.subresourceRange.levelCount = 1;
7856 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7857 VkImageView image_view;
7858 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7859 &image_view);
7860 ASSERT_VK_SUCCESS(err);
7861
7862 VkDescriptorBufferInfo buff_info = {};
7863 buff_info.buffer = buffer;
7864 VkDescriptorImageInfo img_info = {};
7865 img_info.imageView = image_view;
7866 VkWriteDescriptorSet descriptor_write = {};
7867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7868 descriptor_write.dstBinding = 0;
7869 descriptor_write.descriptorCount = 1;
7870 descriptor_write.pTexelBufferView = &buff_view;
7871 descriptor_write.pBufferInfo = &buff_info;
7872 descriptor_write.pImageInfo = &img_info;
7873
7874 // These error messages align with VkDescriptorType struct
7875 const char *error_msgs[] = {
7876 "", // placeholder, no error for SAMPLER descriptor
7877 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7878 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7879 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7880 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7881 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7882 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7883 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7884 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7885 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7886 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7887 // Start loop at 1 as SAMPLER desc type has no usage bit error
7888 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7889 descriptor_write.descriptorType = VkDescriptorType(i);
7890 descriptor_write.dstSet = descriptor_sets[i];
7891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7892 error_msgs[i]);
7893
7894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7895 NULL);
7896
7897 m_errorMonitor->VerifyFound();
7898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7899 }
7900 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7901 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007902 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007903 vkDestroyImageView(m_device->device(), image_view, NULL);
7904 vkDestroyBuffer(m_device->device(), buffer, NULL);
7905 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7906 vkFreeDescriptorSets(m_device->device(), ds_pool,
7907 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7908 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7909}
7910
Karl Schultz6addd812016-02-02 17:17:23 -07007911TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007912 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07007913 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007914
Karl Schultz6addd812016-02-02 17:17:23 -07007915 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7917 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
7918 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007919
Tobin Ehlis3b780662015-05-28 12:11:26 -06007920 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007921 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007922 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007923 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7924 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007925
7926 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7928 ds_pool_ci.pNext = NULL;
7929 ds_pool_ci.maxSets = 1;
7930 ds_pool_ci.poolSizeCount = 1;
7931 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007932
Tobin Ehlis3b780662015-05-28 12:11:26 -06007933 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007934 err =
7935 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007936 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007937 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007938 dsl_binding.binding = 0;
7939 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7940 dsl_binding.descriptorCount = 1;
7941 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7942 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007943
Tony Barboureb254902015-07-15 12:50:33 -06007944 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007945 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7946 ds_layout_ci.pNext = NULL;
7947 ds_layout_ci.bindingCount = 1;
7948 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007949
Tobin Ehlis3b780662015-05-28 12:11:26 -06007950 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007951 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7952 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007953 ASSERT_VK_SUCCESS(err);
7954
7955 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007956 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007957 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007958 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007959 alloc_info.descriptorPool = ds_pool;
7960 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007961 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7962 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007963 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007964
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007965 VkSamplerCreateInfo sampler_ci = {};
7966 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7967 sampler_ci.pNext = NULL;
7968 sampler_ci.magFilter = VK_FILTER_NEAREST;
7969 sampler_ci.minFilter = VK_FILTER_NEAREST;
7970 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7971 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7972 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7973 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7974 sampler_ci.mipLodBias = 1.0;
7975 sampler_ci.anisotropyEnable = VK_FALSE;
7976 sampler_ci.maxAnisotropy = 1;
7977 sampler_ci.compareEnable = VK_FALSE;
7978 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7979 sampler_ci.minLod = 1.0;
7980 sampler_ci.maxLod = 1.0;
7981 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7982 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7983 VkSampler sampler;
7984 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7985 ASSERT_VK_SUCCESS(err);
7986
7987 VkDescriptorImageInfo info = {};
7988 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007989
7990 VkWriteDescriptorSet descriptor_write;
7991 memset(&descriptor_write, 0, sizeof(descriptor_write));
7992 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007993 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007994 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007995 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007996 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007997 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007998
7999 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008001 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008002
Chia-I Wuf7458c52015-10-26 21:10:41 +08008003 vkDestroySampler(m_device->device(), sampler, NULL);
8004 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8005 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008006}
8007
Karl Schultz6addd812016-02-02 17:17:23 -07008008TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008009 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008010 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008011
Karl Schultz6addd812016-02-02 17:17:23 -07008012 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008013 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8014 " binding #0 with 1 total descriptors but update of 1 descriptors "
8015 "starting at binding offset of 0 combined with update array element "
8016 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008017
Tobin Ehlis3b780662015-05-28 12:11:26 -06008018 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008019 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008020 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008021 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8022 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008023
8024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8026 ds_pool_ci.pNext = NULL;
8027 ds_pool_ci.maxSets = 1;
8028 ds_pool_ci.poolSizeCount = 1;
8029 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008030
Tobin Ehlis3b780662015-05-28 12:11:26 -06008031 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008032 err =
8033 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008034 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008035
Tony Barboureb254902015-07-15 12:50:33 -06008036 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 dsl_binding.binding = 0;
8038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8039 dsl_binding.descriptorCount = 1;
8040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8041 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008042
8043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8045 ds_layout_ci.pNext = NULL;
8046 ds_layout_ci.bindingCount = 1;
8047 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008048
Tobin Ehlis3b780662015-05-28 12:11:26 -06008049 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8051 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008052 ASSERT_VK_SUCCESS(err);
8053
8054 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008055 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008056 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008057 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008058 alloc_info.descriptorPool = ds_pool;
8059 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008060 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8061 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008062 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008063
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008064 // Correctly update descriptor to avoid "NOT_UPDATED" error
8065 VkDescriptorBufferInfo buff_info = {};
8066 buff_info.buffer =
8067 VkBuffer(0); // Don't care about buffer handle for this test
8068 buff_info.offset = 0;
8069 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008070
8071 VkWriteDescriptorSet descriptor_write;
8072 memset(&descriptor_write, 0, sizeof(descriptor_write));
8073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008074 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008075 descriptor_write.dstArrayElement =
8076 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008077 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8079 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008080
8081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8082
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008083 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008084
Chia-I Wuf7458c52015-10-26 21:10:41 +08008085 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8086 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008087}
8088
Karl Schultz6addd812016-02-02 17:17:23 -07008089TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8090 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8091 // index 2
8092 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008093
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8095 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008096
Tobin Ehlis3b780662015-05-28 12:11:26 -06008097 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008098 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008099 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008100 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8101 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008102
8103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8105 ds_pool_ci.pNext = NULL;
8106 ds_pool_ci.maxSets = 1;
8107 ds_pool_ci.poolSizeCount = 1;
8108 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008109
Tobin Ehlis3b780662015-05-28 12:11:26 -06008110 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008111 err =
8112 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008113 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008114
Tony Barboureb254902015-07-15 12:50:33 -06008115 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008116 dsl_binding.binding = 0;
8117 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8118 dsl_binding.descriptorCount = 1;
8119 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8120 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008121
8122 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008123 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8124 ds_layout_ci.pNext = NULL;
8125 ds_layout_ci.bindingCount = 1;
8126 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008127 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8129 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008130 ASSERT_VK_SUCCESS(err);
8131
8132 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008135 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008136 alloc_info.descriptorPool = ds_pool;
8137 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8139 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008140 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008141
Tony Barboureb254902015-07-15 12:50:33 -06008142 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008143 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8144 sampler_ci.pNext = NULL;
8145 sampler_ci.magFilter = VK_FILTER_NEAREST;
8146 sampler_ci.minFilter = VK_FILTER_NEAREST;
8147 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8148 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8149 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8150 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8151 sampler_ci.mipLodBias = 1.0;
8152 sampler_ci.anisotropyEnable = VK_FALSE;
8153 sampler_ci.maxAnisotropy = 1;
8154 sampler_ci.compareEnable = VK_FALSE;
8155 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8156 sampler_ci.minLod = 1.0;
8157 sampler_ci.maxLod = 1.0;
8158 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8159 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008160
Tobin Ehlis3b780662015-05-28 12:11:26 -06008161 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008162 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008163 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008164
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008165 VkDescriptorImageInfo info = {};
8166 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008167
8168 VkWriteDescriptorSet descriptor_write;
8169 memset(&descriptor_write, 0, sizeof(descriptor_write));
8170 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008171 descriptor_write.dstSet = descriptorSet;
8172 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008173 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008174 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008175 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008176 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008177
8178 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8179
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008180 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008181
Chia-I Wuf7458c52015-10-26 21:10:41 +08008182 vkDestroySampler(m_device->device(), sampler, NULL);
8183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8184 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008185}
8186
Karl Schultz6addd812016-02-02 17:17:23 -07008187TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8188 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8189 // types
8190 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008191
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008193 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008194
Tobin Ehlis3b780662015-05-28 12:11:26 -06008195 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008196
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008197 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008198 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8199 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008200
8201 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008202 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8203 ds_pool_ci.pNext = NULL;
8204 ds_pool_ci.maxSets = 1;
8205 ds_pool_ci.poolSizeCount = 1;
8206 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008207
Tobin Ehlis3b780662015-05-28 12:11:26 -06008208 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008209 err =
8210 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008211 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008212 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008213 dsl_binding.binding = 0;
8214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8215 dsl_binding.descriptorCount = 1;
8216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8217 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008218
Tony Barboureb254902015-07-15 12:50:33 -06008219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8221 ds_layout_ci.pNext = NULL;
8222 ds_layout_ci.bindingCount = 1;
8223 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008224
Tobin Ehlis3b780662015-05-28 12:11:26 -06008225 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8227 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008228 ASSERT_VK_SUCCESS(err);
8229
8230 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008231 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008232 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008233 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008234 alloc_info.descriptorPool = ds_pool;
8235 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008236 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8237 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008238 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008239
Tony Barboureb254902015-07-15 12:50:33 -06008240 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008241 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8242 sampler_ci.pNext = NULL;
8243 sampler_ci.magFilter = VK_FILTER_NEAREST;
8244 sampler_ci.minFilter = VK_FILTER_NEAREST;
8245 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8246 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8247 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8248 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8249 sampler_ci.mipLodBias = 1.0;
8250 sampler_ci.anisotropyEnable = VK_FALSE;
8251 sampler_ci.maxAnisotropy = 1;
8252 sampler_ci.compareEnable = VK_FALSE;
8253 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8254 sampler_ci.minLod = 1.0;
8255 sampler_ci.maxLod = 1.0;
8256 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8257 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008258 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008259 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008260 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008261
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008262 VkDescriptorImageInfo info = {};
8263 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008264
8265 VkWriteDescriptorSet descriptor_write;
8266 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008267 descriptor_write.sType =
8268 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008269 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008270 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008271 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008272 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008273 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008274
8275 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008278
Chia-I Wuf7458c52015-10-26 21:10:41 +08008279 vkDestroySampler(m_device->device(), sampler, NULL);
8280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008282}
8283
Karl Schultz6addd812016-02-02 17:17:23 -07008284TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008285 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008286 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008287
Karl Schultz6addd812016-02-02 17:17:23 -07008288 m_errorMonitor->SetDesiredFailureMsg(
8289 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008290 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008291
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008292 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008293 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8294 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008295 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008296 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8297 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008298
8299 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008300 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8301 ds_pool_ci.pNext = NULL;
8302 ds_pool_ci.maxSets = 1;
8303 ds_pool_ci.poolSizeCount = 1;
8304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008305
8306 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008307 err =
8308 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008309 ASSERT_VK_SUCCESS(err);
8310
8311 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008312 dsl_binding.binding = 0;
8313 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8314 dsl_binding.descriptorCount = 1;
8315 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8316 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008317
8318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8320 ds_layout_ci.pNext = NULL;
8321 ds_layout_ci.bindingCount = 1;
8322 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008323 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8325 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008326 ASSERT_VK_SUCCESS(err);
8327
8328 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008329 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008330 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008331 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008332 alloc_info.descriptorPool = ds_pool;
8333 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008334 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8335 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008336 ASSERT_VK_SUCCESS(err);
8337
Karl Schultz6addd812016-02-02 17:17:23 -07008338 VkSampler sampler =
8339 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008340
8341 VkDescriptorImageInfo descriptor_info;
8342 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8343 descriptor_info.sampler = sampler;
8344
8345 VkWriteDescriptorSet descriptor_write;
8346 memset(&descriptor_write, 0, sizeof(descriptor_write));
8347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008348 descriptor_write.dstSet = descriptorSet;
8349 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008350 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008351 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8352 descriptor_write.pImageInfo = &descriptor_info;
8353
8354 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008356 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008357
Chia-I Wuf7458c52015-10-26 21:10:41 +08008358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008360}
8361
Karl Schultz6addd812016-02-02 17:17:23 -07008362TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8363 // Create a single combined Image/Sampler descriptor and send it an invalid
8364 // imageView
8365 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008366
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8368 "Attempted write update to combined "
8369 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008370 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008371
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008372 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008373 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008374 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8375 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008376
8377 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008378 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8379 ds_pool_ci.pNext = NULL;
8380 ds_pool_ci.maxSets = 1;
8381 ds_pool_ci.poolSizeCount = 1;
8382 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008383
8384 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008385 err =
8386 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008387 ASSERT_VK_SUCCESS(err);
8388
8389 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008390 dsl_binding.binding = 0;
8391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8392 dsl_binding.descriptorCount = 1;
8393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8394 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008395
8396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8398 ds_layout_ci.pNext = NULL;
8399 ds_layout_ci.bindingCount = 1;
8400 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008401 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8403 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008404 ASSERT_VK_SUCCESS(err);
8405
8406 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008407 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008409 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008410 alloc_info.descriptorPool = ds_pool;
8411 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8413 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008414 ASSERT_VK_SUCCESS(err);
8415
8416 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008417 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8418 sampler_ci.pNext = NULL;
8419 sampler_ci.magFilter = VK_FILTER_NEAREST;
8420 sampler_ci.minFilter = VK_FILTER_NEAREST;
8421 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8422 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8423 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8424 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8425 sampler_ci.mipLodBias = 1.0;
8426 sampler_ci.anisotropyEnable = VK_FALSE;
8427 sampler_ci.maxAnisotropy = 1;
8428 sampler_ci.compareEnable = VK_FALSE;
8429 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8430 sampler_ci.minLod = 1.0;
8431 sampler_ci.maxLod = 1.0;
8432 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8433 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008434
8435 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008436 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008437 ASSERT_VK_SUCCESS(err);
8438
Karl Schultz6addd812016-02-02 17:17:23 -07008439 VkImageView view =
8440 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008441
8442 VkDescriptorImageInfo descriptor_info;
8443 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8444 descriptor_info.sampler = sampler;
8445 descriptor_info.imageView = view;
8446
8447 VkWriteDescriptorSet descriptor_write;
8448 memset(&descriptor_write, 0, sizeof(descriptor_write));
8449 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008450 descriptor_write.dstSet = descriptorSet;
8451 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008452 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008453 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8454 descriptor_write.pImageInfo = &descriptor_info;
8455
8456 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008458 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008459
Chia-I Wuf7458c52015-10-26 21:10:41 +08008460 vkDestroySampler(m_device->device(), sampler, NULL);
8461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008463}
8464
Karl Schultz6addd812016-02-02 17:17:23 -07008465TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8466 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8467 // into the other
8468 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008469
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8471 " binding #1 with type "
8472 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8473 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008474
Tobin Ehlis04356f92015-10-27 16:35:27 -06008475 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008476 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008477 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008478 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8479 ds_type_count[0].descriptorCount = 1;
8480 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8481 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008482
8483 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008484 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8485 ds_pool_ci.pNext = NULL;
8486 ds_pool_ci.maxSets = 1;
8487 ds_pool_ci.poolSizeCount = 2;
8488 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008489
8490 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008491 err =
8492 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008493 ASSERT_VK_SUCCESS(err);
8494 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008495 dsl_binding[0].binding = 0;
8496 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8497 dsl_binding[0].descriptorCount = 1;
8498 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8499 dsl_binding[0].pImmutableSamplers = NULL;
8500 dsl_binding[1].binding = 1;
8501 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8502 dsl_binding[1].descriptorCount = 1;
8503 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8504 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008505
8506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8508 ds_layout_ci.pNext = NULL;
8509 ds_layout_ci.bindingCount = 2;
8510 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008511
8512 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008513 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8514 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008515 ASSERT_VK_SUCCESS(err);
8516
8517 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008518 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008519 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008520 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008521 alloc_info.descriptorPool = ds_pool;
8522 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008523 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8524 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008525 ASSERT_VK_SUCCESS(err);
8526
8527 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008528 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8529 sampler_ci.pNext = NULL;
8530 sampler_ci.magFilter = VK_FILTER_NEAREST;
8531 sampler_ci.minFilter = VK_FILTER_NEAREST;
8532 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8533 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8534 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8535 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8536 sampler_ci.mipLodBias = 1.0;
8537 sampler_ci.anisotropyEnable = VK_FALSE;
8538 sampler_ci.maxAnisotropy = 1;
8539 sampler_ci.compareEnable = VK_FALSE;
8540 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8541 sampler_ci.minLod = 1.0;
8542 sampler_ci.maxLod = 1.0;
8543 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8544 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008545
8546 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008547 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008548 ASSERT_VK_SUCCESS(err);
8549
8550 VkDescriptorImageInfo info = {};
8551 info.sampler = sampler;
8552
8553 VkWriteDescriptorSet descriptor_write;
8554 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8555 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008556 descriptor_write.dstSet = descriptorSet;
8557 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008558 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008559 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8560 descriptor_write.pImageInfo = &info;
8561 // This write update should succeed
8562 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8563 // Now perform a copy update that fails due to type mismatch
8564 VkCopyDescriptorSet copy_ds_update;
8565 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8566 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8567 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008568 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008569 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008570 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008571 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008572 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8573
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008574 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008575 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008576 m_errorMonitor->SetDesiredFailureMsg(
8577 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008578 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008579 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8580 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8581 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008582 copy_ds_update.srcBinding =
8583 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008584 copy_ds_update.dstSet = descriptorSet;
8585 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008586 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008587 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8588
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008589 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008590
Tobin Ehlis04356f92015-10-27 16:35:27 -06008591 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008592 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008593 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8594 "update array offset of 0 and update of "
8595 "5 descriptors oversteps total number "
8596 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008597
Tobin Ehlis04356f92015-10-27 16:35:27 -06008598 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8599 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8600 copy_ds_update.srcSet = descriptorSet;
8601 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008602 copy_ds_update.dstSet = descriptorSet;
8603 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008604 copy_ds_update.descriptorCount =
8605 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008606 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8607
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008608 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008609
Chia-I Wuf7458c52015-10-26 21:10:41 +08008610 vkDestroySampler(m_device->device(), sampler, NULL);
8611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8612 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008613}
8614
Karl Schultz6addd812016-02-02 17:17:23 -07008615TEST_F(VkLayerTest, NumSamplesMismatch) {
8616 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8617 // sampleCount
8618 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008619
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008621 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008622
Tobin Ehlis3b780662015-05-28 12:11:26 -06008623 ASSERT_NO_FATAL_FAILURE(InitState());
8624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008625 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008626 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008627 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008628
8629 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008630 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8631 ds_pool_ci.pNext = NULL;
8632 ds_pool_ci.maxSets = 1;
8633 ds_pool_ci.poolSizeCount = 1;
8634 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008635
Tobin Ehlis3b780662015-05-28 12:11:26 -06008636 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008637 err =
8638 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008639 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008640
Tony Barboureb254902015-07-15 12:50:33 -06008641 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008642 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008643 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008644 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008645 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8646 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008647
Tony Barboureb254902015-07-15 12:50:33 -06008648 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8649 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8650 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008651 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008652 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008653
Tobin Ehlis3b780662015-05-28 12:11:26 -06008654 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8656 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008657 ASSERT_VK_SUCCESS(err);
8658
8659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008662 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008663 alloc_info.descriptorPool = ds_pool;
8664 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8666 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008667 ASSERT_VK_SUCCESS(err);
8668
Tony Barboureb254902015-07-15 12:50:33 -06008669 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008670 pipe_ms_state_ci.sType =
8671 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8672 pipe_ms_state_ci.pNext = NULL;
8673 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8674 pipe_ms_state_ci.sampleShadingEnable = 0;
8675 pipe_ms_state_ci.minSampleShading = 1.0;
8676 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008677
Tony Barboureb254902015-07-15 12:50:33 -06008678 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008679 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8680 pipeline_layout_ci.pNext = NULL;
8681 pipeline_layout_ci.setLayoutCount = 1;
8682 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008683
8684 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008685 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8686 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008687 ASSERT_VK_SUCCESS(err);
8688
Karl Schultz6addd812016-02-02 17:17:23 -07008689 VkShaderObj vs(m_device, bindStateVertShaderText,
8690 VK_SHADER_STAGE_VERTEX_BIT, this);
8691 VkShaderObj fs(m_device, bindStateFragShaderText,
8692 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008693 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008694 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008695 VkPipelineObj pipe(m_device);
8696 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008697 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008698 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008699 pipe.SetMSAA(&pipe_ms_state_ci);
8700 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008701
Tony Barbourfe3351b2015-07-28 10:17:20 -06008702 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008703 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8704 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008705
Mark Young29927482016-05-04 14:38:51 -06008706 // Render triangle (the error should trigger on the attempt to draw).
8707 Draw(3, 1, 0, 0);
8708
8709 // Finalize recording of the command buffer
8710 EndCommandBuffer();
8711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008713
Chia-I Wuf7458c52015-10-26 21:10:41 +08008714 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8715 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8716 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008717}
Mark Young29927482016-05-04 14:38:51 -06008718
Mark Youngc89c6312016-03-31 16:03:20 -06008719TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8720 // Create Pipeline where the number of blend attachments doesn't match the
8721 // number of color attachments. In this case, we don't add any color
8722 // blend attachments even though we have a color attachment.
8723 VkResult err;
8724
8725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008726 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008727
8728 ASSERT_NO_FATAL_FAILURE(InitState());
8729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8730 VkDescriptorPoolSize ds_type_count = {};
8731 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8732 ds_type_count.descriptorCount = 1;
8733
8734 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8735 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8736 ds_pool_ci.pNext = NULL;
8737 ds_pool_ci.maxSets = 1;
8738 ds_pool_ci.poolSizeCount = 1;
8739 ds_pool_ci.pPoolSizes = &ds_type_count;
8740
8741 VkDescriptorPool ds_pool;
8742 err =
8743 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8744 ASSERT_VK_SUCCESS(err);
8745
8746 VkDescriptorSetLayoutBinding dsl_binding = {};
8747 dsl_binding.binding = 0;
8748 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8749 dsl_binding.descriptorCount = 1;
8750 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8751 dsl_binding.pImmutableSamplers = NULL;
8752
8753 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8754 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8755 ds_layout_ci.pNext = NULL;
8756 ds_layout_ci.bindingCount = 1;
8757 ds_layout_ci.pBindings = &dsl_binding;
8758
8759 VkDescriptorSetLayout ds_layout;
8760 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8761 &ds_layout);
8762 ASSERT_VK_SUCCESS(err);
8763
8764 VkDescriptorSet descriptorSet;
8765 VkDescriptorSetAllocateInfo alloc_info = {};
8766 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8767 alloc_info.descriptorSetCount = 1;
8768 alloc_info.descriptorPool = ds_pool;
8769 alloc_info.pSetLayouts = &ds_layout;
8770 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8771 &descriptorSet);
8772 ASSERT_VK_SUCCESS(err);
8773
8774 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8775 pipe_ms_state_ci.sType =
8776 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8777 pipe_ms_state_ci.pNext = NULL;
8778 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8779 pipe_ms_state_ci.sampleShadingEnable = 0;
8780 pipe_ms_state_ci.minSampleShading = 1.0;
8781 pipe_ms_state_ci.pSampleMask = NULL;
8782
8783 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8784 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8785 pipeline_layout_ci.pNext = NULL;
8786 pipeline_layout_ci.setLayoutCount = 1;
8787 pipeline_layout_ci.pSetLayouts = &ds_layout;
8788
8789 VkPipelineLayout pipeline_layout;
8790 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8791 &pipeline_layout);
8792 ASSERT_VK_SUCCESS(err);
8793
8794 VkShaderObj vs(m_device, bindStateVertShaderText,
8795 VK_SHADER_STAGE_VERTEX_BIT, this);
8796 VkShaderObj fs(m_device, bindStateFragShaderText,
8797 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008798 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06008799 // but add it to be able to run on more devices
8800 VkPipelineObj pipe(m_device);
8801 pipe.AddShader(&vs);
8802 pipe.AddShader(&fs);
8803 pipe.SetMSAA(&pipe_ms_state_ci);
8804 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8805
8806 BeginCommandBuffer();
8807 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8808 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8809
Mark Young29927482016-05-04 14:38:51 -06008810 // Render triangle (the error should trigger on the attempt to draw).
8811 Draw(3, 1, 0, 0);
8812
8813 // Finalize recording of the command buffer
8814 EndCommandBuffer();
8815
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008816 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06008817
8818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8821}
Mark Young29927482016-05-04 14:38:51 -06008822
Mark Muellerd4914412016-06-13 17:52:06 -06008823TEST_F(VkLayerTest, MissingClearAttachment) {
8824 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
8825 "structure passed to vkCmdClearAttachments");
8826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8827 "vkCmdClearAttachments() attachment index 1 not found in attachment "
8828 "reference array of active subpass 0");
8829
8830 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
8831 m_errorMonitor->VerifyFound();
8832}
8833
Karl Schultz6addd812016-02-02 17:17:23 -07008834TEST_F(VkLayerTest, ClearCmdNoDraw) {
8835 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
8836 // to issuing a Draw
8837 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008838
Karl Schultz6addd812016-02-02 17:17:23 -07008839 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07008840 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008841 "vkCmdClearAttachments() issued on CB object ");
8842
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008843 ASSERT_NO_FATAL_FAILURE(InitState());
8844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008845
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008846 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8848 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008849
8850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8852 ds_pool_ci.pNext = NULL;
8853 ds_pool_ci.maxSets = 1;
8854 ds_pool_ci.poolSizeCount = 1;
8855 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008856
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008857 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008858 err =
8859 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008860 ASSERT_VK_SUCCESS(err);
8861
Tony Barboureb254902015-07-15 12:50:33 -06008862 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008863 dsl_binding.binding = 0;
8864 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8865 dsl_binding.descriptorCount = 1;
8866 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8867 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008868
Tony Barboureb254902015-07-15 12:50:33 -06008869 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008870 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8871 ds_layout_ci.pNext = NULL;
8872 ds_layout_ci.bindingCount = 1;
8873 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008874
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008875 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8877 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008878 ASSERT_VK_SUCCESS(err);
8879
8880 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008881 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008883 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008884 alloc_info.descriptorPool = ds_pool;
8885 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8887 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008888 ASSERT_VK_SUCCESS(err);
8889
Tony Barboureb254902015-07-15 12:50:33 -06008890 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008891 pipe_ms_state_ci.sType =
8892 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8893 pipe_ms_state_ci.pNext = NULL;
8894 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8895 pipe_ms_state_ci.sampleShadingEnable = 0;
8896 pipe_ms_state_ci.minSampleShading = 1.0;
8897 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008898
Tony Barboureb254902015-07-15 12:50:33 -06008899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8901 pipeline_layout_ci.pNext = NULL;
8902 pipeline_layout_ci.setLayoutCount = 1;
8903 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008904
8905 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8907 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008908 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008909
Karl Schultz6addd812016-02-02 17:17:23 -07008910 VkShaderObj vs(m_device, bindStateVertShaderText,
8911 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06008912 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07008913 // on more devices
8914 VkShaderObj fs(m_device, bindStateFragShaderText,
8915 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008916
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008917 VkPipelineObj pipe(m_device);
8918 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008919 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008920 pipe.SetMSAA(&pipe_ms_state_ci);
8921 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008922
8923 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008924
Karl Schultz6addd812016-02-02 17:17:23 -07008925 // Main thing we care about for this test is that the VkImage obj we're
8926 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008927 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008928 VkClearAttachment color_attachment;
8929 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8930 color_attachment.clearValue.color.float32[0] = 1.0;
8931 color_attachment.clearValue.color.float32[1] = 1.0;
8932 color_attachment.clearValue.color.float32[2] = 1.0;
8933 color_attachment.clearValue.color.float32[3] = 1.0;
8934 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008935 VkClearRect clear_rect = {
8936 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008937
Karl Schultz6addd812016-02-02 17:17:23 -07008938 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8939 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008940
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008941 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008942
Chia-I Wuf7458c52015-10-26 21:10:41 +08008943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008946}
8947
Karl Schultz6addd812016-02-02 17:17:23 -07008948TEST_F(VkLayerTest, VtxBufferBadIndex) {
8949 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008950
Karl Schultz6addd812016-02-02 17:17:23 -07008951 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008952 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008953 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008954
Tobin Ehlis502480b2015-06-24 15:53:07 -06008955 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008956 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008958
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008959 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008960 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8961 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008962
8963 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008964 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8965 ds_pool_ci.pNext = NULL;
8966 ds_pool_ci.maxSets = 1;
8967 ds_pool_ci.poolSizeCount = 1;
8968 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008969
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008970 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008971 err =
8972 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008973 ASSERT_VK_SUCCESS(err);
8974
Tony Barboureb254902015-07-15 12:50:33 -06008975 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008976 dsl_binding.binding = 0;
8977 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8978 dsl_binding.descriptorCount = 1;
8979 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8980 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008981
Tony Barboureb254902015-07-15 12:50:33 -06008982 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008983 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8984 ds_layout_ci.pNext = NULL;
8985 ds_layout_ci.bindingCount = 1;
8986 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008987
Tobin Ehlis502480b2015-06-24 15:53:07 -06008988 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008989 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8990 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008991 ASSERT_VK_SUCCESS(err);
8992
8993 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008994 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008995 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008996 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008997 alloc_info.descriptorPool = ds_pool;
8998 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008999 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9000 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009001 ASSERT_VK_SUCCESS(err);
9002
Tony Barboureb254902015-07-15 12:50:33 -06009003 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009004 pipe_ms_state_ci.sType =
9005 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9006 pipe_ms_state_ci.pNext = NULL;
9007 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9008 pipe_ms_state_ci.sampleShadingEnable = 0;
9009 pipe_ms_state_ci.minSampleShading = 1.0;
9010 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009011
Tony Barboureb254902015-07-15 12:50:33 -06009012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9014 pipeline_layout_ci.pNext = NULL;
9015 pipeline_layout_ci.setLayoutCount = 1;
9016 pipeline_layout_ci.pSetLayouts = &ds_layout;
9017 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009018
Karl Schultz6addd812016-02-02 17:17:23 -07009019 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9020 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009021 ASSERT_VK_SUCCESS(err);
9022
Karl Schultz6addd812016-02-02 17:17:23 -07009023 VkShaderObj vs(m_device, bindStateVertShaderText,
9024 VK_SHADER_STAGE_VERTEX_BIT, this);
9025 VkShaderObj fs(m_device, bindStateFragShaderText,
9026 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009027 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009028 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009029 VkPipelineObj pipe(m_device);
9030 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009031 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009032 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009033 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009034 pipe.SetViewport(m_viewports);
9035 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009036 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009037
9038 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009039 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9040 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009041 // Don't care about actual data, just need to get to draw to flag error
9042 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009043 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9044 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009045 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009046 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009047
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009048 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009049
Chia-I Wuf7458c52015-10-26 21:10:41 +08009050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009053}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009054// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9055TEST_F(VkLayerTest, InvalidImageLayout) {
9056 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9057 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9058 "images in the wrong layout when they're copied or transitioned.");
9059 // 3 in ValidateCmdBufImageLayouts
9060 // * -1 Attempt to submit cmd buf w/ deleted image
9061 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9062 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9063 m_errorMonitor->SetDesiredFailureMsg(
9064 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9065 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9066
9067 ASSERT_NO_FATAL_FAILURE(InitState());
9068 // Create src & dst images to use for copy operations
9069 VkImage src_image;
9070 VkImage dst_image;
9071
9072 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9073 const int32_t tex_width = 32;
9074 const int32_t tex_height = 32;
9075
9076 VkImageCreateInfo image_create_info = {};
9077 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9078 image_create_info.pNext = NULL;
9079 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9080 image_create_info.format = tex_format;
9081 image_create_info.extent.width = tex_width;
9082 image_create_info.extent.height = tex_height;
9083 image_create_info.extent.depth = 1;
9084 image_create_info.mipLevels = 1;
9085 image_create_info.arrayLayers = 4;
9086 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9087 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9088 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9089 image_create_info.flags = 0;
9090
9091 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9092 ASSERT_VK_SUCCESS(err);
9093 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9094 ASSERT_VK_SUCCESS(err);
9095
9096 BeginCommandBuffer();
9097 VkImageCopy copyRegion;
9098 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9099 copyRegion.srcSubresource.mipLevel = 0;
9100 copyRegion.srcSubresource.baseArrayLayer = 0;
9101 copyRegion.srcSubresource.layerCount = 1;
9102 copyRegion.srcOffset.x = 0;
9103 copyRegion.srcOffset.y = 0;
9104 copyRegion.srcOffset.z = 0;
9105 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9106 copyRegion.dstSubresource.mipLevel = 0;
9107 copyRegion.dstSubresource.baseArrayLayer = 0;
9108 copyRegion.dstSubresource.layerCount = 1;
9109 copyRegion.dstOffset.x = 0;
9110 copyRegion.dstOffset.y = 0;
9111 copyRegion.dstOffset.z = 0;
9112 copyRegion.extent.width = 1;
9113 copyRegion.extent.height = 1;
9114 copyRegion.extent.depth = 1;
9115 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9116 m_errorMonitor->VerifyFound();
9117 // Now cause error due to src image layout changing
9118 m_errorMonitor->SetDesiredFailureMsg(
9119 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9120 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9121 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9122 m_errorMonitor->VerifyFound();
9123 // Final src error is due to bad layout type
9124 m_errorMonitor->SetDesiredFailureMsg(
9125 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9126 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9127 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9128 m_errorMonitor->VerifyFound();
9129 // Now verify same checks for dst
9130 m_errorMonitor->SetDesiredFailureMsg(
9131 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9132 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9133 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9134 m_errorMonitor->VerifyFound();
9135 // Now cause error due to src image layout changing
9136 m_errorMonitor->SetDesiredFailureMsg(
9137 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9138 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9139 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9140 m_errorMonitor->VerifyFound();
9141 m_errorMonitor->SetDesiredFailureMsg(
9142 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9143 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9144 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9145 m_errorMonitor->VerifyFound();
9146 // Now cause error due to bad image layout transition in PipelineBarrier
9147 VkImageMemoryBarrier image_barrier[1] = {};
9148 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9149 image_barrier[0].image = src_image;
9150 image_barrier[0].subresourceRange.layerCount = 2;
9151 image_barrier[0].subresourceRange.levelCount = 2;
9152 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9153 m_errorMonitor->SetDesiredFailureMsg(
9154 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9155 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9156 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9157 m_errorMonitor->VerifyFound();
9158
9159 // Finally some layout errors at RenderPass create time
9160 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9161 VkAttachmentReference attach = {};
9162 // perf warning for GENERAL layout w/ non-DS input attachment
9163 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9164 VkSubpassDescription subpass = {};
9165 subpass.inputAttachmentCount = 1;
9166 subpass.pInputAttachments = &attach;
9167 VkRenderPassCreateInfo rpci = {};
9168 rpci.subpassCount = 1;
9169 rpci.pSubpasses = &subpass;
9170 rpci.attachmentCount = 1;
9171 VkAttachmentDescription attach_desc = {};
9172 attach_desc.format = VK_FORMAT_UNDEFINED;
9173 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009174 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009175 VkRenderPass rp;
9176 m_errorMonitor->SetDesiredFailureMsg(
9177 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9178 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9179 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9180 m_errorMonitor->VerifyFound();
9181 // error w/ non-general layout
9182 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9183
9184 m_errorMonitor->SetDesiredFailureMsg(
9185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9186 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9187 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9188 m_errorMonitor->VerifyFound();
9189 subpass.inputAttachmentCount = 0;
9190 subpass.colorAttachmentCount = 1;
9191 subpass.pColorAttachments = &attach;
9192 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9193 // perf warning for GENERAL layout on color attachment
9194 m_errorMonitor->SetDesiredFailureMsg(
9195 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9196 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9197 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9198 m_errorMonitor->VerifyFound();
9199 // error w/ non-color opt or GENERAL layout for color attachment
9200 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9201 m_errorMonitor->SetDesiredFailureMsg(
9202 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9203 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9204 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9205 m_errorMonitor->VerifyFound();
9206 subpass.colorAttachmentCount = 0;
9207 subpass.pDepthStencilAttachment = &attach;
9208 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9209 // perf warning for GENERAL layout on DS attachment
9210 m_errorMonitor->SetDesiredFailureMsg(
9211 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9212 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9213 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9214 m_errorMonitor->VerifyFound();
9215 // error w/ non-ds opt or GENERAL layout for color attachment
9216 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9217 m_errorMonitor->SetDesiredFailureMsg(
9218 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9219 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9220 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9221 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009222 // For this error we need a valid renderpass so create default one
9223 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9224 attach.attachment = 0;
9225 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9226 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9227 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9228 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9229 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9230 // Can't do a CLEAR load on READ_ONLY initialLayout
9231 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9232 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9233 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9235 " with invalid first layout "
9236 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9237 "ONLY_OPTIMAL");
9238 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9239 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009240
9241 vkDestroyImage(m_device->device(), src_image, NULL);
9242 vkDestroyImage(m_device->device(), dst_image, NULL);
9243}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009244#endif // DRAW_STATE_TESTS
9245
Tobin Ehlis0788f522015-05-26 16:11:58 -06009246#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009247#if GTEST_IS_THREADSAFE
9248struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009249 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009250 VkEvent event;
9251 bool bailout;
9252};
9253
Karl Schultz6addd812016-02-02 17:17:23 -07009254extern "C" void *AddToCommandBuffer(void *arg) {
9255 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009256
Karl Schultz6addd812016-02-02 17:17:23 -07009257 for (int i = 0; i < 10000; i++) {
9258 vkCmdSetEvent(data->commandBuffer, data->event,
9259 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009260 if (data->bailout) {
9261 break;
9262 }
9263 }
9264 return NULL;
9265}
9266
Karl Schultz6addd812016-02-02 17:17:23 -07009267TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009268 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009269
Karl Schultz6addd812016-02-02 17:17:23 -07009270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9271 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009272
Mike Stroyanaccf7692015-05-12 16:00:45 -06009273 ASSERT_NO_FATAL_FAILURE(InitState());
9274 ASSERT_NO_FATAL_FAILURE(InitViewport());
9275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9276
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009277 // Calls AllocateCommandBuffers
9278 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009279
9280 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009281 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009282
9283 VkEventCreateInfo event_info;
9284 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009285 VkResult err;
9286
9287 memset(&event_info, 0, sizeof(event_info));
9288 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9289
Chia-I Wuf7458c52015-10-26 21:10:41 +08009290 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009291 ASSERT_VK_SUCCESS(err);
9292
Mike Stroyanaccf7692015-05-12 16:00:45 -06009293 err = vkResetEvent(device(), event);
9294 ASSERT_VK_SUCCESS(err);
9295
9296 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009297 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009298 data.event = event;
9299 data.bailout = false;
9300 m_errorMonitor->SetBailout(&data.bailout);
9301 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009302 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009303 // Add many entries to command buffer from this thread at the same time.
9304 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009305
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009306 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009307 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009308
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009309 m_errorMonitor->SetBailout(NULL);
9310
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009311 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009312
Chia-I Wuf7458c52015-10-26 21:10:41 +08009313 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009314}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009315#endif // GTEST_IS_THREADSAFE
9316#endif // THREADING_TESTS
9317
Chris Forbes9f7ff632015-05-25 11:13:08 +12009318#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009319TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009321 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009322
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009323 ASSERT_NO_FATAL_FAILURE(InitState());
9324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9325
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009326 VkShaderModule module;
9327 VkShaderModuleCreateInfo moduleCreateInfo;
9328 struct icd_spv_header spv;
9329
9330 spv.magic = ICD_SPV_MAGIC;
9331 spv.version = ICD_SPV_VERSION;
9332 spv.gen_magic = 0;
9333
9334 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9335 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009336 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009337 moduleCreateInfo.codeSize = 4;
9338 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009339 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009340
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009341 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009342}
9343
Karl Schultz6addd812016-02-02 17:17:23 -07009344TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009346 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009347
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009348 ASSERT_NO_FATAL_FAILURE(InitState());
9349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9350
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009351 VkShaderModule module;
9352 VkShaderModuleCreateInfo moduleCreateInfo;
9353 struct icd_spv_header spv;
9354
9355 spv.magic = ~ICD_SPV_MAGIC;
9356 spv.version = ICD_SPV_VERSION;
9357 spv.gen_magic = 0;
9358
9359 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9360 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009361 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009362 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9363 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009364 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009366 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009367}
9368
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009369#if 0
9370// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009371TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009373 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009374
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009375 ASSERT_NO_FATAL_FAILURE(InitState());
9376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9377
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009378 VkShaderModule module;
9379 VkShaderModuleCreateInfo moduleCreateInfo;
9380 struct icd_spv_header spv;
9381
9382 spv.magic = ICD_SPV_MAGIC;
9383 spv.version = ~ICD_SPV_VERSION;
9384 spv.gen_magic = 0;
9385
9386 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9387 moduleCreateInfo.pNext = NULL;
9388
Karl Schultz6addd812016-02-02 17:17:23 -07009389 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009390 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9391 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009392 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009393
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009394 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009395}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009396#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009397
Karl Schultz6addd812016-02-02 17:17:23 -07009398TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009400 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009401
Chris Forbes9f7ff632015-05-25 11:13:08 +12009402 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009404
9405 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009406 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009407 "\n"
9408 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009409 "out gl_PerVertex {\n"
9410 " vec4 gl_Position;\n"
9411 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009412 "void main(){\n"
9413 " gl_Position = vec4(1);\n"
9414 " x = 0;\n"
9415 "}\n";
9416 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009417 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009418 "\n"
9419 "layout(location=0) out vec4 color;\n"
9420 "void main(){\n"
9421 " color = vec4(1);\n"
9422 "}\n";
9423
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009426
9427 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009428 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009429 pipe.AddShader(&vs);
9430 pipe.AddShader(&fs);
9431
Chris Forbes9f7ff632015-05-25 11:13:08 +12009432 VkDescriptorSetObj descriptorSet(m_device);
9433 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009434 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009435
Tony Barbour5781e8f2015-08-04 16:23:11 -06009436 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009437
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009438 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009439}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009440
Karl Schultz6addd812016-02-02 17:17:23 -07009441TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009443 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009444
Chris Forbes59cb88d2015-05-25 11:13:13 +12009445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009447
9448 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009449 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009450 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009451 "out gl_PerVertex {\n"
9452 " vec4 gl_Position;\n"
9453 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009454 "void main(){\n"
9455 " gl_Position = vec4(1);\n"
9456 "}\n";
9457 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009458 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009459 "\n"
9460 "layout(location=0) in float x;\n"
9461 "layout(location=0) out vec4 color;\n"
9462 "void main(){\n"
9463 " color = vec4(x);\n"
9464 "}\n";
9465
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009466 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9467 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009468
9469 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009470 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009471 pipe.AddShader(&vs);
9472 pipe.AddShader(&fs);
9473
Chris Forbes59cb88d2015-05-25 11:13:13 +12009474 VkDescriptorSetObj descriptorSet(m_device);
9475 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009476 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009477
Tony Barbour5781e8f2015-08-04 16:23:11 -06009478 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009479
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009480 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009481}
9482
Karl Schultz6addd812016-02-02 17:17:23 -07009483TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009485 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009486
9487 ASSERT_NO_FATAL_FAILURE(InitState());
9488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9489
9490 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009491 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009492 "\n"
9493 "out gl_PerVertex {\n"
9494 " vec4 gl_Position;\n"
9495 "};\n"
9496 "void main(){\n"
9497 " gl_Position = vec4(1);\n"
9498 "}\n";
9499 char const *fsSource =
9500 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009501 "\n"
9502 "in block { layout(location=0) float x; } ins;\n"
9503 "layout(location=0) out vec4 color;\n"
9504 "void main(){\n"
9505 " color = vec4(ins.x);\n"
9506 "}\n";
9507
9508 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9509 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9510
9511 VkPipelineObj pipe(m_device);
9512 pipe.AddColorAttachment();
9513 pipe.AddShader(&vs);
9514 pipe.AddShader(&fs);
9515
9516 VkDescriptorSetObj descriptorSet(m_device);
9517 descriptorSet.AppendDummy();
9518 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9519
9520 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9521
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009522 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009523}
9524
Karl Schultz6addd812016-02-02 17:17:23 -07009525TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009527 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009528 "output arr[2] of float32' vs 'ptr to "
9529 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009530
9531 ASSERT_NO_FATAL_FAILURE(InitState());
9532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9533
9534 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009535 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009536 "\n"
9537 "layout(location=0) out float x[2];\n"
9538 "out gl_PerVertex {\n"
9539 " vec4 gl_Position;\n"
9540 "};\n"
9541 "void main(){\n"
9542 " x[0] = 0; x[1] = 0;\n"
9543 " gl_Position = vec4(1);\n"
9544 "}\n";
9545 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009546 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009547 "\n"
9548 "layout(location=0) in float x[3];\n"
9549 "layout(location=0) out vec4 color;\n"
9550 "void main(){\n"
9551 " color = vec4(x[0] + x[1] + x[2]);\n"
9552 "}\n";
9553
9554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9556
9557 VkPipelineObj pipe(m_device);
9558 pipe.AddColorAttachment();
9559 pipe.AddShader(&vs);
9560 pipe.AddShader(&fs);
9561
9562 VkDescriptorSetObj descriptorSet(m_device);
9563 descriptorSet.AppendDummy();
9564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9565
9566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009568 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009569}
9570
Karl Schultz6addd812016-02-02 17:17:23 -07009571TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009573 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009574
Chris Forbesb56af562015-05-25 11:13:17 +12009575 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009577
9578 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009579 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009580 "\n"
9581 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009582 "out gl_PerVertex {\n"
9583 " vec4 gl_Position;\n"
9584 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009585 "void main(){\n"
9586 " x = 0;\n"
9587 " gl_Position = vec4(1);\n"
9588 "}\n";
9589 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009590 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009591 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009592 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009593 "layout(location=0) out vec4 color;\n"
9594 "void main(){\n"
9595 " color = vec4(x);\n"
9596 "}\n";
9597
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009598 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9599 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009600
9601 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009602 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009603 pipe.AddShader(&vs);
9604 pipe.AddShader(&fs);
9605
Chris Forbesb56af562015-05-25 11:13:17 +12009606 VkDescriptorSetObj descriptorSet(m_device);
9607 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009608 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009609
Tony Barbour5781e8f2015-08-04 16:23:11 -06009610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009611
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009612 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009613}
9614
Karl Schultz6addd812016-02-02 17:17:23 -07009615TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009617 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009618
9619 ASSERT_NO_FATAL_FAILURE(InitState());
9620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9621
9622 char const *vsSource =
9623 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009624 "\n"
9625 "out block { layout(location=0) int x; } outs;\n"
9626 "out gl_PerVertex {\n"
9627 " vec4 gl_Position;\n"
9628 "};\n"
9629 "void main(){\n"
9630 " outs.x = 0;\n"
9631 " gl_Position = vec4(1);\n"
9632 "}\n";
9633 char const *fsSource =
9634 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009635 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009636 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009637 "layout(location=0) out vec4 color;\n"
9638 "void main(){\n"
9639 " color = vec4(ins.x);\n"
9640 "}\n";
9641
9642 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9643 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9644
9645 VkPipelineObj pipe(m_device);
9646 pipe.AddColorAttachment();
9647 pipe.AddShader(&vs);
9648 pipe.AddShader(&fs);
9649
9650 VkDescriptorSetObj descriptorSet(m_device);
9651 descriptorSet.AppendDummy();
9652 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9653
9654 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9655
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009656 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009657}
9658
9659TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9661 "location 0.0 which is not written by vertex shader");
9662
9663 ASSERT_NO_FATAL_FAILURE(InitState());
9664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9665
9666 char const *vsSource =
9667 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009668 "\n"
9669 "out block { layout(location=1) float x; } outs;\n"
9670 "out gl_PerVertex {\n"
9671 " vec4 gl_Position;\n"
9672 "};\n"
9673 "void main(){\n"
9674 " outs.x = 0;\n"
9675 " gl_Position = vec4(1);\n"
9676 "}\n";
9677 char const *fsSource =
9678 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009679 "\n"
9680 "in block { layout(location=0) float x; } ins;\n"
9681 "layout(location=0) out vec4 color;\n"
9682 "void main(){\n"
9683 " color = vec4(ins.x);\n"
9684 "}\n";
9685
9686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9688
9689 VkPipelineObj pipe(m_device);
9690 pipe.AddColorAttachment();
9691 pipe.AddShader(&vs);
9692 pipe.AddShader(&fs);
9693
9694 VkDescriptorSetObj descriptorSet(m_device);
9695 descriptorSet.AppendDummy();
9696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9697
9698 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9699
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009700 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009701}
9702
9703TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9705 "location 0.1 which is not written by vertex shader");
9706
9707 ASSERT_NO_FATAL_FAILURE(InitState());
9708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9709
9710 char const *vsSource =
9711 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009712 "\n"
9713 "out block { layout(location=0, component=0) float x; } outs;\n"
9714 "out gl_PerVertex {\n"
9715 " vec4 gl_Position;\n"
9716 "};\n"
9717 "void main(){\n"
9718 " outs.x = 0;\n"
9719 " gl_Position = vec4(1);\n"
9720 "}\n";
9721 char const *fsSource =
9722 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009723 "\n"
9724 "in block { layout(location=0, component=1) float x; } ins;\n"
9725 "layout(location=0) out vec4 color;\n"
9726 "void main(){\n"
9727 " color = vec4(ins.x);\n"
9728 "}\n";
9729
9730 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9731 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9732
9733 VkPipelineObj pipe(m_device);
9734 pipe.AddColorAttachment();
9735 pipe.AddShader(&vs);
9736 pipe.AddShader(&fs);
9737
9738 VkDescriptorSetObj descriptorSet(m_device);
9739 descriptorSet.AppendDummy();
9740 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9741
9742 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9743
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009744 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009745}
9746
Karl Schultz6addd812016-02-02 17:17:23 -07009747TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009749 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009750
Chris Forbesde136e02015-05-25 11:13:28 +12009751 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12009753
9754 VkVertexInputBindingDescription input_binding;
9755 memset(&input_binding, 0, sizeof(input_binding));
9756
9757 VkVertexInputAttributeDescription input_attrib;
9758 memset(&input_attrib, 0, sizeof(input_attrib));
9759 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9760
9761 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009762 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009763 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009764 "out gl_PerVertex {\n"
9765 " vec4 gl_Position;\n"
9766 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009767 "void main(){\n"
9768 " gl_Position = vec4(1);\n"
9769 "}\n";
9770 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009771 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009772 "\n"
9773 "layout(location=0) out vec4 color;\n"
9774 "void main(){\n"
9775 " color = vec4(1);\n"
9776 "}\n";
9777
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9779 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12009780
9781 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009782 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12009783 pipe.AddShader(&vs);
9784 pipe.AddShader(&fs);
9785
9786 pipe.AddVertexInputBindings(&input_binding, 1);
9787 pipe.AddVertexInputAttribs(&input_attrib, 1);
9788
Chris Forbesde136e02015-05-25 11:13:28 +12009789 VkDescriptorSetObj descriptorSet(m_device);
9790 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009791 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12009792
Tony Barbour5781e8f2015-08-04 16:23:11 -06009793 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12009794
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009795 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12009796}
9797
Karl Schultz6addd812016-02-02 17:17:23 -07009798TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009800 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13009801
9802 ASSERT_NO_FATAL_FAILURE(InitState());
9803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9804
9805 VkVertexInputBindingDescription input_binding;
9806 memset(&input_binding, 0, sizeof(input_binding));
9807
9808 VkVertexInputAttributeDescription input_attrib;
9809 memset(&input_attrib, 0, sizeof(input_attrib));
9810 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9811
9812 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009813 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009814 "\n"
9815 "layout(location=1) in float x;\n"
9816 "out gl_PerVertex {\n"
9817 " vec4 gl_Position;\n"
9818 "};\n"
9819 "void main(){\n"
9820 " gl_Position = vec4(x);\n"
9821 "}\n";
9822 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009823 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009824 "\n"
9825 "layout(location=0) out vec4 color;\n"
9826 "void main(){\n"
9827 " color = vec4(1);\n"
9828 "}\n";
9829
9830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9832
9833 VkPipelineObj pipe(m_device);
9834 pipe.AddColorAttachment();
9835 pipe.AddShader(&vs);
9836 pipe.AddShader(&fs);
9837
9838 pipe.AddVertexInputBindings(&input_binding, 1);
9839 pipe.AddVertexInputAttribs(&input_attrib, 1);
9840
9841 VkDescriptorSetObj descriptorSet(m_device);
9842 descriptorSet.AppendDummy();
9843 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9844
9845 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9846
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009847 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13009848}
9849
Karl Schultz6addd812016-02-02 17:17:23 -07009850TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
9851 m_errorMonitor->SetDesiredFailureMsg(
9852 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009853 "VS consumes input at location 0 but not provided");
9854
Chris Forbes62e8e502015-05-25 11:13:29 +12009855 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12009857
9858 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009859 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009860 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009861 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07009862 "out gl_PerVertex {\n"
9863 " vec4 gl_Position;\n"
9864 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009865 "void main(){\n"
9866 " gl_Position = x;\n"
9867 "}\n";
9868 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009869 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009870 "\n"
9871 "layout(location=0) out vec4 color;\n"
9872 "void main(){\n"
9873 " color = vec4(1);\n"
9874 "}\n";
9875
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12009878
9879 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009880 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12009881 pipe.AddShader(&vs);
9882 pipe.AddShader(&fs);
9883
Chris Forbes62e8e502015-05-25 11:13:29 +12009884 VkDescriptorSetObj descriptorSet(m_device);
9885 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12009887
Tony Barbour5781e8f2015-08-04 16:23:11 -06009888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12009889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009890 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12009891}
9892
Karl Schultz6addd812016-02-02 17:17:23 -07009893TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
9894 m_errorMonitor->SetDesiredFailureMsg(
9895 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009896 "location 0 does not match VS input type");
9897
Chris Forbesc97d98e2015-05-25 11:13:31 +12009898 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009900
9901 VkVertexInputBindingDescription input_binding;
9902 memset(&input_binding, 0, sizeof(input_binding));
9903
9904 VkVertexInputAttributeDescription input_attrib;
9905 memset(&input_attrib, 0, sizeof(input_attrib));
9906 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9907
9908 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009909 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009910 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009911 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009912 "out gl_PerVertex {\n"
9913 " vec4 gl_Position;\n"
9914 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009915 "void main(){\n"
9916 " gl_Position = vec4(x);\n"
9917 "}\n";
9918 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009919 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009920 "\n"
9921 "layout(location=0) out vec4 color;\n"
9922 "void main(){\n"
9923 " color = vec4(1);\n"
9924 "}\n";
9925
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009926 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9927 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009928
9929 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009930 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009931 pipe.AddShader(&vs);
9932 pipe.AddShader(&fs);
9933
9934 pipe.AddVertexInputBindings(&input_binding, 1);
9935 pipe.AddVertexInputAttribs(&input_attrib, 1);
9936
Chris Forbesc97d98e2015-05-25 11:13:31 +12009937 VkDescriptorSetObj descriptorSet(m_device);
9938 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009939 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009940
Tony Barbour5781e8f2015-08-04 16:23:11 -06009941 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009942
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009943 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009944}
9945
Chris Forbesc68b43c2016-04-06 11:18:47 +12009946TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9947 m_errorMonitor->SetDesiredFailureMsg(
9948 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9949 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9950
9951 ASSERT_NO_FATAL_FAILURE(InitState());
9952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9953
9954 char const *vsSource =
9955 "#version 450\n"
9956 "\n"
9957 "out gl_PerVertex {\n"
9958 " vec4 gl_Position;\n"
9959 "};\n"
9960 "void main(){\n"
9961 " gl_Position = vec4(1);\n"
9962 "}\n";
9963 char const *fsSource =
9964 "#version 450\n"
9965 "\n"
9966 "layout(location=0) out vec4 color;\n"
9967 "void main(){\n"
9968 " color = vec4(1);\n"
9969 "}\n";
9970
9971 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9972 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9973
9974 VkPipelineObj pipe(m_device);
9975 pipe.AddColorAttachment();
9976 pipe.AddShader(&vs);
9977 pipe.AddShader(&vs);
9978 pipe.AddShader(&fs);
9979
9980 VkDescriptorSetObj descriptorSet(m_device);
9981 descriptorSet.AppendDummy();
9982 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9983
9984 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9985
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009986 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009987}
9988
Karl Schultz6addd812016-02-02 17:17:23 -07009989TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009990 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009991
9992 ASSERT_NO_FATAL_FAILURE(InitState());
9993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9994
9995 VkVertexInputBindingDescription input_binding;
9996 memset(&input_binding, 0, sizeof(input_binding));
9997
9998 VkVertexInputAttributeDescription input_attribs[2];
9999 memset(input_attribs, 0, sizeof(input_attribs));
10000
10001 for (int i = 0; i < 2; i++) {
10002 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10003 input_attribs[i].location = i;
10004 }
10005
10006 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010007 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010008 "\n"
10009 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010010 "out gl_PerVertex {\n"
10011 " vec4 gl_Position;\n"
10012 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010013 "void main(){\n"
10014 " gl_Position = x[0] + x[1];\n"
10015 "}\n";
10016 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010017 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010018 "\n"
10019 "layout(location=0) out vec4 color;\n"
10020 "void main(){\n"
10021 " color = vec4(1);\n"
10022 "}\n";
10023
10024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10026
10027 VkPipelineObj pipe(m_device);
10028 pipe.AddColorAttachment();
10029 pipe.AddShader(&vs);
10030 pipe.AddShader(&fs);
10031
10032 pipe.AddVertexInputBindings(&input_binding, 1);
10033 pipe.AddVertexInputAttribs(input_attribs, 2);
10034
10035 VkDescriptorSetObj descriptorSet(m_device);
10036 descriptorSet.AppendDummy();
10037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10038
10039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10040
10041 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010042 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010043}
10044
Chris Forbes2682b242015-11-24 11:13:14 +130010045TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10046{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010047 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010048
10049 ASSERT_NO_FATAL_FAILURE(InitState());
10050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10051
10052 VkVertexInputBindingDescription input_binding;
10053 memset(&input_binding, 0, sizeof(input_binding));
10054
10055 VkVertexInputAttributeDescription input_attribs[2];
10056 memset(input_attribs, 0, sizeof(input_attribs));
10057
10058 for (int i = 0; i < 2; i++) {
10059 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10060 input_attribs[i].location = i;
10061 }
10062
10063 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010064 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010065 "\n"
10066 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010067 "out gl_PerVertex {\n"
10068 " vec4 gl_Position;\n"
10069 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010070 "void main(){\n"
10071 " gl_Position = x[0] + x[1];\n"
10072 "}\n";
10073 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010074 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010075 "\n"
10076 "layout(location=0) out vec4 color;\n"
10077 "void main(){\n"
10078 " color = vec4(1);\n"
10079 "}\n";
10080
10081 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10082 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10083
10084 VkPipelineObj pipe(m_device);
10085 pipe.AddColorAttachment();
10086 pipe.AddShader(&vs);
10087 pipe.AddShader(&fs);
10088
10089 pipe.AddVertexInputBindings(&input_binding, 1);
10090 pipe.AddVertexInputAttribs(input_attribs, 2);
10091
10092 VkDescriptorSetObj descriptorSet(m_device);
10093 descriptorSet.AppendDummy();
10094 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10095
10096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10097
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010098 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010099}
Chris Forbes2682b242015-11-24 11:13:14 +130010100
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010101TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10102{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010103 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010104
10105 ASSERT_NO_FATAL_FAILURE(InitState());
10106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10107
10108 char const *vsSource =
10109 "#version 450\n"
10110 "out gl_PerVertex {\n"
10111 " vec4 gl_Position;\n"
10112 "};\n"
10113 "void main(){\n"
10114 " gl_Position = vec4(0);\n"
10115 "}\n";
10116 char const *fsSource =
10117 "#version 450\n"
10118 "\n"
10119 "layout(location=0) out vec4 color;\n"
10120 "void main(){\n"
10121 " color = vec4(1);\n"
10122 "}\n";
10123
10124 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10125 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10126
10127 VkPipelineObj pipe(m_device);
10128 pipe.AddColorAttachment();
10129 pipe.AddShader(&vs);
10130 pipe.AddShader(&fs);
10131
10132 VkDescriptorSetObj descriptorSet(m_device);
10133 descriptorSet.AppendDummy();
10134 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10135
10136 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10137
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010138 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010139}
10140
Chris Forbes912c9192016-04-05 17:50:35 +120010141TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10142{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010143 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010144
10145 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10146
10147 ASSERT_NO_FATAL_FAILURE(InitState());
10148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10149
10150 char const *vsSource =
10151 "#version 450\n"
10152 "out gl_PerVertex {\n"
10153 " vec4 gl_Position;\n"
10154 "};\n"
10155 "layout(location=0) out vec3 x;\n"
10156 "layout(location=1) out ivec3 y;\n"
10157 "layout(location=2) out vec3 z;\n"
10158 "void main(){\n"
10159 " gl_Position = vec4(0);\n"
10160 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10161 "}\n";
10162 char const *fsSource =
10163 "#version 450\n"
10164 "\n"
10165 "layout(location=0) out vec4 color;\n"
10166 "layout(location=0) in float x;\n"
10167 "layout(location=1) flat in int y;\n"
10168 "layout(location=2) in vec2 z;\n"
10169 "void main(){\n"
10170 " color = vec4(1 + x + y + z.x);\n"
10171 "}\n";
10172
10173 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10174 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10175
10176 VkPipelineObj pipe(m_device);
10177 pipe.AddColorAttachment();
10178 pipe.AddShader(&vs);
10179 pipe.AddShader(&fs);
10180
10181 VkDescriptorSetObj descriptorSet(m_device);
10182 descriptorSet.AppendDummy();
10183 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10184
10185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10186
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010187 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010188}
10189
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010190TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10191{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010192 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010193
10194 ASSERT_NO_FATAL_FAILURE(InitState());
10195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10196
Chris Forbesc1e852d2016-04-04 19:26:42 +120010197 if (!m_device->phy().features().tessellationShader) {
10198 printf("Device does not support tessellation shaders; skipped.\n");
10199 return;
10200 }
10201
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010202 char const *vsSource =
10203 "#version 450\n"
10204 "void main(){}\n";
10205 char const *tcsSource =
10206 "#version 450\n"
10207 "layout(location=0) out int x[];\n"
10208 "layout(vertices=3) out;\n"
10209 "void main(){\n"
10210 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10211 " gl_TessLevelInner[0] = 1;\n"
10212 " x[gl_InvocationID] = gl_InvocationID;\n"
10213 "}\n";
10214 char const *tesSource =
10215 "#version 450\n"
10216 "layout(triangles, equal_spacing, cw) in;\n"
10217 "layout(location=0) in int x[];\n"
10218 "out gl_PerVertex { vec4 gl_Position; };\n"
10219 "void main(){\n"
10220 " gl_Position.xyz = gl_TessCoord;\n"
10221 " gl_Position.w = x[0] + x[1] + x[2];\n"
10222 "}\n";
10223 char const *fsSource =
10224 "#version 450\n"
10225 "layout(location=0) out vec4 color;\n"
10226 "void main(){\n"
10227 " color = vec4(1);\n"
10228 "}\n";
10229
10230 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10231 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10232 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10234
10235 VkPipelineInputAssemblyStateCreateInfo iasci{
10236 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10237 nullptr,
10238 0,
10239 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10240 VK_FALSE};
10241
Chris Forbesb4cacb62016-04-04 19:15:00 +120010242 VkPipelineTessellationStateCreateInfo tsci{
10243 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10244 nullptr,
10245 0,
10246 3};
10247
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010248 VkPipelineObj pipe(m_device);
10249 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010250 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010251 pipe.AddColorAttachment();
10252 pipe.AddShader(&vs);
10253 pipe.AddShader(&tcs);
10254 pipe.AddShader(&tes);
10255 pipe.AddShader(&fs);
10256
10257 VkDescriptorSetObj descriptorSet(m_device);
10258 descriptorSet.AppendDummy();
10259 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10260
10261 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010263 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010264}
10265
Chris Forbesa0ab8152016-04-20 13:34:27 +120010266TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10267{
10268 m_errorMonitor->ExpectSuccess();
10269
10270 ASSERT_NO_FATAL_FAILURE(InitState());
10271 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10272
10273 if (!m_device->phy().features().geometryShader) {
10274 printf("Device does not support geometry shaders; skipped.\n");
10275 return;
10276 }
10277
10278 char const *vsSource =
10279 "#version 450\n"
10280 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10281 "void main(){\n"
10282 " vs_out.x = vec4(1);\n"
10283 "}\n";
10284 char const *gsSource =
10285 "#version 450\n"
10286 "layout(triangles) in;\n"
10287 "layout(triangle_strip, max_vertices=3) out;\n"
10288 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10289 "out gl_PerVertex { vec4 gl_Position; };\n"
10290 "void main() {\n"
10291 " gl_Position = gs_in[0].x;\n"
10292 " EmitVertex();\n"
10293 "}\n";
10294 char const *fsSource =
10295 "#version 450\n"
10296 "layout(location=0) out vec4 color;\n"
10297 "void main(){\n"
10298 " color = vec4(1);\n"
10299 "}\n";
10300
10301 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10302 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10303 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10304
10305 VkPipelineObj pipe(m_device);
10306 pipe.AddColorAttachment();
10307 pipe.AddShader(&vs);
10308 pipe.AddShader(&gs);
10309 pipe.AddShader(&fs);
10310
10311 VkDescriptorSetObj descriptorSet(m_device);
10312 descriptorSet.AppendDummy();
10313 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10314
10315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10316
10317 m_errorMonitor->VerifyNotFound();
10318}
10319
Chris Forbesa0193bc2016-04-04 19:19:47 +120010320TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10321{
10322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10323 "is per-vertex in tessellation control shader stage "
10324 "but per-patch in tessellation evaluation shader stage");
10325
10326 ASSERT_NO_FATAL_FAILURE(InitState());
10327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10328
Chris Forbesc1e852d2016-04-04 19:26:42 +120010329 if (!m_device->phy().features().tessellationShader) {
10330 printf("Device does not support tessellation shaders; skipped.\n");
10331 return;
10332 }
10333
Chris Forbesa0193bc2016-04-04 19:19:47 +120010334 char const *vsSource =
10335 "#version 450\n"
10336 "void main(){}\n";
10337 char const *tcsSource =
10338 "#version 450\n"
10339 "layout(location=0) out int x[];\n"
10340 "layout(vertices=3) out;\n"
10341 "void main(){\n"
10342 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10343 " gl_TessLevelInner[0] = 1;\n"
10344 " x[gl_InvocationID] = gl_InvocationID;\n"
10345 "}\n";
10346 char const *tesSource =
10347 "#version 450\n"
10348 "layout(triangles, equal_spacing, cw) in;\n"
10349 "layout(location=0) patch in int x;\n"
10350 "out gl_PerVertex { vec4 gl_Position; };\n"
10351 "void main(){\n"
10352 " gl_Position.xyz = gl_TessCoord;\n"
10353 " gl_Position.w = x;\n"
10354 "}\n";
10355 char const *fsSource =
10356 "#version 450\n"
10357 "layout(location=0) out vec4 color;\n"
10358 "void main(){\n"
10359 " color = vec4(1);\n"
10360 "}\n";
10361
10362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10363 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10364 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10366
10367 VkPipelineInputAssemblyStateCreateInfo iasci{
10368 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10369 nullptr,
10370 0,
10371 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10372 VK_FALSE};
10373
10374 VkPipelineTessellationStateCreateInfo tsci{
10375 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10376 nullptr,
10377 0,
10378 3};
10379
10380 VkPipelineObj pipe(m_device);
10381 pipe.SetInputAssembly(&iasci);
10382 pipe.SetTessellation(&tsci);
10383 pipe.AddColorAttachment();
10384 pipe.AddShader(&vs);
10385 pipe.AddShader(&tcs);
10386 pipe.AddShader(&tes);
10387 pipe.AddShader(&fs);
10388
10389 VkDescriptorSetObj descriptorSet(m_device);
10390 descriptorSet.AppendDummy();
10391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10392
10393 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010395 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010396}
10397
Karl Schultz6addd812016-02-02 17:17:23 -070010398TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10399 m_errorMonitor->SetDesiredFailureMsg(
10400 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010401 "Duplicate vertex input binding descriptions for binding 0");
10402
Chris Forbes280ba2c2015-06-12 11:16:41 +120010403 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010405
10406 /* Two binding descriptions for binding 0 */
10407 VkVertexInputBindingDescription input_bindings[2];
10408 memset(input_bindings, 0, sizeof(input_bindings));
10409
10410 VkVertexInputAttributeDescription input_attrib;
10411 memset(&input_attrib, 0, sizeof(input_attrib));
10412 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10413
10414 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010415 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010416 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010417 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010418 "out gl_PerVertex {\n"
10419 " vec4 gl_Position;\n"
10420 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010421 "void main(){\n"
10422 " gl_Position = vec4(x);\n"
10423 "}\n";
10424 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010425 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010426 "\n"
10427 "layout(location=0) out vec4 color;\n"
10428 "void main(){\n"
10429 " color = vec4(1);\n"
10430 "}\n";
10431
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010434
10435 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010436 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010437 pipe.AddShader(&vs);
10438 pipe.AddShader(&fs);
10439
10440 pipe.AddVertexInputBindings(input_bindings, 2);
10441 pipe.AddVertexInputAttribs(&input_attrib, 1);
10442
Chris Forbes280ba2c2015-06-12 11:16:41 +120010443 VkDescriptorSetObj descriptorSet(m_device);
10444 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010446
Tony Barbour5781e8f2015-08-04 16:23:11 -060010447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010449 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010450}
Chris Forbes8f68b562015-05-25 11:13:32 +120010451
Chris Forbes35efec72016-04-21 14:32:08 +120010452TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10453 m_errorMonitor->ExpectSuccess();
10454
10455 ASSERT_NO_FATAL_FAILURE(InitState());
10456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10457
10458 if (!m_device->phy().features().tessellationShader) {
10459 printf("Device does not support 64bit vertex attributes; skipped.\n");
10460 return;
10461 }
10462
10463 VkVertexInputBindingDescription input_bindings[1];
10464 memset(input_bindings, 0, sizeof(input_bindings));
10465
10466 VkVertexInputAttributeDescription input_attribs[4];
10467 memset(input_attribs, 0, sizeof(input_attribs));
10468 input_attribs[0].location = 0;
10469 input_attribs[0].offset = 0;
10470 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10471 input_attribs[1].location = 2;
10472 input_attribs[1].offset = 32;
10473 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10474 input_attribs[2].location = 4;
10475 input_attribs[2].offset = 64;
10476 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10477 input_attribs[3].location = 6;
10478 input_attribs[3].offset = 96;
10479 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10480
10481 char const *vsSource =
10482 "#version 450\n"
10483 "\n"
10484 "layout(location=0) in dmat4 x;\n"
10485 "out gl_PerVertex {\n"
10486 " vec4 gl_Position;\n"
10487 "};\n"
10488 "void main(){\n"
10489 " gl_Position = vec4(x[0][0]);\n"
10490 "}\n";
10491 char const *fsSource =
10492 "#version 450\n"
10493 "\n"
10494 "layout(location=0) out vec4 color;\n"
10495 "void main(){\n"
10496 " color = vec4(1);\n"
10497 "}\n";
10498
10499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10501
10502 VkPipelineObj pipe(m_device);
10503 pipe.AddColorAttachment();
10504 pipe.AddShader(&vs);
10505 pipe.AddShader(&fs);
10506
10507 pipe.AddVertexInputBindings(input_bindings, 1);
10508 pipe.AddVertexInputAttribs(input_attribs, 4);
10509
10510 VkDescriptorSetObj descriptorSet(m_device);
10511 descriptorSet.AppendDummy();
10512 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10513
10514 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10515
10516 m_errorMonitor->VerifyNotFound();
10517}
10518
Karl Schultz6addd812016-02-02 17:17:23 -070010519TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010521 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010522
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010523 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010524
10525 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010526 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010527 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010528 "out gl_PerVertex {\n"
10529 " vec4 gl_Position;\n"
10530 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010531 "void main(){\n"
10532 " gl_Position = vec4(1);\n"
10533 "}\n";
10534 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010535 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010536 "\n"
10537 "void main(){\n"
10538 "}\n";
10539
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010540 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10541 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010542
10543 VkPipelineObj pipe(m_device);
10544 pipe.AddShader(&vs);
10545 pipe.AddShader(&fs);
10546
Chia-I Wu08accc62015-07-07 11:50:03 +080010547 /* set up CB 0, not written */
10548 pipe.AddColorAttachment();
10549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010550
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010551 VkDescriptorSetObj descriptorSet(m_device);
10552 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010554
Tony Barbour5781e8f2015-08-04 16:23:11 -060010555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010556
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010557 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010558}
10559
Karl Schultz6addd812016-02-02 17:17:23 -070010560TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010561 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010562 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010563 "FS writes to output location 1 with no matching attachment");
10564
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010565 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010566
10567 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010568 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010569 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010570 "out gl_PerVertex {\n"
10571 " vec4 gl_Position;\n"
10572 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010573 "void main(){\n"
10574 " gl_Position = vec4(1);\n"
10575 "}\n";
10576 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010577 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010578 "\n"
10579 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010580 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010581 "void main(){\n"
10582 " x = vec4(1);\n"
10583 " y = vec4(1);\n"
10584 "}\n";
10585
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010586 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10587 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010588
10589 VkPipelineObj pipe(m_device);
10590 pipe.AddShader(&vs);
10591 pipe.AddShader(&fs);
10592
Chia-I Wu08accc62015-07-07 11:50:03 +080010593 /* set up CB 0, not written */
10594 pipe.AddColorAttachment();
10595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010596 /* FS writes CB 1, but we don't configure it */
10597
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010598 VkDescriptorSetObj descriptorSet(m_device);
10599 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010600 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010601
Tony Barbour5781e8f2015-08-04 16:23:11 -060010602 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010603
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010604 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010605}
10606
Karl Schultz6addd812016-02-02 17:17:23 -070010607TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010609 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010610
Chris Forbesa36d69e2015-05-25 11:13:44 +120010611 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010612
10613 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010614 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010615 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010616 "out gl_PerVertex {\n"
10617 " vec4 gl_Position;\n"
10618 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010619 "void main(){\n"
10620 " gl_Position = vec4(1);\n"
10621 "}\n";
10622 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010623 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010624 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010625 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010626 "void main(){\n"
10627 " x = ivec4(1);\n"
10628 "}\n";
10629
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010630 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10631 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010632
10633 VkPipelineObj pipe(m_device);
10634 pipe.AddShader(&vs);
10635 pipe.AddShader(&fs);
10636
Chia-I Wu08accc62015-07-07 11:50:03 +080010637 /* set up CB 0; type is UNORM by default */
10638 pipe.AddColorAttachment();
10639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010640
Chris Forbesa36d69e2015-05-25 11:13:44 +120010641 VkDescriptorSetObj descriptorSet(m_device);
10642 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010643 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010644
Tony Barbour5781e8f2015-08-04 16:23:11 -060010645 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010646
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010647 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010648}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010649
Karl Schultz6addd812016-02-02 17:17:23 -070010650TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010652 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010653
Chris Forbes556c76c2015-08-14 12:04:59 +120010654 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010655
10656 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010657 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010658 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010659 "out gl_PerVertex {\n"
10660 " vec4 gl_Position;\n"
10661 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010662 "void main(){\n"
10663 " gl_Position = vec4(1);\n"
10664 "}\n";
10665 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010666 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010667 "\n"
10668 "layout(location=0) out vec4 x;\n"
10669 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10670 "void main(){\n"
10671 " x = vec4(bar.y);\n"
10672 "}\n";
10673
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010676
Chris Forbes556c76c2015-08-14 12:04:59 +120010677 VkPipelineObj pipe(m_device);
10678 pipe.AddShader(&vs);
10679 pipe.AddShader(&fs);
10680
10681 /* set up CB 0; type is UNORM by default */
10682 pipe.AddColorAttachment();
10683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10684
10685 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010686 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010687
10688 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10689
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010690 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010691}
10692
Chris Forbes5c59e902016-02-26 16:56:09 +130010693TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10695 "not declared in layout");
10696
10697 ASSERT_NO_FATAL_FAILURE(InitState());
10698
10699 char const *vsSource =
10700 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010701 "\n"
10702 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10703 "out gl_PerVertex {\n"
10704 " vec4 gl_Position;\n"
10705 "};\n"
10706 "void main(){\n"
10707 " gl_Position = vec4(consts.x);\n"
10708 "}\n";
10709 char const *fsSource =
10710 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010711 "\n"
10712 "layout(location=0) out vec4 x;\n"
10713 "void main(){\n"
10714 " x = vec4(1);\n"
10715 "}\n";
10716
10717 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10718 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10719
10720 VkPipelineObj pipe(m_device);
10721 pipe.AddShader(&vs);
10722 pipe.AddShader(&fs);
10723
10724 /* set up CB 0; type is UNORM by default */
10725 pipe.AddColorAttachment();
10726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10727
10728 VkDescriptorSetObj descriptorSet(m_device);
10729 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10730
10731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10732
10733 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010734 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010735}
10736
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010737TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10738 m_errorMonitor->SetDesiredFailureMsg(
10739 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10740 "Shader uses descriptor slot 0.0");
10741
10742 ASSERT_NO_FATAL_FAILURE(InitState());
10743
10744 char const *csSource =
10745 "#version 450\n"
10746 "\n"
10747 "layout(local_size_x=1) in;\n"
10748 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10749 "void main(){\n"
10750 " x = vec4(1);\n"
10751 "}\n";
10752
10753 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10754
10755 VkDescriptorSetObj descriptorSet(m_device);
10756 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10757
10758 VkComputePipelineCreateInfo cpci = {
10759 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10760 nullptr, 0, {
10761 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10762 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10763 cs.handle(), "main", nullptr
10764 },
10765 descriptorSet.GetPipelineLayout(),
10766 VK_NULL_HANDLE, -1
10767 };
10768
10769 VkPipeline pipe;
10770 VkResult err = vkCreateComputePipelines(
10771 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10772
10773 m_errorMonitor->VerifyFound();
10774
10775 if (err == VK_SUCCESS) {
10776 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10777 }
10778}
10779
10780TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
10781 m_errorMonitor->ExpectSuccess();
10782
10783 ASSERT_NO_FATAL_FAILURE(InitState());
10784
10785 char const *csSource =
10786 "#version 450\n"
10787 "\n"
10788 "layout(local_size_x=1) in;\n"
10789 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10790 "void main(){\n"
10791 " // x is not used.\n"
10792 "}\n";
10793
10794 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10795
10796 VkDescriptorSetObj descriptorSet(m_device);
10797 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10798
10799 VkComputePipelineCreateInfo cpci = {
10800 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10801 nullptr, 0, {
10802 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10803 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10804 cs.handle(), "main", nullptr
10805 },
10806 descriptorSet.GetPipelineLayout(),
10807 VK_NULL_HANDLE, -1
10808 };
10809
10810 VkPipeline pipe;
10811 VkResult err = vkCreateComputePipelines(
10812 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10813
10814 m_errorMonitor->VerifyNotFound();
10815
10816 if (err == VK_SUCCESS) {
10817 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10818 }
10819}
10820
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010821#endif // SHADER_CHECKER_TESTS
10822
10823#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060010824TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070010825 m_errorMonitor->SetDesiredFailureMsg(
10826 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010827 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010828
10829 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010830
10831 // Create an image
10832 VkImage image;
10833
Karl Schultz6addd812016-02-02 17:17:23 -070010834 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10835 const int32_t tex_width = 32;
10836 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010837
10838 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010839 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10840 image_create_info.pNext = NULL;
10841 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10842 image_create_info.format = tex_format;
10843 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010844 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070010845 image_create_info.extent.depth = 1;
10846 image_create_info.mipLevels = 1;
10847 image_create_info.arrayLayers = 1;
10848 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10849 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10850 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10851 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010852
10853 // Introduce error by sending down a bogus width extent
10854 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010855 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010856
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010857 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010858}
10859
Mark Youngc48c4c12016-04-11 14:26:49 -060010860TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
10861 m_errorMonitor->SetDesiredFailureMsg(
10862 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10863 "CreateImage extents is 0 for at least one required dimension");
10864
10865 ASSERT_NO_FATAL_FAILURE(InitState());
10866
10867 // Create an image
10868 VkImage image;
10869
10870 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10871 const int32_t tex_width = 32;
10872 const int32_t tex_height = 32;
10873
10874 VkImageCreateInfo image_create_info = {};
10875 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10876 image_create_info.pNext = NULL;
10877 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10878 image_create_info.format = tex_format;
10879 image_create_info.extent.width = tex_width;
10880 image_create_info.extent.height = tex_height;
10881 image_create_info.extent.depth = 1;
10882 image_create_info.mipLevels = 1;
10883 image_create_info.arrayLayers = 1;
10884 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10885 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10886 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10887 image_create_info.flags = 0;
10888
10889 // Introduce error by sending down a bogus width extent
10890 image_create_info.extent.width = 0;
10891 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
10892
10893 m_errorMonitor->VerifyFound();
10894}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010895#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120010896
Tobin Ehliscde08892015-09-22 10:11:37 -060010897#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070010898TEST_F(VkLayerTest, InvalidImageView) {
10899 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060010900
Karl Schultz6addd812016-02-02 17:17:23 -070010901 m_errorMonitor->SetDesiredFailureMsg(
10902 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010903 "vkCreateImageView called with baseMipLevel 10 ");
10904
Tobin Ehliscde08892015-09-22 10:11:37 -060010905 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060010906
Mike Stroyana3082432015-09-25 13:39:21 -060010907 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070010908 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060010909
Karl Schultz6addd812016-02-02 17:17:23 -070010910 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10911 const int32_t tex_width = 32;
10912 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060010913
10914 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010915 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10916 image_create_info.pNext = NULL;
10917 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10918 image_create_info.format = tex_format;
10919 image_create_info.extent.width = tex_width;
10920 image_create_info.extent.height = tex_height;
10921 image_create_info.extent.depth = 1;
10922 image_create_info.mipLevels = 1;
10923 image_create_info.arrayLayers = 1;
10924 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10925 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10926 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10927 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060010928
Chia-I Wuf7458c52015-10-26 21:10:41 +080010929 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060010930 ASSERT_VK_SUCCESS(err);
10931
10932 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010933 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10934 image_view_create_info.image = image;
10935 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10936 image_view_create_info.format = tex_format;
10937 image_view_create_info.subresourceRange.layerCount = 1;
10938 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
10939 image_view_create_info.subresourceRange.levelCount = 1;
10940 image_view_create_info.subresourceRange.aspectMask =
10941 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060010942
10943 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010944 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10945 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060010946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010947 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010948 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060010949}
Mike Stroyana3082432015-09-25 13:39:21 -060010950
Karl Schultz6addd812016-02-02 17:17:23 -070010951TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010952 TEST_DESCRIPTION(
10953 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010955 "vkCreateImageView: Color image "
10956 "formats must have ONLY the "
10957 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010958
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010959 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010960
Karl Schultz6addd812016-02-02 17:17:23 -070010961 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010962 VkImageObj image(m_device);
10963 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
10964 VK_IMAGE_TILING_LINEAR, 0);
10965 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010966
10967 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010968 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010969 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070010970 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10971 image_view_create_info.format = tex_format;
10972 image_view_create_info.subresourceRange.baseMipLevel = 0;
10973 image_view_create_info.subresourceRange.levelCount = 1;
10974 // Cause an error by setting an invalid image aspect
10975 image_view_create_info.subresourceRange.aspectMask =
10976 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010977
10978 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010979 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010980
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010981 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010982}
10983
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010984TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010985 VkResult err;
10986 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010987
Karl Schultz6addd812016-02-02 17:17:23 -070010988 m_errorMonitor->SetDesiredFailureMsg(
10989 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010990 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010991
Mike Stroyana3082432015-09-25 13:39:21 -060010992 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010993
10994 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010995 VkImage srcImage;
10996 VkImage dstImage;
10997 VkDeviceMemory srcMem;
10998 VkDeviceMemory destMem;
10999 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011000
11001 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011002 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11003 image_create_info.pNext = NULL;
11004 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11005 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11006 image_create_info.extent.width = 32;
11007 image_create_info.extent.height = 32;
11008 image_create_info.extent.depth = 1;
11009 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011010 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011011 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11012 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11013 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11014 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011015
Karl Schultz6addd812016-02-02 17:17:23 -070011016 err =
11017 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011018 ASSERT_VK_SUCCESS(err);
11019
Karl Schultz6addd812016-02-02 17:17:23 -070011020 err =
11021 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011022 ASSERT_VK_SUCCESS(err);
11023
11024 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011025 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011026 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11027 memAlloc.pNext = NULL;
11028 memAlloc.allocationSize = 0;
11029 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011030
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011031 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011032 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011033 pass =
11034 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011035 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011036 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011037 ASSERT_VK_SUCCESS(err);
11038
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011039 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011040 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011041 pass =
11042 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011043 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011044 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011045 ASSERT_VK_SUCCESS(err);
11046
11047 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11048 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011049 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011050 ASSERT_VK_SUCCESS(err);
11051
11052 BeginCommandBuffer();
11053 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011054 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011055 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011056 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011057 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011058 copyRegion.srcOffset.x = 0;
11059 copyRegion.srcOffset.y = 0;
11060 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011061 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011062 copyRegion.dstSubresource.mipLevel = 0;
11063 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011064 // Introduce failure by forcing the dst layerCount to differ from src
11065 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011066 copyRegion.dstOffset.x = 0;
11067 copyRegion.dstOffset.y = 0;
11068 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011069 copyRegion.extent.width = 1;
11070 copyRegion.extent.height = 1;
11071 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011072 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11073 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011074 EndCommandBuffer();
11075
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011076 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011077
Chia-I Wuf7458c52015-10-26 21:10:41 +080011078 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011079 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011080 vkFreeMemory(m_device->device(), srcMem, NULL);
11081 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011082}
11083
Tony Barbourd6673642016-05-05 14:46:39 -060011084TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11085
11086 TEST_DESCRIPTION("Creating images with unsuported formats ");
11087
11088 ASSERT_NO_FATAL_FAILURE(InitState());
11089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11090 VkImageObj image(m_device);
11091 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11092 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11093 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11094 VK_IMAGE_TILING_OPTIMAL, 0);
11095 ASSERT_TRUE(image.initialized());
11096
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011097 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11098 VkImageCreateInfo image_create_info;
11099 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11100 image_create_info.pNext = NULL;
11101 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11102 image_create_info.format = VK_FORMAT_UNDEFINED;
11103 image_create_info.extent.width = 32;
11104 image_create_info.extent.height = 32;
11105 image_create_info.extent.depth = 1;
11106 image_create_info.mipLevels = 1;
11107 image_create_info.arrayLayers = 1;
11108 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11109 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11110 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11111 image_create_info.flags = 0;
11112
11113 m_errorMonitor->SetDesiredFailureMsg(
11114 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11115 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11116
11117 VkImage localImage;
11118 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11119 m_errorMonitor->VerifyFound();
11120
Tony Barbourd6673642016-05-05 14:46:39 -060011121 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011122 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011123 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11124 VkFormat format = static_cast<VkFormat>(f);
11125 VkFormatProperties fProps = m_device->format_properties(format);
11126 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11127 fProps.optimalTilingFeatures == 0) {
11128 unsupported = format;
11129 break;
11130 }
11131 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011132
Tony Barbourd6673642016-05-05 14:46:39 -060011133 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011134 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011136 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011137
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011138 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011139 m_errorMonitor->VerifyFound();
11140 }
11141}
11142
11143TEST_F(VkLayerTest, ImageLayerViewTests) {
11144 VkResult ret;
11145 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11146
11147 ASSERT_NO_FATAL_FAILURE(InitState());
11148
11149 VkImageObj image(m_device);
11150 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11151 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11152 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11153 VK_IMAGE_TILING_OPTIMAL, 0);
11154 ASSERT_TRUE(image.initialized());
11155
11156 VkImageView imgView;
11157 VkImageViewCreateInfo imgViewInfo = {};
11158 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11159 imgViewInfo.image = image.handle();
11160 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11161 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11162 imgViewInfo.subresourceRange.layerCount = 1;
11163 imgViewInfo.subresourceRange.baseMipLevel = 0;
11164 imgViewInfo.subresourceRange.levelCount = 1;
11165 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11166
11167 m_errorMonitor->SetDesiredFailureMsg(
11168 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11169 "vkCreateImageView called with baseMipLevel");
11170 // View can't have baseMipLevel >= image's mipLevels - Expect
11171 // VIEW_CREATE_ERROR
11172 imgViewInfo.subresourceRange.baseMipLevel = 1;
11173 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11174 m_errorMonitor->VerifyFound();
11175 imgViewInfo.subresourceRange.baseMipLevel = 0;
11176
11177 m_errorMonitor->SetDesiredFailureMsg(
11178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11179 "vkCreateImageView called with baseArrayLayer");
11180 // View can't have baseArrayLayer >= image's arraySize - Expect
11181 // VIEW_CREATE_ERROR
11182 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11183 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11184 m_errorMonitor->VerifyFound();
11185 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11186
11187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11188 "vkCreateImageView called with 0 in "
11189 "pCreateInfo->subresourceRange."
11190 "levelCount");
11191 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11192 imgViewInfo.subresourceRange.levelCount = 0;
11193 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11194 m_errorMonitor->VerifyFound();
11195 imgViewInfo.subresourceRange.levelCount = 1;
11196
11197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11198 "vkCreateImageView called with 0 in "
11199 "pCreateInfo->subresourceRange."
11200 "layerCount");
11201 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11202 imgViewInfo.subresourceRange.layerCount = 0;
11203 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11204 m_errorMonitor->VerifyFound();
11205 imgViewInfo.subresourceRange.layerCount = 1;
11206
11207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11208 "but both must be color formats");
11209 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11210 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11211 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11212 m_errorMonitor->VerifyFound();
11213 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11214
11215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11216 "Formats MUST be IDENTICAL unless "
11217 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11218 "was set on image creation.");
11219 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11220 // VIEW_CREATE_ERROR
11221 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11222 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11223 m_errorMonitor->VerifyFound();
11224 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11225
11226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11227 "can support ImageViews with "
11228 "differing formats but they must be "
11229 "in the same compatibility class.");
11230 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11231 // VIEW_CREATE_ERROR
11232 VkImageCreateInfo mutImgInfo = image.create_info();
11233 VkImage mutImage;
11234 mutImgInfo.format = VK_FORMAT_R8_UINT;
11235 assert(
11236 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11237 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11238 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11239 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11240 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11241 ASSERT_VK_SUCCESS(ret);
11242 imgViewInfo.image = mutImage;
11243 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11244 m_errorMonitor->VerifyFound();
11245 imgViewInfo.image = image.handle();
11246 vkDestroyImage(m_device->handle(), mutImage, NULL);
11247}
11248
11249TEST_F(VkLayerTest, MiscImageLayerTests) {
11250
11251 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11252
11253 ASSERT_NO_FATAL_FAILURE(InitState());
11254
11255 VkImageObj image(m_device);
11256 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11257 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11258 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11259 VK_IMAGE_TILING_OPTIMAL, 0);
11260 ASSERT_TRUE(image.initialized());
11261
11262 m_errorMonitor->SetDesiredFailureMsg(
11263 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11264 "number of layers in image subresource is zero");
11265 vk_testing::Buffer buffer;
11266 VkMemoryPropertyFlags reqs = 0;
11267 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11268 VkBufferImageCopy region = {};
11269 region.bufferRowLength = 128;
11270 region.bufferImageHeight = 128;
11271 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11272 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11273 region.imageSubresource.layerCount = 0;
11274 region.imageExtent.height = 4;
11275 region.imageExtent.width = 4;
11276 region.imageExtent.depth = 1;
11277 m_commandBuffer->BeginCommandBuffer();
11278 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11279 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11280 1, &region);
11281 m_errorMonitor->VerifyFound();
11282 region.imageSubresource.layerCount = 1;
11283
11284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11285 "aspectMasks for each region must "
11286 "specify only COLOR or DEPTH or "
11287 "STENCIL");
11288 // Expect MISMATCHED_IMAGE_ASPECT
11289 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11290 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11291 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11292 1, &region);
11293 m_errorMonitor->VerifyFound();
11294 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11295
11296 m_errorMonitor->SetDesiredFailureMsg(
11297 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11298 "If the format of srcImage is a depth, stencil, depth stencil or "
11299 "integer-based format then filter must be VK_FILTER_NEAREST");
11300 // Expect INVALID_FILTER
11301 VkImageObj intImage1(m_device);
11302 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11303 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11304 0);
11305 VkImageObj intImage2(m_device);
11306 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11307 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11308 0);
11309 VkImageBlit blitRegion = {};
11310 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11311 blitRegion.srcSubresource.baseArrayLayer = 0;
11312 blitRegion.srcSubresource.layerCount = 1;
11313 blitRegion.srcSubresource.mipLevel = 0;
11314 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11315 blitRegion.dstSubresource.baseArrayLayer = 0;
11316 blitRegion.dstSubresource.layerCount = 1;
11317 blitRegion.dstSubresource.mipLevel = 0;
11318
11319 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11320 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11321 16, &blitRegion, VK_FILTER_LINEAR);
11322 m_errorMonitor->VerifyFound();
11323
11324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11325 "called with 0 in ppMemoryBarriers");
11326 VkImageMemoryBarrier img_barrier;
11327 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11328 img_barrier.pNext = NULL;
11329 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11330 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11331 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11332 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11333 img_barrier.image = image.handle();
11334 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11335 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11336 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11337 img_barrier.subresourceRange.baseArrayLayer = 0;
11338 img_barrier.subresourceRange.baseMipLevel = 0;
11339 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11340 img_barrier.subresourceRange.layerCount = 0;
11341 img_barrier.subresourceRange.levelCount = 1;
11342 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11343 VK_PIPELINE_STAGE_HOST_BIT,
11344 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11345 nullptr, 1, &img_barrier);
11346 m_errorMonitor->VerifyFound();
11347 img_barrier.subresourceRange.layerCount = 1;
11348}
11349
11350TEST_F(VkLayerTest, ImageFormatLimits) {
11351
11352 TEST_DESCRIPTION("Exceed the limits of image format ");
11353
11354 m_errorMonitor->SetDesiredFailureMsg(
11355 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11356 "CreateImage extents exceed allowable limits for format");
11357 VkImageCreateInfo image_create_info = {};
11358 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11359 image_create_info.pNext = NULL;
11360 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11361 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11362 image_create_info.extent.width = 32;
11363 image_create_info.extent.height = 32;
11364 image_create_info.extent.depth = 1;
11365 image_create_info.mipLevels = 1;
11366 image_create_info.arrayLayers = 1;
11367 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11368 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11369 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11370 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11371 image_create_info.flags = 0;
11372
11373 VkImage nullImg;
11374 VkImageFormatProperties imgFmtProps;
11375 vkGetPhysicalDeviceImageFormatProperties(
11376 gpu(), image_create_info.format, image_create_info.imageType,
11377 image_create_info.tiling, image_create_info.usage,
11378 image_create_info.flags, &imgFmtProps);
11379 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11380 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11381 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11382 m_errorMonitor->VerifyFound();
11383 image_create_info.extent.depth = 1;
11384
11385 m_errorMonitor->SetDesiredFailureMsg(
11386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11387 "exceeds allowable maximum supported by format of");
11388 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11389 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11390 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11391 m_errorMonitor->VerifyFound();
11392 image_create_info.mipLevels = 1;
11393
11394 m_errorMonitor->SetDesiredFailureMsg(
11395 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11396 "exceeds allowable maximum supported by format of");
11397 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11398 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11399 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11400 m_errorMonitor->VerifyFound();
11401 image_create_info.arrayLayers = 1;
11402
11403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11404 "is not supported by format");
11405 int samples = imgFmtProps.sampleCounts >> 1;
11406 image_create_info.samples = (VkSampleCountFlagBits)samples;
11407 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11408 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11409 m_errorMonitor->VerifyFound();
11410 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11411
11412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11413 "pCreateInfo->initialLayout, must be "
11414 "VK_IMAGE_LAYOUT_UNDEFINED or "
11415 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11416 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11417 // Expect INVALID_LAYOUT
11418 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11419 m_errorMonitor->VerifyFound();
11420 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11421}
11422
Karl Schultz6addd812016-02-02 17:17:23 -070011423TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011424 VkResult err;
11425 bool pass;
11426
11427 // Create color images with different format sizes and try to copy between them
11428 m_errorMonitor->SetDesiredFailureMsg(
11429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11430 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11431
11432 ASSERT_NO_FATAL_FAILURE(InitState());
11433
11434 // Create two images of different types and try to copy between them
11435 VkImage srcImage;
11436 VkImage dstImage;
11437 VkDeviceMemory srcMem;
11438 VkDeviceMemory destMem;
11439 VkMemoryRequirements memReqs;
11440
11441 VkImageCreateInfo image_create_info = {};
11442 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11443 image_create_info.pNext = NULL;
11444 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11445 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11446 image_create_info.extent.width = 32;
11447 image_create_info.extent.height = 32;
11448 image_create_info.extent.depth = 1;
11449 image_create_info.mipLevels = 1;
11450 image_create_info.arrayLayers = 1;
11451 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11452 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11453 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11454 image_create_info.flags = 0;
11455
11456 err =
11457 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11458 ASSERT_VK_SUCCESS(err);
11459
11460 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11461 // Introduce failure by creating second image with a different-sized format.
11462 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11463
11464 err =
11465 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11466 ASSERT_VK_SUCCESS(err);
11467
11468 // Allocate memory
11469 VkMemoryAllocateInfo memAlloc = {};
11470 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11471 memAlloc.pNext = NULL;
11472 memAlloc.allocationSize = 0;
11473 memAlloc.memoryTypeIndex = 0;
11474
11475 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11476 memAlloc.allocationSize = memReqs.size;
11477 pass =
11478 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11479 ASSERT_TRUE(pass);
11480 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11481 ASSERT_VK_SUCCESS(err);
11482
11483 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11484 memAlloc.allocationSize = memReqs.size;
11485 pass =
11486 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11487 ASSERT_TRUE(pass);
11488 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11489 ASSERT_VK_SUCCESS(err);
11490
11491 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11492 ASSERT_VK_SUCCESS(err);
11493 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11494 ASSERT_VK_SUCCESS(err);
11495
11496 BeginCommandBuffer();
11497 VkImageCopy copyRegion;
11498 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11499 copyRegion.srcSubresource.mipLevel = 0;
11500 copyRegion.srcSubresource.baseArrayLayer = 0;
11501 copyRegion.srcSubresource.layerCount = 0;
11502 copyRegion.srcOffset.x = 0;
11503 copyRegion.srcOffset.y = 0;
11504 copyRegion.srcOffset.z = 0;
11505 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11506 copyRegion.dstSubresource.mipLevel = 0;
11507 copyRegion.dstSubresource.baseArrayLayer = 0;
11508 copyRegion.dstSubresource.layerCount = 0;
11509 copyRegion.dstOffset.x = 0;
11510 copyRegion.dstOffset.y = 0;
11511 copyRegion.dstOffset.z = 0;
11512 copyRegion.extent.width = 1;
11513 copyRegion.extent.height = 1;
11514 copyRegion.extent.depth = 1;
11515 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11516 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11517 EndCommandBuffer();
11518
11519 m_errorMonitor->VerifyFound();
11520
11521 vkDestroyImage(m_device->device(), srcImage, NULL);
11522 vkDestroyImage(m_device->device(), dstImage, NULL);
11523 vkFreeMemory(m_device->device(), srcMem, NULL);
11524 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011525}
11526
Karl Schultz6addd812016-02-02 17:17:23 -070011527TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11528 VkResult err;
11529 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011530
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011531 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011532 m_errorMonitor->SetDesiredFailureMsg(
11533 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011534 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011535
Mike Stroyana3082432015-09-25 13:39:21 -060011536 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011537
11538 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011539 VkImage srcImage;
11540 VkImage dstImage;
11541 VkDeviceMemory srcMem;
11542 VkDeviceMemory destMem;
11543 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011544
11545 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011546 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11547 image_create_info.pNext = NULL;
11548 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11549 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11550 image_create_info.extent.width = 32;
11551 image_create_info.extent.height = 32;
11552 image_create_info.extent.depth = 1;
11553 image_create_info.mipLevels = 1;
11554 image_create_info.arrayLayers = 1;
11555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11556 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11557 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11558 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011559
Karl Schultz6addd812016-02-02 17:17:23 -070011560 err =
11561 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011562 ASSERT_VK_SUCCESS(err);
11563
Karl Schultzbdb75952016-04-19 11:36:49 -060011564 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11565
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011566 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011567 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011568 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11569 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011570
Karl Schultz6addd812016-02-02 17:17:23 -070011571 err =
11572 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011573 ASSERT_VK_SUCCESS(err);
11574
11575 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011576 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011577 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11578 memAlloc.pNext = NULL;
11579 memAlloc.allocationSize = 0;
11580 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011581
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011582 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011583 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011584 pass =
11585 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011586 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011587 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011588 ASSERT_VK_SUCCESS(err);
11589
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011590 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011591 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011592 pass =
11593 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011594 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011595 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011596 ASSERT_VK_SUCCESS(err);
11597
11598 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11599 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011600 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011601 ASSERT_VK_SUCCESS(err);
11602
11603 BeginCommandBuffer();
11604 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011605 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011606 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011607 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011608 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011609 copyRegion.srcOffset.x = 0;
11610 copyRegion.srcOffset.y = 0;
11611 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011612 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011613 copyRegion.dstSubresource.mipLevel = 0;
11614 copyRegion.dstSubresource.baseArrayLayer = 0;
11615 copyRegion.dstSubresource.layerCount = 0;
11616 copyRegion.dstOffset.x = 0;
11617 copyRegion.dstOffset.y = 0;
11618 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011619 copyRegion.extent.width = 1;
11620 copyRegion.extent.height = 1;
11621 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011622 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11623 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011624 EndCommandBuffer();
11625
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011626 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011627
Chia-I Wuf7458c52015-10-26 21:10:41 +080011628 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011629 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011630 vkFreeMemory(m_device->device(), srcMem, NULL);
11631 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011632}
11633
Karl Schultz6addd812016-02-02 17:17:23 -070011634TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11635 VkResult err;
11636 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011637
Karl Schultz6addd812016-02-02 17:17:23 -070011638 m_errorMonitor->SetDesiredFailureMsg(
11639 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011640 "vkCmdResolveImage called with source sample count less than 2.");
11641
Mike Stroyana3082432015-09-25 13:39:21 -060011642 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011643
11644 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011645 VkImage srcImage;
11646 VkImage dstImage;
11647 VkDeviceMemory srcMem;
11648 VkDeviceMemory destMem;
11649 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011650
11651 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011652 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11653 image_create_info.pNext = NULL;
11654 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11655 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11656 image_create_info.extent.width = 32;
11657 image_create_info.extent.height = 1;
11658 image_create_info.extent.depth = 1;
11659 image_create_info.mipLevels = 1;
11660 image_create_info.arrayLayers = 1;
11661 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11662 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11663 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11664 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011665
Karl Schultz6addd812016-02-02 17:17:23 -070011666 err =
11667 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011668 ASSERT_VK_SUCCESS(err);
11669
Karl Schultz6addd812016-02-02 17:17:23 -070011670 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011671
Karl Schultz6addd812016-02-02 17:17:23 -070011672 err =
11673 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011674 ASSERT_VK_SUCCESS(err);
11675
11676 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011677 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011678 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11679 memAlloc.pNext = NULL;
11680 memAlloc.allocationSize = 0;
11681 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011682
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011683 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011684 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011685 pass =
11686 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011687 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011688 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011689 ASSERT_VK_SUCCESS(err);
11690
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011691 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011692 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011693 pass =
11694 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011695 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011696 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011697 ASSERT_VK_SUCCESS(err);
11698
11699 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11700 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011701 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011702 ASSERT_VK_SUCCESS(err);
11703
11704 BeginCommandBuffer();
11705 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011706 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11707 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011708 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011709 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011710 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011711 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011712 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011713 resolveRegion.srcOffset.x = 0;
11714 resolveRegion.srcOffset.y = 0;
11715 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011716 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011717 resolveRegion.dstSubresource.mipLevel = 0;
11718 resolveRegion.dstSubresource.baseArrayLayer = 0;
11719 resolveRegion.dstSubresource.layerCount = 0;
11720 resolveRegion.dstOffset.x = 0;
11721 resolveRegion.dstOffset.y = 0;
11722 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011723 resolveRegion.extent.width = 1;
11724 resolveRegion.extent.height = 1;
11725 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011726 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11727 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011728 EndCommandBuffer();
11729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011730 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011731
Chia-I Wuf7458c52015-10-26 21:10:41 +080011732 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011733 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011734 vkFreeMemory(m_device->device(), srcMem, NULL);
11735 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011736}
11737
Karl Schultz6addd812016-02-02 17:17:23 -070011738TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11739 VkResult err;
11740 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011741
Karl Schultz6addd812016-02-02 17:17:23 -070011742 m_errorMonitor->SetDesiredFailureMsg(
11743 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011744 "vkCmdResolveImage called with dest sample count greater than 1.");
11745
Mike Stroyana3082432015-09-25 13:39:21 -060011746 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011747
Chris Forbesa7530692016-05-08 12:35:39 +120011748 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011749 VkImage srcImage;
11750 VkImage dstImage;
11751 VkDeviceMemory srcMem;
11752 VkDeviceMemory destMem;
11753 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011754
11755 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011756 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11757 image_create_info.pNext = NULL;
11758 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11759 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11760 image_create_info.extent.width = 32;
11761 image_create_info.extent.height = 1;
11762 image_create_info.extent.depth = 1;
11763 image_create_info.mipLevels = 1;
11764 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120011765 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070011766 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11767 // Note: Some implementations expect color attachment usage for any
11768 // multisample surface
11769 image_create_info.usage =
11770 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11771 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011772
Karl Schultz6addd812016-02-02 17:17:23 -070011773 err =
11774 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011775 ASSERT_VK_SUCCESS(err);
11776
Karl Schultz6addd812016-02-02 17:17:23 -070011777 // Note: Some implementations expect color attachment usage for any
11778 // multisample surface
11779 image_create_info.usage =
11780 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011781
Karl Schultz6addd812016-02-02 17:17:23 -070011782 err =
11783 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011784 ASSERT_VK_SUCCESS(err);
11785
11786 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011787 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011788 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11789 memAlloc.pNext = NULL;
11790 memAlloc.allocationSize = 0;
11791 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011792
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011793 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011794 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011795 pass =
11796 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011797 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011798 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011799 ASSERT_VK_SUCCESS(err);
11800
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011801 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011802 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011803 pass =
11804 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011805 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011806 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011807 ASSERT_VK_SUCCESS(err);
11808
11809 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11810 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011811 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011812 ASSERT_VK_SUCCESS(err);
11813
11814 BeginCommandBuffer();
11815 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011816 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11817 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011818 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011819 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011820 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011821 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011822 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011823 resolveRegion.srcOffset.x = 0;
11824 resolveRegion.srcOffset.y = 0;
11825 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011826 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011827 resolveRegion.dstSubresource.mipLevel = 0;
11828 resolveRegion.dstSubresource.baseArrayLayer = 0;
11829 resolveRegion.dstSubresource.layerCount = 0;
11830 resolveRegion.dstOffset.x = 0;
11831 resolveRegion.dstOffset.y = 0;
11832 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011833 resolveRegion.extent.width = 1;
11834 resolveRegion.extent.height = 1;
11835 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011836 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11837 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011838 EndCommandBuffer();
11839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011840 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011841
Chia-I Wuf7458c52015-10-26 21:10:41 +080011842 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011843 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011844 vkFreeMemory(m_device->device(), srcMem, NULL);
11845 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011846}
11847
Karl Schultz6addd812016-02-02 17:17:23 -070011848TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
11849 VkResult err;
11850 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011851
Karl Schultz6addd812016-02-02 17:17:23 -070011852 m_errorMonitor->SetDesiredFailureMsg(
11853 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011854 "vkCmdResolveImage called with unmatched source and dest formats.");
11855
Mike Stroyana3082432015-09-25 13:39:21 -060011856 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011857
11858 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011859 VkImage srcImage;
11860 VkImage dstImage;
11861 VkDeviceMemory srcMem;
11862 VkDeviceMemory destMem;
11863 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011864
11865 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011866 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11867 image_create_info.pNext = NULL;
11868 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11869 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11870 image_create_info.extent.width = 32;
11871 image_create_info.extent.height = 1;
11872 image_create_info.extent.depth = 1;
11873 image_create_info.mipLevels = 1;
11874 image_create_info.arrayLayers = 1;
11875 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11876 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11877 // Note: Some implementations expect color attachment usage for any
11878 // multisample surface
11879 image_create_info.usage =
11880 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11881 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011882
Karl Schultz6addd812016-02-02 17:17:23 -070011883 err =
11884 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011885 ASSERT_VK_SUCCESS(err);
11886
Karl Schultz6addd812016-02-02 17:17:23 -070011887 // Set format to something other than source image
11888 image_create_info.format = VK_FORMAT_R32_SFLOAT;
11889 // Note: Some implementations expect color attachment usage for any
11890 // multisample surface
11891 image_create_info.usage =
11892 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11893 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011894
Karl Schultz6addd812016-02-02 17:17:23 -070011895 err =
11896 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011897 ASSERT_VK_SUCCESS(err);
11898
11899 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011900 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011901 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11902 memAlloc.pNext = NULL;
11903 memAlloc.allocationSize = 0;
11904 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011905
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011906 vkGetImageMemoryRequirements(m_device->device(), srcImage, &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, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011912 ASSERT_VK_SUCCESS(err);
11913
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011914 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011915 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011916 pass =
11917 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011918 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011919 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011920 ASSERT_VK_SUCCESS(err);
11921
11922 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11923 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011924 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011925 ASSERT_VK_SUCCESS(err);
11926
11927 BeginCommandBuffer();
11928 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011929 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11930 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011931 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011932 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011933 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011934 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011935 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011936 resolveRegion.srcOffset.x = 0;
11937 resolveRegion.srcOffset.y = 0;
11938 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011939 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011940 resolveRegion.dstSubresource.mipLevel = 0;
11941 resolveRegion.dstSubresource.baseArrayLayer = 0;
11942 resolveRegion.dstSubresource.layerCount = 0;
11943 resolveRegion.dstOffset.x = 0;
11944 resolveRegion.dstOffset.y = 0;
11945 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011946 resolveRegion.extent.width = 1;
11947 resolveRegion.extent.height = 1;
11948 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011949 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11950 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011951 EndCommandBuffer();
11952
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011953 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011954
Chia-I Wuf7458c52015-10-26 21:10:41 +080011955 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011956 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011957 vkFreeMemory(m_device->device(), srcMem, NULL);
11958 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011959}
11960
Karl Schultz6addd812016-02-02 17:17:23 -070011961TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11962 VkResult err;
11963 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011964
Karl Schultz6addd812016-02-02 17:17:23 -070011965 m_errorMonitor->SetDesiredFailureMsg(
11966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011967 "vkCmdResolveImage called with unmatched source and dest image types.");
11968
Mike Stroyana3082432015-09-25 13:39:21 -060011969 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011970
11971 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011972 VkImage srcImage;
11973 VkImage dstImage;
11974 VkDeviceMemory srcMem;
11975 VkDeviceMemory destMem;
11976 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011977
11978 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011979 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11980 image_create_info.pNext = NULL;
11981 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11982 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11983 image_create_info.extent.width = 32;
11984 image_create_info.extent.height = 1;
11985 image_create_info.extent.depth = 1;
11986 image_create_info.mipLevels = 1;
11987 image_create_info.arrayLayers = 1;
11988 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11989 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11990 // Note: Some implementations expect color attachment usage for any
11991 // multisample surface
11992 image_create_info.usage =
11993 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11994 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011995
Karl Schultz6addd812016-02-02 17:17:23 -070011996 err =
11997 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011998 ASSERT_VK_SUCCESS(err);
11999
Karl Schultz6addd812016-02-02 17:17:23 -070012000 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12001 // Note: Some implementations expect color attachment usage for any
12002 // multisample surface
12003 image_create_info.usage =
12004 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12005 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012006
Karl Schultz6addd812016-02-02 17:17:23 -070012007 err =
12008 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012009 ASSERT_VK_SUCCESS(err);
12010
12011 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012012 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012013 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12014 memAlloc.pNext = NULL;
12015 memAlloc.allocationSize = 0;
12016 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012017
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012018 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012019 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012020 pass =
12021 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012022 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012023 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012024 ASSERT_VK_SUCCESS(err);
12025
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012026 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012027 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012028 pass =
12029 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012030 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012031 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012032 ASSERT_VK_SUCCESS(err);
12033
12034 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12035 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012036 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012037 ASSERT_VK_SUCCESS(err);
12038
12039 BeginCommandBuffer();
12040 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012041 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12042 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012043 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012044 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012045 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012046 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012047 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012048 resolveRegion.srcOffset.x = 0;
12049 resolveRegion.srcOffset.y = 0;
12050 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012051 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012052 resolveRegion.dstSubresource.mipLevel = 0;
12053 resolveRegion.dstSubresource.baseArrayLayer = 0;
12054 resolveRegion.dstSubresource.layerCount = 0;
12055 resolveRegion.dstOffset.x = 0;
12056 resolveRegion.dstOffset.y = 0;
12057 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012058 resolveRegion.extent.width = 1;
12059 resolveRegion.extent.height = 1;
12060 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012061 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12062 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012063 EndCommandBuffer();
12064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012065 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012066
Chia-I Wuf7458c52015-10-26 21:10:41 +080012067 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012068 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012069 vkFreeMemory(m_device->device(), srcMem, NULL);
12070 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012071}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012072
Karl Schultz6addd812016-02-02 17:17:23 -070012073TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012074 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012075 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12076 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012077 // The image format check comes 2nd in validation so we trigger it first,
12078 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012079 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012080
Karl Schultz6addd812016-02-02 17:17:23 -070012081 m_errorMonitor->SetDesiredFailureMsg(
12082 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012083 "Combination depth/stencil image formats can have only the ");
12084
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012085 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012086
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012087 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012088 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12089 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012090
12091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12093 ds_pool_ci.pNext = NULL;
12094 ds_pool_ci.maxSets = 1;
12095 ds_pool_ci.poolSizeCount = 1;
12096 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012097
12098 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012099 err =
12100 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012101 ASSERT_VK_SUCCESS(err);
12102
12103 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012104 dsl_binding.binding = 0;
12105 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12106 dsl_binding.descriptorCount = 1;
12107 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12108 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012109
12110 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012111 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12112 ds_layout_ci.pNext = NULL;
12113 ds_layout_ci.bindingCount = 1;
12114 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012115 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012116 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12117 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012118 ASSERT_VK_SUCCESS(err);
12119
12120 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012121 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012122 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012123 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012124 alloc_info.descriptorPool = ds_pool;
12125 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012126 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12127 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012128 ASSERT_VK_SUCCESS(err);
12129
Karl Schultz6addd812016-02-02 17:17:23 -070012130 VkImage image_bad;
12131 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012132 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012133 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012134 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012135 const int32_t tex_width = 32;
12136 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012137
12138 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012139 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12140 image_create_info.pNext = NULL;
12141 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12142 image_create_info.format = tex_format_bad;
12143 image_create_info.extent.width = tex_width;
12144 image_create_info.extent.height = tex_height;
12145 image_create_info.extent.depth = 1;
12146 image_create_info.mipLevels = 1;
12147 image_create_info.arrayLayers = 1;
12148 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12149 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12150 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12151 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12152 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012153
Karl Schultz6addd812016-02-02 17:17:23 -070012154 err =
12155 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012156 ASSERT_VK_SUCCESS(err);
12157 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012158 image_create_info.usage =
12159 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12160 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12161 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012162 ASSERT_VK_SUCCESS(err);
12163
12164 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012165 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12166 image_view_create_info.image = image_bad;
12167 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12168 image_view_create_info.format = tex_format_bad;
12169 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12170 image_view_create_info.subresourceRange.baseMipLevel = 0;
12171 image_view_create_info.subresourceRange.layerCount = 1;
12172 image_view_create_info.subresourceRange.levelCount = 1;
12173 image_view_create_info.subresourceRange.aspectMask =
12174 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012175
12176 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012177 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12178 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012179
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012180 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012181
Chia-I Wuf7458c52015-10-26 21:10:41 +080012182 vkDestroyImage(m_device->device(), image_bad, NULL);
12183 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012186}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012187
12188TEST_F(VkLayerTest, ClearImageErrors) {
12189 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12190 "ClearDepthStencilImage with a color image.");
12191
12192 ASSERT_NO_FATAL_FAILURE(InitState());
12193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12194
12195 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12196 BeginCommandBuffer();
12197 m_commandBuffer->EndRenderPass();
12198
12199 // Color image
12200 VkClearColorValue clear_color;
12201 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12203 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12204 const int32_t img_width = 32;
12205 const int32_t img_height = 32;
12206 VkImageCreateInfo image_create_info = {};
12207 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12208 image_create_info.pNext = NULL;
12209 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12210 image_create_info.format = color_format;
12211 image_create_info.extent.width = img_width;
12212 image_create_info.extent.height = img_height;
12213 image_create_info.extent.depth = 1;
12214 image_create_info.mipLevels = 1;
12215 image_create_info.arrayLayers = 1;
12216 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12217 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12218 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12219
12220 vk_testing::Image color_image;
12221 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12222 reqs);
12223
12224 const VkImageSubresourceRange color_range =
12225 vk_testing::Image::subresource_range(image_create_info,
12226 VK_IMAGE_ASPECT_COLOR_BIT);
12227
12228 // Depth/Stencil image
12229 VkClearDepthStencilValue clear_value = {0};
12230 reqs = 0; // don't need HOST_VISIBLE DS image
12231 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12232 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12233 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12234 ds_image_create_info.extent.width = 64;
12235 ds_image_create_info.extent.height = 64;
12236 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12237 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12238
12239 vk_testing::Image ds_image;
12240 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12241 reqs);
12242
12243 const VkImageSubresourceRange ds_range =
12244 vk_testing::Image::subresource_range(ds_image_create_info,
12245 VK_IMAGE_ASPECT_DEPTH_BIT);
12246
12247 m_errorMonitor->SetDesiredFailureMsg(
12248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12249 "vkCmdClearColorImage called with depth/stencil image.");
12250
12251 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12252 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12253 &color_range);
12254
12255 m_errorMonitor->VerifyFound();
12256
Tony Barbour26434b92016-06-02 09:43:50 -060012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12258 "vkCmdClearColorImage called with "
12259 "image created without "
12260 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12261
12262 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12263 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12264 &color_range);
12265
12266 m_errorMonitor->VerifyFound();
12267
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012268 // Call CmdClearDepthStencilImage with color image
12269 m_errorMonitor->SetDesiredFailureMsg(
12270 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12271 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12272
12273 vkCmdClearDepthStencilImage(
12274 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12275 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12276 &ds_range);
12277
12278 m_errorMonitor->VerifyFound();
12279}
Tobin Ehliscde08892015-09-22 10:11:37 -060012280#endif // IMAGE_TESTS
12281
Tony Barbour300a6082015-04-07 13:44:53 -060012282int main(int argc, char **argv) {
12283 int result;
12284
Cody Northrop8e54a402016-03-08 22:25:52 -070012285#ifdef ANDROID
12286 int vulkanSupport = InitVulkan();
12287 if (vulkanSupport == 0)
12288 return 1;
12289#endif
12290
Tony Barbour300a6082015-04-07 13:44:53 -060012291 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012292 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012293
12294 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12295
12296 result = RUN_ALL_TESTS();
12297
Tony Barbour6918cd52015-04-09 12:58:51 -060012298 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012299 return result;
12300}