blob: 8ed1e4457e53e438135aece818448aabae262e5b [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001424 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001425 mmr.memory = mem;
1426 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1427 m_errorMonitor->SetDesiredFailureMsg(
1428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1429 ") is less than Memory Object's offset (");
1430 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1431 m_errorMonitor->VerifyFound();
1432 // Now flush range that oversteps mapped range
1433 vkUnmapMemory(m_device->device(), mem);
1434 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1435 ASSERT_VK_SUCCESS(err);
1436 mmr.offset = 16;
1437 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1438 m_errorMonitor->SetDesiredFailureMsg(
1439 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1440 ") exceeds the Memory Object's upper-bound (");
1441 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1442 m_errorMonitor->VerifyFound();
1443
1444 pass =
1445 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1446 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1447 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1448 if (!pass) {
1449 vkFreeMemory(m_device->device(), mem, NULL);
1450 vkDestroyBuffer(m_device->device(), buffer, NULL);
1451 return;
1452 }
1453 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1454 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1455
1456 vkDestroyBuffer(m_device->device(), buffer, NULL);
1457 vkFreeMemory(m_device->device(), mem, NULL);
1458}
1459
Ian Elliott1c32c772016-04-28 14:47:13 -06001460TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1461 VkResult err;
1462 bool pass;
1463
Ian Elliott489eec02016-05-05 14:12:44 -06001464// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1465// following declaration (which is temporarily being moved below):
1466// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001467 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1468 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1469 uint32_t swapchain_image_count = 0;
1470// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1471 uint32_t image_index = 0;
1472// VkPresentInfoKHR present_info = {};
1473
1474 ASSERT_NO_FATAL_FAILURE(InitState());
1475
Ian Elliott3f06ce52016-04-29 14:46:21 -06001476#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1477#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1478 // Use the functions from the VK_KHR_android_surface extension without
1479 // enabling that extension:
1480
1481 // Create a surface:
1482 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483 m_errorMonitor->SetDesiredFailureMsg(
1484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1485 "extension was not enabled for this");
1486 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1487 &surface);
1488 pass = (err != VK_SUCCESS);
1489 ASSERT_TRUE(pass);
1490 m_errorMonitor->VerifyFound();
1491#endif // VK_USE_PLATFORM_ANDROID_KHR
1492
1493
1494#if defined(VK_USE_PLATFORM_MIR_KHR)
1495 // Use the functions from the VK_KHR_mir_surface extension without enabling
1496 // that extension:
1497
1498 // Create a surface:
1499 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001500 m_errorMonitor->SetDesiredFailureMsg(
1501 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1502 "extension was not enabled for this");
1503 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1504 pass = (err != VK_SUCCESS);
1505 ASSERT_TRUE(pass);
1506 m_errorMonitor->VerifyFound();
1507
1508 // Tell whether an mir_connection supports presentation:
1509 MirConnection *mir_connection = NULL;
1510 m_errorMonitor->SetDesiredFailureMsg(
1511 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1512 "extension was not enabled for this");
1513 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1514 visual_id);
1515 m_errorMonitor->VerifyFound();
1516#endif // VK_USE_PLATFORM_MIR_KHR
1517
1518
1519#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1520 // Use the functions from the VK_KHR_wayland_surface extension without
1521 // enabling that extension:
1522
1523 // Create a surface:
1524 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001525 m_errorMonitor->SetDesiredFailureMsg(
1526 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1527 "extension was not enabled for this");
1528 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1529 &surface);
1530 pass = (err != VK_SUCCESS);
1531 ASSERT_TRUE(pass);
1532 m_errorMonitor->VerifyFound();
1533
1534 // Tell whether an wayland_display supports presentation:
1535 struct wl_display wayland_display = {};
1536 m_errorMonitor->SetDesiredFailureMsg(
1537 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1538 "extension was not enabled for this");
1539 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1540 &wayland_display);
1541 m_errorMonitor->VerifyFound();
1542#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001543#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544
1545
1546#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001547// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1548// TO NON-LINUX PLATFORMS:
1549VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 // Use the functions from the VK_KHR_win32_surface extension without
1551 // enabling that extension:
1552
1553 // Create a surface:
1554 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555 m_errorMonitor->SetDesiredFailureMsg(
1556 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1557 "extension was not enabled for this");
1558 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1559 &surface);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001565 m_errorMonitor->SetDesiredFailureMsg(
1566 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1567 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001568 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001570// Set this (for now, until all platforms are supported and tested):
1571#define NEED_TO_TEST_THIS_ON_PLATFORM
1572#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573
1574
Ian Elliott1c32c772016-04-28 14:47:13 -06001575#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001576// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1577// TO NON-LINUX PLATFORMS:
1578VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001579 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1580 // that extension:
1581
1582 // Create a surface:
1583 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 m_errorMonitor->SetDesiredFailureMsg(
1585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1586 "extension was not enabled for this");
1587 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1588 pass = (err != VK_SUCCESS);
1589 ASSERT_TRUE(pass);
1590 m_errorMonitor->VerifyFound();
1591
1592 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001594 xcb_visualid_t visual_id = 0;
1595 m_errorMonitor->SetDesiredFailureMsg(
1596 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1597 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001599 visual_id);
1600 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001601// Set this (for now, until all platforms are supported and tested):
1602#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001603#endif // VK_USE_PLATFORM_XCB_KHR
1604
1605
Ian Elliott12630812016-04-29 14:35:43 -06001606#if defined(VK_USE_PLATFORM_XLIB_KHR)
1607 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1608 // that extension:
1609
1610 // Create a surface:
1611 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001612 m_errorMonitor->SetDesiredFailureMsg(
1613 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1614 "extension was not enabled for this");
1615 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1616 pass = (err != VK_SUCCESS);
1617 ASSERT_TRUE(pass);
1618 m_errorMonitor->VerifyFound();
1619
1620 // Tell whether an Xlib VisualID supports presentation:
1621 Display *dpy = NULL;
1622 VisualID visual = 0;
1623 m_errorMonitor->SetDesiredFailureMsg(
1624 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1625 "extension was not enabled for this");
1626 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1627 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001628// Set this (for now, until all platforms are supported and tested):
1629#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001630#endif // VK_USE_PLATFORM_XLIB_KHR
1631
1632
Ian Elliott1c32c772016-04-28 14:47:13 -06001633 // Use the functions from the VK_KHR_surface extension without enabling
1634 // that extension:
1635
Ian Elliott489eec02016-05-05 14:12:44 -06001636#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 // Destroy a surface:
1638 m_errorMonitor->SetDesiredFailureMsg(
1639 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1640 "extension was not enabled for this");
1641 vkDestroySurfaceKHR(instance(), surface, NULL);
1642 m_errorMonitor->VerifyFound();
1643
1644 // Check if surface supports presentation:
1645 VkBool32 supported = false;
1646 m_errorMonitor->SetDesiredFailureMsg(
1647 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1648 "extension was not enabled for this");
1649 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Check surface capabilities:
1655 VkSurfaceCapabilitiesKHR capabilities = {};
1656 m_errorMonitor->SetDesiredFailureMsg(
1657 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1658 "extension was not enabled for this");
1659 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1660 &capabilities);
1661 pass = (err != VK_SUCCESS);
1662 ASSERT_TRUE(pass);
1663 m_errorMonitor->VerifyFound();
1664
1665 // Check surface formats:
1666 uint32_t format_count = 0;
1667 VkSurfaceFormatKHR *formats = NULL;
1668 m_errorMonitor->SetDesiredFailureMsg(
1669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1670 "extension was not enabled for this");
1671 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1672 &format_count, formats);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Check surface present modes:
1678 uint32_t present_mode_count = 0;
1679 VkSurfaceFormatKHR *present_modes = NULL;
1680 m_errorMonitor->SetDesiredFailureMsg(
1681 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "extension was not enabled for this");
1683 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1684 &present_mode_count, present_modes);
1685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001688#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001689
1690
1691 // Use the functions from the VK_KHR_swapchain extension without enabling
1692 // that extension:
1693
1694 // Create a swapchain:
1695 m_errorMonitor->SetDesiredFailureMsg(
1696 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1697 "extension was not enabled for this");
1698 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1699 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001700 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1701 NULL, &swapchain);
1702 pass = (err != VK_SUCCESS);
1703 ASSERT_TRUE(pass);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Get the images from the swapchain:
1707 m_errorMonitor->SetDesiredFailureMsg(
1708 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1709 "extension was not enabled for this");
1710 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1711 &swapchain_image_count, NULL);
1712 pass = (err != VK_SUCCESS);
1713 ASSERT_TRUE(pass);
1714 m_errorMonitor->VerifyFound();
1715
1716 // Try to acquire an image:
1717 m_errorMonitor->SetDesiredFailureMsg(
1718 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1719 "extension was not enabled for this");
1720 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1721 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1722 pass = (err != VK_SUCCESS);
1723 ASSERT_TRUE(pass);
1724 m_errorMonitor->VerifyFound();
1725
1726 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001727 //
1728 // NOTE: Currently can't test this because a real swapchain is needed (as
1729 // opposed to the fake one we created) in order for the layer to lookup the
1730 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001731
1732 // Destroy the swapchain:
1733 m_errorMonitor->SetDesiredFailureMsg(
1734 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1735 "extension was not enabled for this");
1736 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1737 m_errorMonitor->VerifyFound();
1738}
1739
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001741
Dustin Graves6c6d8982016-05-17 10:09:21 -06001742#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001745 VkResult err;
1746 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001747 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1748 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001749 // uint32_t swapchain_image_count = 0;
1750 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1751 // uint32_t image_index = 0;
1752 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753
1754 ASSERT_NO_FATAL_FAILURE(InitState());
1755
1756 // Use the create function from one of the VK_KHR_*_surface extension in
1757 // order to create a surface, testing all known errors in the process,
1758 // before successfully creating a surface:
1759 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1761 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001762 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1763 pass = (err != VK_SUCCESS);
1764 ASSERT_TRUE(pass);
1765 m_errorMonitor->VerifyFound();
1766
1767 // Next, try to create a surface with the wrong
1768 // VkXcbSurfaceCreateInfoKHR::sType:
1769 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1770 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1772 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1774 pass = (err != VK_SUCCESS);
1775 ASSERT_TRUE(pass);
1776 m_errorMonitor->VerifyFound();
1777
Ian Elliott2c1daf52016-05-12 09:41:46 -06001778 // Create a native window, and then correctly create a surface:
1779 xcb_connection_t *connection;
1780 xcb_screen_t *screen;
1781 xcb_window_t xcb_window;
1782 xcb_intern_atom_reply_t *atom_wm_delete_window;
1783
1784 const xcb_setup_t *setup;
1785 xcb_screen_iterator_t iter;
1786 int scr;
1787 uint32_t value_mask, value_list[32];
1788 int width = 1;
1789 int height = 1;
1790
1791 connection = xcb_connect(NULL, &scr);
1792 ASSERT_TRUE(connection != NULL);
1793 setup = xcb_get_setup(connection);
1794 iter = xcb_setup_roots_iterator(setup);
1795 while (scr-- > 0)
1796 xcb_screen_next(&iter);
1797 screen = iter.data;
1798
1799 xcb_window = xcb_generate_id(connection);
1800
1801 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1802 value_list[0] = screen->black_pixel;
1803 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1804 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1805
1806 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1807 screen->root, 0, 0, width, height, 0,
1808 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1809 value_mask, value_list);
1810
1811 /* Magic code that will send notification when window is destroyed */
1812 xcb_intern_atom_cookie_t cookie =
1813 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1814 xcb_intern_atom_reply_t *reply =
1815 xcb_intern_atom_reply(connection, cookie, 0);
1816
1817 xcb_intern_atom_cookie_t cookie2 =
1818 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001819 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001820 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1821 (*reply).atom, 4, 32, 1,
1822 &(*atom_wm_delete_window).atom);
1823 free(reply);
1824
1825 xcb_map_window(connection, xcb_window);
1826
1827 // Force the x/y coordinates to 100,100 results are identical in consecutive
1828 // runs
1829 const uint32_t coords[] = {100, 100};
1830 xcb_configure_window(connection, xcb_window,
1831 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1832
Ian Elliott2c1daf52016-05-12 09:41:46 -06001833 // Finally, try to correctly create a surface:
1834 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1835 xcb_create_info.pNext = NULL;
1836 xcb_create_info.flags = 0;
1837 xcb_create_info.connection = connection;
1838 xcb_create_info.window = xcb_window;
1839 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1840 pass = (err == VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842
Ian Elliott2c1daf52016-05-12 09:41:46 -06001843 // Check if surface supports presentation:
1844
1845 // 1st, do so without having queried the queue families:
1846 VkBool32 supported = false;
1847 // TODO: Get the following error to come out:
1848 m_errorMonitor->SetDesiredFailureMsg(
1849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1850 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1851 "function");
1852 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1853 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001854 // ASSERT_TRUE(pass);
1855 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001856
1857 // Next, query a queue family index that's too large:
1858 m_errorMonitor->SetDesiredFailureMsg(
1859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1860 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001861 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1862 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001863 pass = (err != VK_SUCCESS);
1864 ASSERT_TRUE(pass);
1865 m_errorMonitor->VerifyFound();
1866
1867 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001868 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1869 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001870 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1871 pass = (err == VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873
Ian Elliott2c1daf52016-05-12 09:41:46 -06001874 // Before proceeding, try to create a swapchain without having called
1875 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1876 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1877 swapchain_create_info.pNext = NULL;
1878 swapchain_create_info.flags = 0;
1879 m_errorMonitor->SetDesiredFailureMsg(
1880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1881 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001882 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1883 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001884 pass = (err != VK_SUCCESS);
1885 ASSERT_TRUE(pass);
1886 m_errorMonitor->VerifyFound();
1887
Ian Elliott2c1daf52016-05-12 09:41:46 -06001888 // Get the surface capabilities:
1889 VkSurfaceCapabilitiesKHR surface_capabilities;
1890
1891 // Do so correctly (only error logged by this entrypoint is if the
1892 // extension isn't enabled):
1893 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1894 &surface_capabilities);
1895 pass = (err == VK_SUCCESS);
1896 ASSERT_TRUE(pass);
1897
Ian Elliott2c1daf52016-05-12 09:41:46 -06001898 // Get the surface formats:
1899 uint32_t surface_format_count;
1900
1901 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1903 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001904 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1905 pass = (err == VK_SUCCESS);
1906 ASSERT_TRUE(pass);
1907 m_errorMonitor->VerifyFound();
1908
1909 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1910 // correctly done a 1st try (to get the count):
1911 m_errorMonitor->SetDesiredFailureMsg(
1912 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1913 "but no prior positive value has been seen for");
1914 surface_format_count = 0;
1915 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001916 gpu(), surface, &surface_format_count,
1917 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001918 pass = (err == VK_SUCCESS);
1919 ASSERT_TRUE(pass);
1920 m_errorMonitor->VerifyFound();
1921
1922 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001923 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1924 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001925 pass = (err == VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927
1928 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1930 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001931
1932 // Next, do a 2nd try with surface_format_count being set too high:
1933 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1935 "that is greater than the value");
1936 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001937 surface_formats);
1938 pass = (err == VK_SUCCESS);
1939 ASSERT_TRUE(pass);
1940 m_errorMonitor->VerifyFound();
1941
1942 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001943 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err == VK_SUCCESS);
1946 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001947 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001948 surface_formats);
1949 pass = (err == VK_SUCCESS);
1950 ASSERT_TRUE(pass);
1951
Ian Elliott2c1daf52016-05-12 09:41:46 -06001952 // Get the surface present modes:
1953 uint32_t surface_present_mode_count;
1954
1955 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1957 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001958 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1959 pass = (err == VK_SUCCESS);
1960 ASSERT_TRUE(pass);
1961 m_errorMonitor->VerifyFound();
1962
1963 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1964 // correctly done a 1st try (to get the count):
1965 m_errorMonitor->SetDesiredFailureMsg(
1966 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1967 "but no prior positive value has been seen for");
1968 surface_present_mode_count = 0;
1969 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001970 gpu(), surface, &surface_present_mode_count,
1971 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001972 pass = (err == VK_SUCCESS);
1973 ASSERT_TRUE(pass);
1974 m_errorMonitor->VerifyFound();
1975
1976 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001977 vkGetPhysicalDeviceSurfacePresentModesKHR(
1978 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001979 pass = (err == VK_SUCCESS);
1980 ASSERT_TRUE(pass);
1981
1982 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001983 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1984 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001985
1986 // Next, do a 2nd try with surface_format_count being set too high:
1987 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1989 "that is greater than the value");
1990 vkGetPhysicalDeviceSurfacePresentModesKHR(
1991 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001992 pass = (err == VK_SUCCESS);
1993 ASSERT_TRUE(pass);
1994 m_errorMonitor->VerifyFound();
1995
1996 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 vkGetPhysicalDeviceSurfacePresentModesKHR(
1998 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 pass = (err == VK_SUCCESS);
2000 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002001 vkGetPhysicalDeviceSurfacePresentModesKHR(
2002 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002003 pass = (err == VK_SUCCESS);
2004 ASSERT_TRUE(pass);
2005
Ian Elliott2c1daf52016-05-12 09:41:46 -06002006 // Create a swapchain:
2007
2008 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2010 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002011 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2012 pass = (err != VK_SUCCESS);
2013 ASSERT_TRUE(pass);
2014 m_errorMonitor->VerifyFound();
2015
2016 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2017 // sType:
2018 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2020 "called with the wrong value for");
2021 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2022 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002023 pass = (err != VK_SUCCESS);
2024 ASSERT_TRUE(pass);
2025 m_errorMonitor->VerifyFound();
2026
2027 // Next, call with a NULL swapchain pointer:
2028 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2029 swapchain_create_info.pNext = NULL;
2030 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2032 "called with NULL pointer");
2033 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2034 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002035 pass = (err != VK_SUCCESS);
2036 ASSERT_TRUE(pass);
2037 m_errorMonitor->VerifyFound();
2038
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002039 // TODO: Enhance swapchain layer so that
2040 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002041
2042 // Next, call with a queue family index that's too large:
2043 uint32_t queueFamilyIndex[2] = {100000, 0};
2044 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2045 swapchain_create_info.queueFamilyIndexCount = 2;
2046 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2047 m_errorMonitor->SetDesiredFailureMsg(
2048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2049 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002050 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2051 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002052 pass = (err != VK_SUCCESS);
2053 ASSERT_TRUE(pass);
2054 m_errorMonitor->VerifyFound();
2055
2056 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2057 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2058 swapchain_create_info.queueFamilyIndexCount = 1;
2059 m_errorMonitor->SetDesiredFailureMsg(
2060 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2061 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2062 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002063 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2064 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002065 pass = (err != VK_SUCCESS);
2066 ASSERT_TRUE(pass);
2067 m_errorMonitor->VerifyFound();
2068
2069 // Next, call with an invalid imageSharingMode:
2070 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2071 swapchain_create_info.queueFamilyIndexCount = 1;
2072 m_errorMonitor->SetDesiredFailureMsg(
2073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2074 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002075 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2076 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002077 pass = (err != VK_SUCCESS);
2078 ASSERT_TRUE(pass);
2079 m_errorMonitor->VerifyFound();
2080 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002081 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2082 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002083 swapchain_create_info.queueFamilyIndexCount = 0;
2084 queueFamilyIndex[0] = 0;
2085 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2086
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002087 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002091 // Destroy the swapchain:
2092
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002093 // TODOs:
2094 //
2095 // - Try destroying the device without first destroying the swapchain
2096 //
2097 // - Try destroying the device without first destroying the surface
2098 //
2099 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002100
2101 // Destroy the surface:
2102 vkDestroySurfaceKHR(instance(), surface, NULL);
2103
Ian Elliott2c1daf52016-05-12 09:41:46 -06002104 // Tear down the window:
2105 xcb_destroy_window(connection, xcb_window);
2106 xcb_disconnect(connection);
2107
2108#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002109 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002110#endif // VK_USE_PLATFORM_XCB_KHR
2111}
2112
Karl Schultz6addd812016-02-02 17:17:23 -07002113TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2114 VkResult err;
2115 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 m_errorMonitor->SetDesiredFailureMsg(
2118 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002119 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2120
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002122
2123 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002124 VkImage image;
2125 VkDeviceMemory mem;
2126 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2129 const int32_t tex_width = 32;
2130 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002131
Tony Barboureb254902015-07-15 12:50:33 -06002132 VkImageCreateInfo image_create_info = {};
2133 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002134 image_create_info.pNext = NULL;
2135 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2136 image_create_info.format = tex_format;
2137 image_create_info.extent.width = tex_width;
2138 image_create_info.extent.height = tex_height;
2139 image_create_info.extent.depth = 1;
2140 image_create_info.mipLevels = 1;
2141 image_create_info.arrayLayers = 1;
2142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2143 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2144 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2145 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002146
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002148 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 mem_alloc.pNext = NULL;
2150 mem_alloc.allocationSize = 0;
2151 // Introduce failure, do NOT set memProps to
2152 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2153 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002154
Chia-I Wuf7458c52015-10-26 21:10:41 +08002155 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002156 ASSERT_VK_SUCCESS(err);
2157
Karl Schultz6addd812016-02-02 17:17:23 -07002158 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002159
Mark Lobodzinski23065352015-05-29 09:32:35 -05002160 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002161
Karl Schultz6addd812016-02-02 17:17:23 -07002162 pass =
2163 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2165 if (!pass) { // If we can't find any unmappable memory this test doesn't
2166 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002167 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002168 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002169 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002170
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002171 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002172 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173 ASSERT_VK_SUCCESS(err);
2174
2175 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002176 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002177 ASSERT_VK_SUCCESS(err);
2178
2179 // Map memory as if to initialize the image
2180 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002181 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2182 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002183
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002184 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002185
Chia-I Wuf7458c52015-10-26 21:10:41 +08002186 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002187 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002188}
2189
Karl Schultz6addd812016-02-02 17:17:23 -07002190TEST_F(VkLayerTest, RebindMemory) {
2191 VkResult err;
2192 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002193
Karl Schultz6addd812016-02-02 17:17:23 -07002194 m_errorMonitor->SetDesiredFailureMsg(
2195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002196 "which has already been bound to mem object");
2197
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002199
2200 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002201 VkImage image;
2202 VkDeviceMemory mem1;
2203 VkDeviceMemory mem2;
2204 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002205
Karl Schultz6addd812016-02-02 17:17:23 -07002206 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2207 const int32_t tex_width = 32;
2208 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002209
Tony Barboureb254902015-07-15 12:50:33 -06002210 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2212 image_create_info.pNext = NULL;
2213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2214 image_create_info.format = tex_format;
2215 image_create_info.extent.width = tex_width;
2216 image_create_info.extent.height = tex_height;
2217 image_create_info.extent.depth = 1;
2218 image_create_info.mipLevels = 1;
2219 image_create_info.arrayLayers = 1;
2220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2221 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2222 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2223 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002224
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002225 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002226 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2227 mem_alloc.pNext = NULL;
2228 mem_alloc.allocationSize = 0;
2229 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002230
Karl Schultz6addd812016-02-02 17:17:23 -07002231 // Introduce failure, do NOT set memProps to
2232 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002233 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002234 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002235 ASSERT_VK_SUCCESS(err);
2236
Karl Schultz6addd812016-02-02 17:17:23 -07002237 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002238
2239 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002240 pass =
2241 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002242 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002243
2244 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002245 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002246 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002247 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002248 ASSERT_VK_SUCCESS(err);
2249
2250 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002251 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002252 ASSERT_VK_SUCCESS(err);
2253
Karl Schultz6addd812016-02-02 17:17:23 -07002254 // Introduce validation failure, try to bind a different memory object to
2255 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002256 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002258 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002259
Chia-I Wuf7458c52015-10-26 21:10:41 +08002260 vkDestroyImage(m_device->device(), image, NULL);
2261 vkFreeMemory(m_device->device(), mem1, NULL);
2262 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002263}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002264
Karl Schultz6addd812016-02-02 17:17:23 -07002265TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002266 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002267
Karl Schultz6addd812016-02-02 17:17:23 -07002268 m_errorMonitor->SetDesiredFailureMsg(
2269 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2270 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002271
2272 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002273 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2274 fenceInfo.pNext = NULL;
2275 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002276
Tony Barbour300a6082015-04-07 13:44:53 -06002277 ASSERT_NO_FATAL_FAILURE(InitState());
2278 ASSERT_NO_FATAL_FAILURE(InitViewport());
2279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2280
Tony Barbourfe3351b2015-07-28 10:17:20 -06002281 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002282 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2283 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002284 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002285
2286 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002287
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002288 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002289 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2290 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002291 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002292 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002293 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002294 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002295 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002296 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002297 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002298
2299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002300 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002302 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002303}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002304// This is a positive test. We used to expect error in this case but spec now
2305// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002306TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002307 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002308 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002309 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002310 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2311 fenceInfo.pNext = NULL;
2312
Tony Barbour0b4d9562015-04-09 10:48:04 -06002313 ASSERT_NO_FATAL_FAILURE(InitState());
2314 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002315 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002316 VkResult result = vkResetFences(m_device->device(), 1, fences);
2317 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002318
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002319 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002320}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002321
Chris Forbes18127d12016-06-08 16:52:28 +12002322TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2323{
2324 m_errorMonitor->ExpectSuccess();
2325
2326 ASSERT_NO_FATAL_FAILURE(InitState());
2327 VkResult err;
2328
2329 // Record (empty!) command buffer that can be submitted multiple times
2330 // simultaneously.
2331 VkCommandBufferBeginInfo cbbi = {
2332 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2333 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2334 };
2335 m_commandBuffer->BeginCommandBuffer(&cbbi);
2336 m_commandBuffer->EndCommandBuffer();
2337
2338 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2339 VkFence fence;
2340 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2341 ASSERT_VK_SUCCESS(err);
2342
2343 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2344 VkSemaphore s1, s2;
2345 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2346 ASSERT_VK_SUCCESS(err);
2347 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2348 ASSERT_VK_SUCCESS(err);
2349
2350 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2351 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2352 1, &m_commandBuffer->handle(), 1, &s1 };
2353 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2354 ASSERT_VK_SUCCESS(err);
2355
2356 // Submit CB again, signaling s2.
2357 si.pSignalSemaphores = &s2;
2358 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2359 ASSERT_VK_SUCCESS(err);
2360
2361 // Wait for fence.
2362 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2363 ASSERT_VK_SUCCESS(err);
2364
2365 // CB is still in flight from second submission, but semaphore s1 is no
2366 // longer in flight. delete it.
2367 vkDestroySemaphore(m_device->device(), s1, nullptr);
2368
2369 m_errorMonitor->VerifyNotFound();
2370
2371 // Force device idle and clean up remaining objects
2372 vkDeviceWaitIdle(m_device->device());
2373 vkDestroySemaphore(m_device->device(), s2, nullptr);
2374 vkDestroyFence(m_device->device(), fence, nullptr);
2375}
2376
Tobin Ehlis41376e12015-07-03 08:45:14 -06002377TEST_F(VkLayerTest, InvalidUsageBits)
2378{
Tony Barbourf92621a2016-05-02 14:28:12 -06002379 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002380 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002381 "Initialize buffer with wrong usage then perform copy expecting errors "
2382 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002384 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002385
2386 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002387 VkImageObj image(m_device);
2388 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002389 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002390 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2391 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002392
Tony Barbourf92621a2016-05-02 14:28:12 -06002393 VkImageView dsv;
2394 VkImageViewCreateInfo dsvci = {};
2395 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2396 dsvci.image = image.handle();
2397 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2398 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2399 dsvci.subresourceRange.layerCount = 1;
2400 dsvci.subresourceRange.baseMipLevel = 0;
2401 dsvci.subresourceRange.levelCount = 1;
2402 dsvci.subresourceRange.aspectMask =
2403 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002404
Tony Barbourf92621a2016-05-02 14:28:12 -06002405 // Create a view with depth / stencil aspect for image with different usage
2406 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002407
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002408 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002409
2410 // Initialize buffer with TRANSFER_DST usage
2411 vk_testing::Buffer buffer;
2412 VkMemoryPropertyFlags reqs = 0;
2413 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2414 VkBufferImageCopy region = {};
2415 region.bufferRowLength = 128;
2416 region.bufferImageHeight = 128;
2417 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2418 region.imageSubresource.layerCount = 1;
2419 region.imageExtent.height = 16;
2420 region.imageExtent.width = 16;
2421 region.imageExtent.depth = 1;
2422
2423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2424 "Invalid usage flag for buffer ");
2425 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2426 // TRANSFER_DST
2427 BeginCommandBuffer();
2428 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2429 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2430 1, &region);
2431 m_errorMonitor->VerifyFound();
2432
2433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2434 "Invalid usage flag for image ");
2435 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2436 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2437 1, &region);
2438 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002439}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002440#endif // MEM_TRACKER_TESTS
2441
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002442#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002443
2444TEST_F(VkLayerTest, LeakAnObject) {
2445 VkResult err;
2446
2447 TEST_DESCRIPTION(
2448 "Create a fence and destroy its device without first destroying the fence.");
2449
2450 // Note that we have to create a new device since destroying the
2451 // framework's device causes Teardown() to fail and just calling Teardown
2452 // will destroy the errorMonitor.
2453
2454 m_errorMonitor->SetDesiredFailureMsg(
2455 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2456 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459
2460 const std::vector<VkQueueFamilyProperties> queue_props =
2461 m_device->queue_props;
2462 std::vector<VkDeviceQueueCreateInfo> queue_info;
2463 queue_info.reserve(queue_props.size());
2464 std::vector<std::vector<float>> queue_priorities;
2465 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2466 VkDeviceQueueCreateInfo qi = {};
2467 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2468 qi.pNext = NULL;
2469 qi.queueFamilyIndex = i;
2470 qi.queueCount = queue_props[i].queueCount;
2471 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2472 qi.pQueuePriorities = queue_priorities[i].data();
2473 queue_info.push_back(qi);
2474 }
2475
2476 std::vector<const char *> device_layer_names;
2477 std::vector<const char *> device_extension_names;
2478 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2479 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2480 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2481 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2482 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2483 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2484 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2485
2486 // The sacrificial device object
2487 VkDevice testDevice;
2488 VkDeviceCreateInfo device_create_info = {};
2489 auto features = m_device->phy().features();
2490 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2491 device_create_info.pNext = NULL;
2492 device_create_info.queueCreateInfoCount = queue_info.size();
2493 device_create_info.pQueueCreateInfos = queue_info.data();
2494 device_create_info.enabledLayerCount = device_layer_names.size();
2495 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2496 device_create_info.pEnabledFeatures = &features;
2497 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2498 ASSERT_VK_SUCCESS(err);
2499
2500 VkFence fence;
2501 VkFenceCreateInfo fence_create_info = {};
2502 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2503 fence_create_info.pNext = NULL;
2504 fence_create_info.flags = 0;
2505 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2506 ASSERT_VK_SUCCESS(err);
2507
2508 // Induce failure by not calling vkDestroyFence
2509 vkDestroyDevice(testDevice, NULL);
2510 m_errorMonitor->VerifyFound();
2511}
2512
2513TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2514
2515 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2516 "attempt to delete them from another.");
2517
2518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2519 "FreeCommandBuffers is attempting to free Command Buffer");
2520
2521 VkCommandPool command_pool_one;
2522 VkCommandPool command_pool_two;
2523
2524 VkCommandPoolCreateInfo pool_create_info{};
2525 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2526 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2527 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2528
2529 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2530 &command_pool_one);
2531
2532 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2533 &command_pool_two);
2534
2535 VkCommandBuffer command_buffer[9];
2536 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2537 command_buffer_allocate_info.sType =
2538 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2539 command_buffer_allocate_info.commandPool = command_pool_one;
2540 command_buffer_allocate_info.commandBufferCount = 9;
2541 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2542 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2543 command_buffer);
2544
2545 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2546 &command_buffer[3]);
2547
2548 m_errorMonitor->VerifyFound();
2549
2550 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2551 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2552}
2553
2554TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2555 VkResult err;
2556
2557 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2558 "attempt to delete them from another.");
2559
2560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2561 "FreeDescriptorSets is attempting to free descriptorSet");
2562
2563 ASSERT_NO_FATAL_FAILURE(InitState());
2564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2565
2566 VkDescriptorPoolSize ds_type_count = {};
2567 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2568 ds_type_count.descriptorCount = 1;
2569
2570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2572 ds_pool_ci.pNext = NULL;
2573 ds_pool_ci.flags = 0;
2574 ds_pool_ci.maxSets = 1;
2575 ds_pool_ci.poolSizeCount = 1;
2576 ds_pool_ci.pPoolSizes = &ds_type_count;
2577
2578 VkDescriptorPool ds_pool_one;
2579 err =
2580 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2581 ASSERT_VK_SUCCESS(err);
2582
2583 // Create a second descriptor pool
2584 VkDescriptorPool ds_pool_two;
2585 err =
2586 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2587 ASSERT_VK_SUCCESS(err);
2588
2589 VkDescriptorSetLayoutBinding dsl_binding = {};
2590 dsl_binding.binding = 0;
2591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2592 dsl_binding.descriptorCount = 1;
2593 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2594 dsl_binding.pImmutableSamplers = NULL;
2595
2596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2598 ds_layout_ci.pNext = NULL;
2599 ds_layout_ci.bindingCount = 1;
2600 ds_layout_ci.pBindings = &dsl_binding;
2601
2602 VkDescriptorSetLayout ds_layout;
2603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2604 &ds_layout);
2605 ASSERT_VK_SUCCESS(err);
2606
2607 VkDescriptorSet descriptorSet;
2608 VkDescriptorSetAllocateInfo alloc_info = {};
2609 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2610 alloc_info.descriptorSetCount = 1;
2611 alloc_info.descriptorPool = ds_pool_one;
2612 alloc_info.pSetLayouts = &ds_layout;
2613 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2614 &descriptorSet);
2615 ASSERT_VK_SUCCESS(err);
2616
2617 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2618
2619 m_errorMonitor->VerifyFound();
2620
2621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2622 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2623 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2624}
2625
2626TEST_F(VkLayerTest, CreateUnknownObject) {
2627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2628 "Invalid VkImage Object ");
2629
2630 TEST_DESCRIPTION(
2631 "Pass an invalid image object handle into a Vulkan API call.");
2632
2633 ASSERT_NO_FATAL_FAILURE(InitState());
2634
2635 // Pass bogus handle into GetImageMemoryRequirements
2636 VkMemoryRequirements mem_reqs;
2637 uint64_t fakeImageHandle = 0xCADECADE;
2638 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2639
2640 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2641
2642 m_errorMonitor->VerifyFound();
2643}
2644
Karl Schultz6addd812016-02-02 17:17:23 -07002645TEST_F(VkLayerTest, PipelineNotBound) {
2646 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002647
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002648 TEST_DESCRIPTION(
2649 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2650
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002652 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002653
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002654 ASSERT_NO_FATAL_FAILURE(InitState());
2655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002656
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002657 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002658 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2659 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002660
2661 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002662 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2663 ds_pool_ci.pNext = NULL;
2664 ds_pool_ci.maxSets = 1;
2665 ds_pool_ci.poolSizeCount = 1;
2666 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002667
2668 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002669 err =
2670 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002671 ASSERT_VK_SUCCESS(err);
2672
2673 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002674 dsl_binding.binding = 0;
2675 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2676 dsl_binding.descriptorCount = 1;
2677 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2678 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002679
2680 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002681 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2682 ds_layout_ci.pNext = NULL;
2683 ds_layout_ci.bindingCount = 1;
2684 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002685
2686 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002687 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2688 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002689 ASSERT_VK_SUCCESS(err);
2690
2691 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002692 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002693 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002694 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002695 alloc_info.descriptorPool = ds_pool;
2696 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002697 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2698 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002699 ASSERT_VK_SUCCESS(err);
2700
2701 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002702 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2703 pipeline_layout_ci.pNext = NULL;
2704 pipeline_layout_ci.setLayoutCount = 1;
2705 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002706
2707 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002708 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2709 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002710 ASSERT_VK_SUCCESS(err);
2711
Mark Youngad779052016-01-06 14:26:04 -07002712 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002713
2714 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002715 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2716 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002718 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002719
Chia-I Wuf7458c52015-10-26 21:10:41 +08002720 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002723}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002724#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002725TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2726 VkResult err;
2727
2728 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2729 "during bind[Buffer|Image]Memory time");
2730
2731 m_errorMonitor->SetDesiredFailureMsg(
2732 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2733 "for this object type are not compatible with the memory");
2734
2735 ASSERT_NO_FATAL_FAILURE(InitState());
2736
2737 // Create an image, allocate memory, set a bad typeIndex and then try to
2738 // bind it
2739 VkImage image;
2740 VkDeviceMemory mem;
2741 VkMemoryRequirements mem_reqs;
2742 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2743 const int32_t tex_width = 32;
2744 const int32_t tex_height = 32;
2745
2746 VkImageCreateInfo image_create_info = {};
2747 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2748 image_create_info.pNext = NULL;
2749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2750 image_create_info.format = tex_format;
2751 image_create_info.extent.width = tex_width;
2752 image_create_info.extent.height = tex_height;
2753 image_create_info.extent.depth = 1;
2754 image_create_info.mipLevels = 1;
2755 image_create_info.arrayLayers = 1;
2756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2757 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2758 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2759 image_create_info.flags = 0;
2760
2761 VkMemoryAllocateInfo mem_alloc = {};
2762 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2763 mem_alloc.pNext = NULL;
2764 mem_alloc.allocationSize = 0;
2765 mem_alloc.memoryTypeIndex = 0;
2766
2767 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2768 ASSERT_VK_SUCCESS(err);
2769
2770 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2771 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002772 // TODO : This is not an ideal way to cause the error and triggers a segF
2773 // on at least one android driver when attempting to Allocate the memory.
2774 // That segF may or may not be a driver bug, but really what we want to do
2775 // here is find a device-supported memory type that is also not supported
2776 // for the particular image we're binding the memory too. If no such
2777 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002778 // Introduce Failure, select likely invalid TypeIndex
2779 mem_alloc.memoryTypeIndex = 31;
2780
2781 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2782 ASSERT_VK_SUCCESS(err);
2783
2784 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2785 (void)err;
2786
2787 m_errorMonitor->VerifyFound();
2788
2789 vkDestroyImage(m_device->device(), image, NULL);
2790 vkFreeMemory(m_device->device(), mem, NULL);
2791}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002792#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002793TEST_F(VkLayerTest, BindInvalidMemory) {
2794 VkResult err;
2795 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002796
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002798 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002799
Tobin Ehlisec598302015-09-15 15:02:17 -06002800 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002801
2802 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002803 VkImage image;
2804 VkDeviceMemory mem;
2805 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002806
Karl Schultz6addd812016-02-02 17:17:23 -07002807 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2808 const int32_t tex_width = 32;
2809 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002810
2811 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002812 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2813 image_create_info.pNext = NULL;
2814 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2815 image_create_info.format = tex_format;
2816 image_create_info.extent.width = tex_width;
2817 image_create_info.extent.height = tex_height;
2818 image_create_info.extent.depth = 1;
2819 image_create_info.mipLevels = 1;
2820 image_create_info.arrayLayers = 1;
2821 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2822 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2823 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2824 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002825
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002826 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002827 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2828 mem_alloc.pNext = NULL;
2829 mem_alloc.allocationSize = 0;
2830 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002831
Chia-I Wuf7458c52015-10-26 21:10:41 +08002832 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002833 ASSERT_VK_SUCCESS(err);
2834
Karl Schultz6addd812016-02-02 17:17:23 -07002835 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002836
2837 mem_alloc.allocationSize = mem_reqs.size;
2838
Karl Schultz6addd812016-02-02 17:17:23 -07002839 pass =
2840 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002841 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002842
2843 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002844 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002845 ASSERT_VK_SUCCESS(err);
2846
2847 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002848 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002849
2850 // Try to bind free memory that has been freed
2851 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2852 // This may very well return an error.
2853 (void)err;
2854
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002855 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002856
Chia-I Wuf7458c52015-10-26 21:10:41 +08002857 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002858}
2859
Karl Schultz6addd812016-02-02 17:17:23 -07002860TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2861 VkResult err;
2862 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002863
Karl Schultz6addd812016-02-02 17:17:23 -07002864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2865 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002866
Tobin Ehlisec598302015-09-15 15:02:17 -06002867 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002868
Karl Schultz6addd812016-02-02 17:17:23 -07002869 // Create an image object, allocate memory, destroy the object and then try
2870 // to bind it
2871 VkImage image;
2872 VkDeviceMemory mem;
2873 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002874
Karl Schultz6addd812016-02-02 17:17:23 -07002875 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2876 const int32_t tex_width = 32;
2877 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002878
2879 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002880 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2881 image_create_info.pNext = NULL;
2882 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2883 image_create_info.format = tex_format;
2884 image_create_info.extent.width = tex_width;
2885 image_create_info.extent.height = tex_height;
2886 image_create_info.extent.depth = 1;
2887 image_create_info.mipLevels = 1;
2888 image_create_info.arrayLayers = 1;
2889 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2890 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2891 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2892 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002893
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002894 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002895 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2896 mem_alloc.pNext = NULL;
2897 mem_alloc.allocationSize = 0;
2898 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002899
Chia-I Wuf7458c52015-10-26 21:10:41 +08002900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002901 ASSERT_VK_SUCCESS(err);
2902
Karl Schultz6addd812016-02-02 17:17:23 -07002903 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002904
2905 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002906 pass =
2907 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002908 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002909
2910 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002912 ASSERT_VK_SUCCESS(err);
2913
2914 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002915 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002916 ASSERT_VK_SUCCESS(err);
2917
2918 // Now Try to bind memory to this destroyed object
2919 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2920 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002921 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002922
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002923 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002924
Chia-I Wuf7458c52015-10-26 21:10:41 +08002925 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002926}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002927
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002928#endif // OBJ_TRACKER_TESTS
2929
Tobin Ehlis0788f522015-05-26 16:11:58 -06002930#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002931
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002932// This is a positive test. No errors are expected.
2933TEST_F(VkLayerTest, StencilLoadOp) {
2934 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2935 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2936 VkResult result = VK_SUCCESS;
2937 VkImageFormatProperties formatProps;
2938 vkGetPhysicalDeviceImageFormatProperties(
2939 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2940 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2941 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2942 0, &formatProps);
2943 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2944 return;
2945 }
2946
2947 ASSERT_NO_FATAL_FAILURE(InitState());
2948 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2949 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2950 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2951 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2952 VkAttachmentDescription att = {};
2953 VkAttachmentReference ref = {};
2954 att.format = depth_stencil_fmt;
2955 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2956 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2957 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2958 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2959 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2960 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2961
2962 VkClearValue clear;
2963 clear.depthStencil.depth = 1.0;
2964 clear.depthStencil.stencil = 0;
2965 ref.attachment = 0;
2966 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2967
2968 VkSubpassDescription subpass = {};
2969 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
2970 subpass.flags = 0;
2971 subpass.inputAttachmentCount = 0;
2972 subpass.pInputAttachments = NULL;
2973 subpass.colorAttachmentCount = 0;
2974 subpass.pColorAttachments = NULL;
2975 subpass.pResolveAttachments = NULL;
2976 subpass.pDepthStencilAttachment = &ref;
2977 subpass.preserveAttachmentCount = 0;
2978 subpass.pPreserveAttachments = NULL;
2979
2980 VkRenderPass rp;
2981 VkRenderPassCreateInfo rp_info = {};
2982 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2983 rp_info.attachmentCount = 1;
2984 rp_info.pAttachments = &att;
2985 rp_info.subpassCount = 1;
2986 rp_info.pSubpasses = &subpass;
2987 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
2988 ASSERT_VK_SUCCESS(result);
2989
2990 VkImageView *depthView = m_depthStencil->BindInfo();
2991 VkFramebufferCreateInfo fb_info = {};
2992 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
2993 fb_info.pNext = NULL;
2994 fb_info.renderPass = rp;
2995 fb_info.attachmentCount = 1;
2996 fb_info.pAttachments = depthView;
2997 fb_info.width = 100;
2998 fb_info.height = 100;
2999 fb_info.layers = 1;
3000 VkFramebuffer fb;
3001 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3002 ASSERT_VK_SUCCESS(result);
3003
3004
3005 VkRenderPassBeginInfo rpbinfo = {};
3006 rpbinfo.clearValueCount = 1;
3007 rpbinfo.pClearValues = &clear;
3008 rpbinfo.pNext = NULL;
3009 rpbinfo.renderPass = rp;
3010 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3011 rpbinfo.renderArea.extent.width = 100;
3012 rpbinfo.renderArea.extent.height = 100;
3013 rpbinfo.renderArea.offset.x = 0;
3014 rpbinfo.renderArea.offset.y = 0;
3015 rpbinfo.framebuffer = fb;
3016
3017 VkFence fence = {};
3018 VkFenceCreateInfo fence_ci = {};
3019 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3020 fence_ci.pNext = nullptr;
3021 fence_ci.flags = 0;
3022 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3023 ASSERT_VK_SUCCESS(result);
3024
3025
3026 m_commandBuffer->BeginCommandBuffer();
3027 m_commandBuffer->BeginRenderPass(rpbinfo);
3028 m_commandBuffer->EndRenderPass();
3029 m_commandBuffer->EndCommandBuffer();
3030 m_commandBuffer->QueueCommandBuffer(fence);
3031
3032 VkImageObj destImage(m_device);
3033 destImage.init(100, 100, depth_stencil_fmt,
3034 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3035 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3036 VK_IMAGE_TILING_OPTIMAL, 0);
3037 VkImageMemoryBarrier barrier = {};
3038 VkImageSubresourceRange range;
3039 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3040 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3041 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3042 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3043 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3044 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3045 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3046 barrier.image = m_depthStencil->handle();
3047 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3048 range.baseMipLevel = 0;
3049 range.levelCount = 1;
3050 range.baseArrayLayer = 0;
3051 range.layerCount = 1;
3052 barrier.subresourceRange = range;
3053 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3054 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3055 cmdbuf.BeginCommandBuffer();
3056 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3057 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3058 nullptr, 1, &barrier);
3059 barrier.srcAccessMask = 0;
3060 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3061 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3062 barrier.image = destImage.handle();
3063 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3064 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3065 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3066 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3067 nullptr, 1, &barrier);
3068 VkImageCopy cregion;
3069 cregion.srcSubresource.aspectMask =
3070 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3071 cregion.srcSubresource.mipLevel = 0;
3072 cregion.srcSubresource.baseArrayLayer = 0;
3073 cregion.srcSubresource.layerCount = 1;
3074 cregion.srcOffset.x = 0;
3075 cregion.srcOffset.y = 0;
3076 cregion.srcOffset.z = 0;
3077 cregion.dstSubresource.aspectMask =
3078 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3079 cregion.dstSubresource.mipLevel = 0;
3080 cregion.dstSubresource.baseArrayLayer = 0;
3081 cregion.dstSubresource.layerCount = 1;
3082 cregion.dstOffset.x = 0;
3083 cregion.dstOffset.y = 0;
3084 cregion.dstOffset.z = 0;
3085 cregion.extent.width = 100;
3086 cregion.extent.height = 100;
3087 cregion.extent.depth = 1;
3088 cmdbuf.CopyImage(m_depthStencil->handle(),
3089 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3090 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3091 cmdbuf.EndCommandBuffer();
3092
3093 VkSubmitInfo submit_info;
3094 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3095 submit_info.pNext = NULL;
3096 submit_info.waitSemaphoreCount = 0;
3097 submit_info.pWaitSemaphores = NULL;
3098 submit_info.pWaitDstStageMask = NULL;
3099 submit_info.commandBufferCount = 1;
3100 submit_info.pCommandBuffers = &cmdbuf.handle();
3101 submit_info.signalSemaphoreCount = 0;
3102 submit_info.pSignalSemaphores = NULL;
3103
3104 m_errorMonitor->ExpectSuccess();
3105 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3106 m_errorMonitor->VerifyNotFound();
3107
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003108 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003109 vkDestroyFence(m_device->device(), fence, nullptr);
3110 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3111 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3112}
3113
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003114TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3115 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3116 "attachment reference of VK_ATTACHMENT_UNUSED");
3117
3118 ASSERT_NO_FATAL_FAILURE(InitState());
3119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3120
3121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3122 "must not be VK_ATTACHMENT_UNUSED");
3123
3124 VkAttachmentReference color_attach = {};
3125 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3126 color_attach.attachment = 0;
3127 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3128 VkSubpassDescription subpass = {};
3129 subpass.colorAttachmentCount = 1;
3130 subpass.pColorAttachments = &color_attach;
3131 subpass.preserveAttachmentCount = 1;
3132 subpass.pPreserveAttachments = &preserve_attachment;
3133
3134 VkRenderPassCreateInfo rpci = {};
3135 rpci.subpassCount = 1;
3136 rpci.pSubpasses = &subpass;
3137 rpci.attachmentCount = 1;
3138 VkAttachmentDescription attach_desc = {};
3139 attach_desc.format = VK_FORMAT_UNDEFINED;
3140 rpci.pAttachments = &attach_desc;
3141 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3142 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003143 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003144
3145 m_errorMonitor->VerifyFound();
3146
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003147 if (result == VK_SUCCESS) {
3148 vkDestroyRenderPass(m_device->device(), rp, NULL);
3149 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003150}
3151
3152TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3153 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3154 "in the depthStencil attachment point");
3155
3156 ASSERT_NO_FATAL_FAILURE(InitState());
3157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3158
3159 m_errorMonitor->SetDesiredFailureMsg(
3160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3161 "conflicts with the image's IMAGE_USAGE flags");
3162
3163 // Create a renderPass with a depth-stencil attachment created with
3164 // IMAGE_USAGE_COLOR_ATTACHMENT
3165 VkAttachmentReference attach = {};
3166 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3167 VkSubpassDescription subpass = {};
3168 // Add our color attachment to pDepthStencilAttachment
3169 subpass.pDepthStencilAttachment = &attach;
3170 VkRenderPassCreateInfo rpci = {};
3171 rpci.subpassCount = 1;
3172 rpci.pSubpasses = &subpass;
3173 rpci.attachmentCount = 1;
3174 VkAttachmentDescription attach_desc = {};
3175 attach_desc.format = VK_FORMAT_UNDEFINED;
3176 rpci.pAttachments = &attach_desc;
3177 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3178 VkRenderPass rp;
3179 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3180 ASSERT_VK_SUCCESS(err);
3181
3182 VkImageView imageView =
3183 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3184 VkFramebufferCreateInfo fb_info = {};
3185 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3186 fb_info.pNext = NULL;
3187 fb_info.renderPass = rp;
3188 fb_info.attachmentCount = 1;
3189 fb_info.pAttachments = &imageView;
3190 fb_info.width = 100;
3191 fb_info.height = 100;
3192 fb_info.layers = 1;
3193
3194 VkFramebuffer fb;
3195 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3196
3197 m_errorMonitor->VerifyFound();
3198
3199 if (err == VK_SUCCESS) {
3200 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3201 }
3202 vkDestroyRenderPass(m_device->device(), rp, NULL);
3203}
3204
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003205// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003206TEST_F(VkLayerTest, WaitEventThenSet) {
3207 TEST_DESCRIPTION(
3208 "Wait on a event then set it after the wait has been submitted.");
3209
Michael Lentine860b0fe2016-05-20 10:14:00 -05003210 m_errorMonitor->ExpectSuccess();
3211
3212 VkEvent event;
3213 VkEventCreateInfo event_create_info{};
3214 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3215 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3216
3217 VkCommandPool command_pool;
3218 VkCommandPoolCreateInfo pool_create_info{};
3219 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3220 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3221 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3222 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3223 &command_pool);
3224
3225 VkCommandBuffer command_buffer;
3226 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3227 command_buffer_allocate_info.sType =
3228 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3229 command_buffer_allocate_info.commandPool = command_pool;
3230 command_buffer_allocate_info.commandBufferCount = 1;
3231 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3232 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3233 &command_buffer);
3234
3235 VkQueue queue = VK_NULL_HANDLE;
3236 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003237 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003238
3239 {
3240 VkCommandBufferBeginInfo begin_info{};
3241 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3242 vkBeginCommandBuffer(command_buffer, &begin_info);
3243
3244 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3245 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3246 nullptr, 0, nullptr);
3247 vkCmdResetEvent(command_buffer, event,
3248 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3249 vkEndCommandBuffer(command_buffer);
3250 }
3251 {
3252 VkSubmitInfo submit_info{};
3253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3254 submit_info.commandBufferCount = 1;
3255 submit_info.pCommandBuffers = &command_buffer;
3256 submit_info.signalSemaphoreCount = 0;
3257 submit_info.pSignalSemaphores = nullptr;
3258 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3259 }
3260 { vkSetEvent(m_device->device(), event); }
3261
3262 vkQueueWaitIdle(queue);
3263
3264 vkDestroyEvent(m_device->device(), event, nullptr);
3265 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3266 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3267
3268 m_errorMonitor->VerifyNotFound();
3269}
Michael Lentine5627e692016-05-20 17:45:02 -05003270// This is a positive test. No errors should be generated.
3271TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3272 TEST_DESCRIPTION(
3273 "Issue a query and copy from it on a second command buffer.");
3274
3275 if ((m_device->queue_props.empty()) ||
3276 (m_device->queue_props[0].queueCount < 2))
3277 return;
3278
3279 m_errorMonitor->ExpectSuccess();
3280
3281 VkQueryPool query_pool;
3282 VkQueryPoolCreateInfo query_pool_create_info{};
3283 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3284 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3285 query_pool_create_info.queryCount = 1;
3286 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3287 &query_pool);
3288
3289 VkCommandPool command_pool;
3290 VkCommandPoolCreateInfo pool_create_info{};
3291 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3292 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3293 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3294 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3295 &command_pool);
3296
3297 VkCommandBuffer command_buffer[2];
3298 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3299 command_buffer_allocate_info.sType =
3300 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3301 command_buffer_allocate_info.commandPool = command_pool;
3302 command_buffer_allocate_info.commandBufferCount = 2;
3303 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3304 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3305 command_buffer);
3306
3307 VkQueue queue = VK_NULL_HANDLE;
3308 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3309 1, &queue);
3310
3311 uint32_t qfi = 0;
3312 VkBufferCreateInfo buff_create_info = {};
3313 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3314 buff_create_info.size = 1024;
3315 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3316 buff_create_info.queueFamilyIndexCount = 1;
3317 buff_create_info.pQueueFamilyIndices = &qfi;
3318
3319 VkResult err;
3320 VkBuffer buffer;
3321 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3322 ASSERT_VK_SUCCESS(err);
3323 VkMemoryAllocateInfo mem_alloc = {};
3324 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3325 mem_alloc.pNext = NULL;
3326 mem_alloc.allocationSize = 1024;
3327 mem_alloc.memoryTypeIndex = 0;
3328
3329 VkMemoryRequirements memReqs;
3330 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3331 bool pass =
3332 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3333 if (!pass) {
3334 vkDestroyBuffer(m_device->device(), buffer, NULL);
3335 return;
3336 }
3337
3338 VkDeviceMemory mem;
3339 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3340 ASSERT_VK_SUCCESS(err);
3341 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3342 ASSERT_VK_SUCCESS(err);
3343
3344 {
3345 VkCommandBufferBeginInfo begin_info{};
3346 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3347 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3348
3349 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3350 vkCmdWriteTimestamp(command_buffer[0],
3351 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3352
3353 vkEndCommandBuffer(command_buffer[0]);
3354
3355 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3356
3357 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3358 0, 0, 0);
3359
3360 vkEndCommandBuffer(command_buffer[1]);
3361 }
3362 {
3363 VkSubmitInfo submit_info{};
3364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3365 submit_info.commandBufferCount = 2;
3366 submit_info.pCommandBuffers = command_buffer;
3367 submit_info.signalSemaphoreCount = 0;
3368 submit_info.pSignalSemaphores = nullptr;
3369 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3370 }
3371
3372 vkQueueWaitIdle(queue);
3373
3374 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3375 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3376 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003377 vkDestroyBuffer(m_device->device(), buffer, NULL);
3378 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003379
3380 m_errorMonitor->VerifyNotFound();
3381}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003382
3383TEST_F(VkLayerTest, ResetEventThenSet) {
3384 TEST_DESCRIPTION(
3385 "Reset an event then set it after the reset has been submitted.");
3386
Michael Lentine860b0fe2016-05-20 10:14:00 -05003387 m_errorMonitor->ExpectSuccess();
3388
3389 VkEvent event;
3390 VkEventCreateInfo event_create_info{};
3391 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3392 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3393
3394 VkCommandPool command_pool;
3395 VkCommandPoolCreateInfo pool_create_info{};
3396 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3397 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3398 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3399 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3400 &command_pool);
3401
3402 VkCommandBuffer command_buffer;
3403 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3404 command_buffer_allocate_info.sType =
3405 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3406 command_buffer_allocate_info.commandPool = command_pool;
3407 command_buffer_allocate_info.commandBufferCount = 1;
3408 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3409 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3410 &command_buffer);
3411
3412 VkQueue queue = VK_NULL_HANDLE;
3413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003414 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003415
3416 {
3417 VkCommandBufferBeginInfo begin_info{};
3418 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3419 vkBeginCommandBuffer(command_buffer, &begin_info);
3420
3421 vkCmdResetEvent(command_buffer, event,
3422 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3423 vkCmdWaitEvents(command_buffer, 1, &event,
3424 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3425 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3426 nullptr, 0, nullptr);
3427 vkEndCommandBuffer(command_buffer);
3428 }
3429 {
3430 VkSubmitInfo submit_info{};
3431 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3432 submit_info.commandBufferCount = 1;
3433 submit_info.pCommandBuffers = &command_buffer;
3434 submit_info.signalSemaphoreCount = 0;
3435 submit_info.pSignalSemaphores = nullptr;
3436 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3437 }
3438 {
3439 m_errorMonitor->SetDesiredFailureMsg(
3440 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3441 "0x1 that is already in use by a "
3442 "command buffer.");
3443 vkSetEvent(m_device->device(), event);
3444 m_errorMonitor->VerifyFound();
3445 }
3446
3447 vkQueueWaitIdle(queue);
3448
3449 vkDestroyEvent(m_device->device(), event, nullptr);
3450 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3451 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3452}
3453
3454// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003455TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3456 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3457 "run through a Submit & WaitForFences cycle 3 times. This "
3458 "previously revealed a bug so running this positive test "
3459 "to prevent a regression.");
3460 m_errorMonitor->ExpectSuccess();
3461
3462 ASSERT_NO_FATAL_FAILURE(InitState());
3463 VkQueue queue = VK_NULL_HANDLE;
3464 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3465 0, &queue);
3466
3467 static const uint32_t NUM_OBJECTS = 2;
3468 static const uint32_t NUM_FRAMES = 3;
3469 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3470 VkFence fences[NUM_OBJECTS] = {};
3471
3472 VkCommandPool cmd_pool;
3473 VkCommandPoolCreateInfo cmd_pool_ci = {};
3474 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3475 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3476 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3477 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3478 nullptr, &cmd_pool);
3479 ASSERT_VK_SUCCESS(err);
3480
3481 VkCommandBufferAllocateInfo cmd_buf_info = {};
3482 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3483 cmd_buf_info.commandPool = cmd_pool;
3484 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3485 cmd_buf_info.commandBufferCount = 1;
3486
3487 VkFenceCreateInfo fence_ci = {};
3488 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3489 fence_ci.pNext = nullptr;
3490 fence_ci.flags = 0;
3491
3492 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3493 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3494 &cmd_buffers[i]);
3495 ASSERT_VK_SUCCESS(err);
3496 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3497 ASSERT_VK_SUCCESS(err);
3498 }
3499
3500 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003501 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3502 // Create empty cmd buffer
3503 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3504 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003505
Tobin Ehlisf9025162016-05-26 06:55:21 -06003506 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3507 ASSERT_VK_SUCCESS(err);
3508 err = vkEndCommandBuffer(cmd_buffers[obj]);
3509 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003510
Tobin Ehlisf9025162016-05-26 06:55:21 -06003511 VkSubmitInfo submit_info = {};
3512 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3513 submit_info.commandBufferCount = 1;
3514 submit_info.pCommandBuffers = &cmd_buffers[obj];
3515 // Submit cmd buffer and wait for fence
3516 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3517 ASSERT_VK_SUCCESS(err);
3518 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3519 UINT64_MAX);
3520 ASSERT_VK_SUCCESS(err);
3521 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3522 ASSERT_VK_SUCCESS(err);
3523 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003524 }
3525 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003526 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3527 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3528 vkDestroyFence(m_device->device(), fences[i], nullptr);
3529 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003530}
3531// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003532TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3533
3534 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3535 "submitted on separate queues followed by a QueueWaitIdle.");
3536
Dustin Graves48458142016-04-29 16:11:55 -06003537 if ((m_device->queue_props.empty()) ||
3538 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003539 return;
3540
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003541 m_errorMonitor->ExpectSuccess();
3542
3543 VkSemaphore semaphore;
3544 VkSemaphoreCreateInfo semaphore_create_info{};
3545 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3546 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3547 &semaphore);
3548
3549 VkCommandPool command_pool;
3550 VkCommandPoolCreateInfo pool_create_info{};
3551 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3552 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3553 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3554 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3555 &command_pool);
3556
3557 VkCommandBuffer command_buffer[2];
3558 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3559 command_buffer_allocate_info.sType =
3560 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3561 command_buffer_allocate_info.commandPool = command_pool;
3562 command_buffer_allocate_info.commandBufferCount = 2;
3563 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3564 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3565 command_buffer);
3566
3567 VkQueue queue = VK_NULL_HANDLE;
3568 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3569 1, &queue);
3570
3571 {
3572 VkCommandBufferBeginInfo begin_info{};
3573 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3574 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3575
3576 vkCmdPipelineBarrier(command_buffer[0],
3577 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3578 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3579 0, nullptr, 0, nullptr);
3580
3581 VkViewport viewport{};
3582 viewport.maxDepth = 1.0f;
3583 viewport.minDepth = 0.0f;
3584 viewport.width = 512;
3585 viewport.height = 512;
3586 viewport.x = 0;
3587 viewport.y = 0;
3588 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3589 vkEndCommandBuffer(command_buffer[0]);
3590 }
3591 {
3592 VkCommandBufferBeginInfo begin_info{};
3593 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3594 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3595
3596 VkViewport viewport{};
3597 viewport.maxDepth = 1.0f;
3598 viewport.minDepth = 0.0f;
3599 viewport.width = 512;
3600 viewport.height = 512;
3601 viewport.x = 0;
3602 viewport.y = 0;
3603 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3604 vkEndCommandBuffer(command_buffer[1]);
3605 }
3606 {
3607 VkSubmitInfo submit_info{};
3608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3609 submit_info.commandBufferCount = 1;
3610 submit_info.pCommandBuffers = &command_buffer[0];
3611 submit_info.signalSemaphoreCount = 1;
3612 submit_info.pSignalSemaphores = &semaphore;
3613 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3614 }
3615 {
3616 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3617 VkSubmitInfo submit_info{};
3618 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3619 submit_info.commandBufferCount = 1;
3620 submit_info.pCommandBuffers = &command_buffer[1];
3621 submit_info.waitSemaphoreCount = 1;
3622 submit_info.pWaitSemaphores = &semaphore;
3623 submit_info.pWaitDstStageMask = flags;
3624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3625 }
3626
3627 vkQueueWaitIdle(m_device->m_queue);
3628
3629 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3630 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3631 &command_buffer[0]);
3632 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3633
3634 m_errorMonitor->VerifyNotFound();
3635}
3636
3637// This is a positive test. No errors should be generated.
3638TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3639
3640 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3641 "submitted on separate queues, the second having a fence"
3642 "followed by a QueueWaitIdle.");
3643
Dustin Graves48458142016-04-29 16:11:55 -06003644 if ((m_device->queue_props.empty()) ||
3645 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003646 return;
3647
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003648 m_errorMonitor->ExpectSuccess();
3649
3650 VkFence fence;
3651 VkFenceCreateInfo fence_create_info{};
3652 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3653 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3654
3655 VkSemaphore semaphore;
3656 VkSemaphoreCreateInfo semaphore_create_info{};
3657 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3658 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3659 &semaphore);
3660
3661 VkCommandPool command_pool;
3662 VkCommandPoolCreateInfo pool_create_info{};
3663 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3664 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3665 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3666 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3667 &command_pool);
3668
3669 VkCommandBuffer command_buffer[2];
3670 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3671 command_buffer_allocate_info.sType =
3672 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3673 command_buffer_allocate_info.commandPool = command_pool;
3674 command_buffer_allocate_info.commandBufferCount = 2;
3675 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3676 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3677 command_buffer);
3678
3679 VkQueue queue = VK_NULL_HANDLE;
3680 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3681 1, &queue);
3682
3683 {
3684 VkCommandBufferBeginInfo begin_info{};
3685 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3686 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3687
3688 vkCmdPipelineBarrier(command_buffer[0],
3689 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3690 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3691 0, nullptr, 0, nullptr);
3692
3693 VkViewport viewport{};
3694 viewport.maxDepth = 1.0f;
3695 viewport.minDepth = 0.0f;
3696 viewport.width = 512;
3697 viewport.height = 512;
3698 viewport.x = 0;
3699 viewport.y = 0;
3700 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3701 vkEndCommandBuffer(command_buffer[0]);
3702 }
3703 {
3704 VkCommandBufferBeginInfo begin_info{};
3705 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3706 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3707
3708 VkViewport viewport{};
3709 viewport.maxDepth = 1.0f;
3710 viewport.minDepth = 0.0f;
3711 viewport.width = 512;
3712 viewport.height = 512;
3713 viewport.x = 0;
3714 viewport.y = 0;
3715 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3716 vkEndCommandBuffer(command_buffer[1]);
3717 }
3718 {
3719 VkSubmitInfo submit_info{};
3720 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3721 submit_info.commandBufferCount = 1;
3722 submit_info.pCommandBuffers = &command_buffer[0];
3723 submit_info.signalSemaphoreCount = 1;
3724 submit_info.pSignalSemaphores = &semaphore;
3725 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3726 }
3727 {
3728 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3729 VkSubmitInfo submit_info{};
3730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3731 submit_info.commandBufferCount = 1;
3732 submit_info.pCommandBuffers = &command_buffer[1];
3733 submit_info.waitSemaphoreCount = 1;
3734 submit_info.pWaitSemaphores = &semaphore;
3735 submit_info.pWaitDstStageMask = flags;
3736 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3737 }
3738
3739 vkQueueWaitIdle(m_device->m_queue);
3740
3741 vkDestroyFence(m_device->device(), fence, nullptr);
3742 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3743 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3744 &command_buffer[0]);
3745 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3746
3747 m_errorMonitor->VerifyNotFound();
3748}
3749
3750// This is a positive test. No errors should be generated.
3751TEST_F(VkLayerTest,
3752 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3753
3754 TEST_DESCRIPTION(
3755 "Two command buffers, each in a separate QueueSubmit call "
3756 "submitted on separate queues, the second having a fence"
3757 "followed by two consecutive WaitForFences calls on the same fence.");
3758
Dustin Graves48458142016-04-29 16:11:55 -06003759 if ((m_device->queue_props.empty()) ||
3760 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003761 return;
3762
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003763 m_errorMonitor->ExpectSuccess();
3764
3765 VkFence fence;
3766 VkFenceCreateInfo fence_create_info{};
3767 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3768 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3769
3770 VkSemaphore semaphore;
3771 VkSemaphoreCreateInfo semaphore_create_info{};
3772 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3773 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3774 &semaphore);
3775
3776 VkCommandPool command_pool;
3777 VkCommandPoolCreateInfo pool_create_info{};
3778 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3779 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3780 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3781 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3782 &command_pool);
3783
3784 VkCommandBuffer command_buffer[2];
3785 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3786 command_buffer_allocate_info.sType =
3787 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3788 command_buffer_allocate_info.commandPool = command_pool;
3789 command_buffer_allocate_info.commandBufferCount = 2;
3790 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3791 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3792 command_buffer);
3793
3794 VkQueue queue = VK_NULL_HANDLE;
3795 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3796 1, &queue);
3797
3798 {
3799 VkCommandBufferBeginInfo begin_info{};
3800 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3801 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3802
3803 vkCmdPipelineBarrier(command_buffer[0],
3804 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3805 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3806 0, nullptr, 0, nullptr);
3807
3808 VkViewport viewport{};
3809 viewport.maxDepth = 1.0f;
3810 viewport.minDepth = 0.0f;
3811 viewport.width = 512;
3812 viewport.height = 512;
3813 viewport.x = 0;
3814 viewport.y = 0;
3815 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3816 vkEndCommandBuffer(command_buffer[0]);
3817 }
3818 {
3819 VkCommandBufferBeginInfo begin_info{};
3820 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3821 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3822
3823 VkViewport viewport{};
3824 viewport.maxDepth = 1.0f;
3825 viewport.minDepth = 0.0f;
3826 viewport.width = 512;
3827 viewport.height = 512;
3828 viewport.x = 0;
3829 viewport.y = 0;
3830 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3831 vkEndCommandBuffer(command_buffer[1]);
3832 }
3833 {
3834 VkSubmitInfo submit_info{};
3835 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3836 submit_info.commandBufferCount = 1;
3837 submit_info.pCommandBuffers = &command_buffer[0];
3838 submit_info.signalSemaphoreCount = 1;
3839 submit_info.pSignalSemaphores = &semaphore;
3840 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3841 }
3842 {
3843 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3844 VkSubmitInfo submit_info{};
3845 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3846 submit_info.commandBufferCount = 1;
3847 submit_info.pCommandBuffers = &command_buffer[1];
3848 submit_info.waitSemaphoreCount = 1;
3849 submit_info.pWaitSemaphores = &semaphore;
3850 submit_info.pWaitDstStageMask = flags;
3851 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3852 }
3853
3854 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3855 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3856
3857 vkDestroyFence(m_device->device(), fence, nullptr);
3858 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3859 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3860 &command_buffer[0]);
3861 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3862
3863 m_errorMonitor->VerifyNotFound();
3864}
3865
3866// This is a positive test. No errors should be generated.
3867TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3868
3869 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3870 "submitted on separate queues, the second having a fence, "
3871 "followed by a WaitForFences call.");
3872
Dustin Graves48458142016-04-29 16:11:55 -06003873 if ((m_device->queue_props.empty()) ||
3874 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003875 return;
3876
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003877 m_errorMonitor->ExpectSuccess();
3878
3879 VkFence fence;
3880 VkFenceCreateInfo fence_create_info{};
3881 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3882 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3883
3884 VkSemaphore semaphore;
3885 VkSemaphoreCreateInfo semaphore_create_info{};
3886 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3887 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3888 &semaphore);
3889
3890 VkCommandPool command_pool;
3891 VkCommandPoolCreateInfo pool_create_info{};
3892 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3893 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3894 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3895 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3896 &command_pool);
3897
3898 VkCommandBuffer command_buffer[2];
3899 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3900 command_buffer_allocate_info.sType =
3901 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3902 command_buffer_allocate_info.commandPool = command_pool;
3903 command_buffer_allocate_info.commandBufferCount = 2;
3904 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3905 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3906 command_buffer);
3907
3908 VkQueue queue = VK_NULL_HANDLE;
3909 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3910 1, &queue);
3911
3912
3913 {
3914 VkCommandBufferBeginInfo begin_info{};
3915 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3916 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3917
3918 vkCmdPipelineBarrier(command_buffer[0],
3919 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3920 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3921 0, nullptr, 0, nullptr);
3922
3923 VkViewport viewport{};
3924 viewport.maxDepth = 1.0f;
3925 viewport.minDepth = 0.0f;
3926 viewport.width = 512;
3927 viewport.height = 512;
3928 viewport.x = 0;
3929 viewport.y = 0;
3930 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3931 vkEndCommandBuffer(command_buffer[0]);
3932 }
3933 {
3934 VkCommandBufferBeginInfo begin_info{};
3935 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3936 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3937
3938 VkViewport viewport{};
3939 viewport.maxDepth = 1.0f;
3940 viewport.minDepth = 0.0f;
3941 viewport.width = 512;
3942 viewport.height = 512;
3943 viewport.x = 0;
3944 viewport.y = 0;
3945 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3946 vkEndCommandBuffer(command_buffer[1]);
3947 }
3948 {
3949 VkSubmitInfo submit_info{};
3950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3951 submit_info.commandBufferCount = 1;
3952 submit_info.pCommandBuffers = &command_buffer[0];
3953 submit_info.signalSemaphoreCount = 1;
3954 submit_info.pSignalSemaphores = &semaphore;
3955 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3956 }
3957 {
3958 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3959 VkSubmitInfo submit_info{};
3960 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3961 submit_info.commandBufferCount = 1;
3962 submit_info.pCommandBuffers = &command_buffer[1];
3963 submit_info.waitSemaphoreCount = 1;
3964 submit_info.pWaitSemaphores = &semaphore;
3965 submit_info.pWaitDstStageMask = flags;
3966 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3967 }
3968
3969 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3970
3971 vkDestroyFence(m_device->device(), fence, nullptr);
3972 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3973 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3974 &command_buffer[0]);
3975 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3976
3977 m_errorMonitor->VerifyNotFound();
3978}
3979
3980// This is a positive test. No errors should be generated.
3981TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3982
3983 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3984 "on the same queue, sharing a signal/wait semaphore, the "
3985 "second having a fence, "
3986 "followed by a WaitForFences call.");
3987
3988 m_errorMonitor->ExpectSuccess();
3989
3990 VkFence fence;
3991 VkFenceCreateInfo fence_create_info{};
3992 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3993 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3994
3995 VkSemaphore semaphore;
3996 VkSemaphoreCreateInfo semaphore_create_info{};
3997 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3998 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3999 &semaphore);
4000
4001 VkCommandPool command_pool;
4002 VkCommandPoolCreateInfo pool_create_info{};
4003 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4004 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4005 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4006 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4007 &command_pool);
4008
4009 VkCommandBuffer command_buffer[2];
4010 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4011 command_buffer_allocate_info.sType =
4012 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4013 command_buffer_allocate_info.commandPool = command_pool;
4014 command_buffer_allocate_info.commandBufferCount = 2;
4015 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4016 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4017 command_buffer);
4018
4019 {
4020 VkCommandBufferBeginInfo begin_info{};
4021 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4022 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4023
4024 vkCmdPipelineBarrier(command_buffer[0],
4025 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4026 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4027 0, nullptr, 0, nullptr);
4028
4029 VkViewport viewport{};
4030 viewport.maxDepth = 1.0f;
4031 viewport.minDepth = 0.0f;
4032 viewport.width = 512;
4033 viewport.height = 512;
4034 viewport.x = 0;
4035 viewport.y = 0;
4036 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4037 vkEndCommandBuffer(command_buffer[0]);
4038 }
4039 {
4040 VkCommandBufferBeginInfo begin_info{};
4041 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4042 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4043
4044 VkViewport viewport{};
4045 viewport.maxDepth = 1.0f;
4046 viewport.minDepth = 0.0f;
4047 viewport.width = 512;
4048 viewport.height = 512;
4049 viewport.x = 0;
4050 viewport.y = 0;
4051 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4052 vkEndCommandBuffer(command_buffer[1]);
4053 }
4054 {
4055 VkSubmitInfo submit_info{};
4056 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4057 submit_info.commandBufferCount = 1;
4058 submit_info.pCommandBuffers = &command_buffer[0];
4059 submit_info.signalSemaphoreCount = 1;
4060 submit_info.pSignalSemaphores = &semaphore;
4061 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4062 }
4063 {
4064 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4065 VkSubmitInfo submit_info{};
4066 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4067 submit_info.commandBufferCount = 1;
4068 submit_info.pCommandBuffers = &command_buffer[1];
4069 submit_info.waitSemaphoreCount = 1;
4070 submit_info.pWaitSemaphores = &semaphore;
4071 submit_info.pWaitDstStageMask = flags;
4072 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4073 }
4074
4075 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4076
4077 vkDestroyFence(m_device->device(), fence, nullptr);
4078 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4079 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4080 &command_buffer[0]);
4081 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4082
4083 m_errorMonitor->VerifyNotFound();
4084}
4085
4086// This is a positive test. No errors should be generated.
4087TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4088
4089 TEST_DESCRIPTION(
4090 "Two command buffers, each in a separate QueueSubmit call "
4091 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4092 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4093
4094 m_errorMonitor->ExpectSuccess();
4095
4096 VkFence fence;
4097 VkFenceCreateInfo fence_create_info{};
4098 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4099 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4100
4101 VkCommandPool command_pool;
4102 VkCommandPoolCreateInfo pool_create_info{};
4103 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4104 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4105 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4106 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4107 &command_pool);
4108
4109 VkCommandBuffer command_buffer[2];
4110 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4111 command_buffer_allocate_info.sType =
4112 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4113 command_buffer_allocate_info.commandPool = command_pool;
4114 command_buffer_allocate_info.commandBufferCount = 2;
4115 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4116 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4117 command_buffer);
4118
4119 {
4120 VkCommandBufferBeginInfo begin_info{};
4121 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4122 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4123
4124 vkCmdPipelineBarrier(command_buffer[0],
4125 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4126 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4127 0, nullptr, 0, nullptr);
4128
4129 VkViewport viewport{};
4130 viewport.maxDepth = 1.0f;
4131 viewport.minDepth = 0.0f;
4132 viewport.width = 512;
4133 viewport.height = 512;
4134 viewport.x = 0;
4135 viewport.y = 0;
4136 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4137 vkEndCommandBuffer(command_buffer[0]);
4138 }
4139 {
4140 VkCommandBufferBeginInfo begin_info{};
4141 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4142 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4143
4144 VkViewport viewport{};
4145 viewport.maxDepth = 1.0f;
4146 viewport.minDepth = 0.0f;
4147 viewport.width = 512;
4148 viewport.height = 512;
4149 viewport.x = 0;
4150 viewport.y = 0;
4151 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4152 vkEndCommandBuffer(command_buffer[1]);
4153 }
4154 {
4155 VkSubmitInfo submit_info{};
4156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4157 submit_info.commandBufferCount = 1;
4158 submit_info.pCommandBuffers = &command_buffer[0];
4159 submit_info.signalSemaphoreCount = 0;
4160 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4162 }
4163 {
4164 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4165 VkSubmitInfo submit_info{};
4166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4167 submit_info.commandBufferCount = 1;
4168 submit_info.pCommandBuffers = &command_buffer[1];
4169 submit_info.waitSemaphoreCount = 0;
4170 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4171 submit_info.pWaitDstStageMask = flags;
4172 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4173 }
4174
4175 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4176
4177 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4178
4179 vkDestroyFence(m_device->device(), fence, nullptr);
4180 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4181 &command_buffer[0]);
4182 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4183
4184 m_errorMonitor->VerifyNotFound();
4185}
4186
4187// This is a positive test. No errors should be generated.
4188TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4189
4190 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4191 "on the same queue, the second having a fence, followed "
4192 "by a WaitForFences call.");
4193
4194 m_errorMonitor->ExpectSuccess();
4195
4196 VkFence fence;
4197 VkFenceCreateInfo fence_create_info{};
4198 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4199 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4200
4201 VkCommandPool command_pool;
4202 VkCommandPoolCreateInfo pool_create_info{};
4203 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4204 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4205 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4206 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4207 &command_pool);
4208
4209 VkCommandBuffer command_buffer[2];
4210 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4211 command_buffer_allocate_info.sType =
4212 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4213 command_buffer_allocate_info.commandPool = command_pool;
4214 command_buffer_allocate_info.commandBufferCount = 2;
4215 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4216 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4217 command_buffer);
4218
4219 {
4220 VkCommandBufferBeginInfo begin_info{};
4221 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4222 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4223
4224 vkCmdPipelineBarrier(command_buffer[0],
4225 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4226 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4227 0, nullptr, 0, nullptr);
4228
4229 VkViewport viewport{};
4230 viewport.maxDepth = 1.0f;
4231 viewport.minDepth = 0.0f;
4232 viewport.width = 512;
4233 viewport.height = 512;
4234 viewport.x = 0;
4235 viewport.y = 0;
4236 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4237 vkEndCommandBuffer(command_buffer[0]);
4238 }
4239 {
4240 VkCommandBufferBeginInfo begin_info{};
4241 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4242 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4243
4244 VkViewport viewport{};
4245 viewport.maxDepth = 1.0f;
4246 viewport.minDepth = 0.0f;
4247 viewport.width = 512;
4248 viewport.height = 512;
4249 viewport.x = 0;
4250 viewport.y = 0;
4251 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4252 vkEndCommandBuffer(command_buffer[1]);
4253 }
4254 {
4255 VkSubmitInfo submit_info{};
4256 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4257 submit_info.commandBufferCount = 1;
4258 submit_info.pCommandBuffers = &command_buffer[0];
4259 submit_info.signalSemaphoreCount = 0;
4260 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4262 }
4263 {
4264 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4265 VkSubmitInfo submit_info{};
4266 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4267 submit_info.commandBufferCount = 1;
4268 submit_info.pCommandBuffers = &command_buffer[1];
4269 submit_info.waitSemaphoreCount = 0;
4270 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4271 submit_info.pWaitDstStageMask = flags;
4272 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4273 }
4274
4275 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4276
4277 vkDestroyFence(m_device->device(), fence, nullptr);
4278 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4279 &command_buffer[0]);
4280 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4281
4282 m_errorMonitor->VerifyNotFound();
4283}
4284
4285// This is a positive test. No errors should be generated.
4286TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4287
4288 TEST_DESCRIPTION(
4289 "Two command buffers each in a separate SubmitInfo sent in a single "
4290 "QueueSubmit call followed by a WaitForFences call.");
4291
4292 m_errorMonitor->ExpectSuccess();
4293
4294 VkFence fence;
4295 VkFenceCreateInfo fence_create_info{};
4296 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4297 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4298
4299 VkSemaphore semaphore;
4300 VkSemaphoreCreateInfo semaphore_create_info{};
4301 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4302 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4303 &semaphore);
4304
4305 VkCommandPool command_pool;
4306 VkCommandPoolCreateInfo pool_create_info{};
4307 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4308 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4309 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4310 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4311 &command_pool);
4312
4313 VkCommandBuffer command_buffer[2];
4314 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4315 command_buffer_allocate_info.sType =
4316 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4317 command_buffer_allocate_info.commandPool = command_pool;
4318 command_buffer_allocate_info.commandBufferCount = 2;
4319 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4320 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4321 command_buffer);
4322
4323 {
4324 VkCommandBufferBeginInfo begin_info{};
4325 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4326 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4327
4328 vkCmdPipelineBarrier(command_buffer[0],
4329 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4330 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4331 0, nullptr, 0, nullptr);
4332
4333 VkViewport viewport{};
4334 viewport.maxDepth = 1.0f;
4335 viewport.minDepth = 0.0f;
4336 viewport.width = 512;
4337 viewport.height = 512;
4338 viewport.x = 0;
4339 viewport.y = 0;
4340 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4341 vkEndCommandBuffer(command_buffer[0]);
4342 }
4343 {
4344 VkCommandBufferBeginInfo begin_info{};
4345 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4346 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4347
4348 VkViewport viewport{};
4349 viewport.maxDepth = 1.0f;
4350 viewport.minDepth = 0.0f;
4351 viewport.width = 512;
4352 viewport.height = 512;
4353 viewport.x = 0;
4354 viewport.y = 0;
4355 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4356 vkEndCommandBuffer(command_buffer[1]);
4357 }
4358 {
4359 VkSubmitInfo submit_info[2];
4360 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4361
4362 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4363 submit_info[0].pNext = NULL;
4364 submit_info[0].commandBufferCount = 1;
4365 submit_info[0].pCommandBuffers = &command_buffer[0];
4366 submit_info[0].signalSemaphoreCount = 1;
4367 submit_info[0].pSignalSemaphores = &semaphore;
4368 submit_info[0].waitSemaphoreCount = 0;
4369 submit_info[0].pWaitSemaphores = NULL;
4370 submit_info[0].pWaitDstStageMask = 0;
4371
4372 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4373 submit_info[1].pNext = NULL;
4374 submit_info[1].commandBufferCount = 1;
4375 submit_info[1].pCommandBuffers = &command_buffer[1];
4376 submit_info[1].waitSemaphoreCount = 1;
4377 submit_info[1].pWaitSemaphores = &semaphore;
4378 submit_info[1].pWaitDstStageMask = flags;
4379 submit_info[1].signalSemaphoreCount = 0;
4380 submit_info[1].pSignalSemaphores = NULL;
4381 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4382 }
4383
4384 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4385
4386 vkDestroyFence(m_device->device(), fence, nullptr);
4387 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4388 &command_buffer[0]);
4389 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004390 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004391
4392 m_errorMonitor->VerifyNotFound();
4393}
4394
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004395TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004396 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004397 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4398 "state is required but not correctly bound.");
4399
4400 // Dynamic depth bias
4401 m_errorMonitor->SetDesiredFailureMsg(
4402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4403 "Dynamic depth bias state not set for this command buffer");
4404 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4405 BsoFailDepthBias);
4406 m_errorMonitor->VerifyFound();
4407}
4408
4409TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4410 TEST_DESCRIPTION(
4411 "Run a simple draw calls to validate failure when Line Width dynamic "
4412 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004413
4414 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004415 m_errorMonitor->SetDesiredFailureMsg(
4416 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004417 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004418 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4419 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004420 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004421}
4422
4423TEST_F(VkLayerTest, DynamicViewportNotBound) {
4424 TEST_DESCRIPTION(
4425 "Run a simple draw calls to validate failure when Viewport dynamic "
4426 "state is required but not correctly bound.");
4427
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004428 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004429 m_errorMonitor->SetDesiredFailureMsg(
4430 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004431 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004432 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4433 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004434 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004435}
4436
4437TEST_F(VkLayerTest, DynamicScissorNotBound) {
4438 TEST_DESCRIPTION(
4439 "Run a simple draw calls to validate failure when Scissor dynamic "
4440 "state is required but not correctly bound.");
4441
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004442 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004443 m_errorMonitor->SetDesiredFailureMsg(
4444 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004445 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004446 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4447 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004448 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004449}
4450
Tobin Ehlis21c88352016-05-26 06:15:45 -06004451TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004452 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004453 "Run a simple draw calls to validate failure when Blend Constants "
4454 "dynamic state is required but not correctly bound.");
4455 // Dynamic blend constant state
4456 m_errorMonitor->SetDesiredFailureMsg(
4457 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4458 "Dynamic blend constants state not set for this command buffer");
4459 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4460 BsoFailBlend);
4461 m_errorMonitor->VerifyFound();
4462}
4463
4464TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4465 TEST_DESCRIPTION(
4466 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004467 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004468 if (!m_device->phy().features().depthBounds) {
4469 printf("Device does not support depthBounds test; skipped.\n");
4470 return;
4471 }
4472 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004473 m_errorMonitor->SetDesiredFailureMsg(
4474 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004475 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004476 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4477 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004478 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004479}
4480
4481TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4482 TEST_DESCRIPTION(
4483 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4484 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004485 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004486 m_errorMonitor->SetDesiredFailureMsg(
4487 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004488 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004489 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4490 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004491 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004492}
4493
4494TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4495 TEST_DESCRIPTION(
4496 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4497 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004498 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004499 m_errorMonitor->SetDesiredFailureMsg(
4500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004501 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004502 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4503 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004504 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004505}
4506
4507TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4508 TEST_DESCRIPTION(
4509 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4510 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004511 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004512 m_errorMonitor->SetDesiredFailureMsg(
4513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004514 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004515 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4516 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004517 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004518}
4519
Karl Schultz6addd812016-02-02 17:17:23 -07004520TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004521 m_errorMonitor->SetDesiredFailureMsg(
4522 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4523 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4524 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004525
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004526 ASSERT_NO_FATAL_FAILURE(InitState());
4527 ASSERT_NO_FATAL_FAILURE(InitViewport());
4528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4529
Karl Schultz6addd812016-02-02 17:17:23 -07004530 // We luck out b/c by default the framework creates CB w/ the
4531 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004532 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004533 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4534 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004535 EndCommandBuffer();
4536
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004537 // Bypass framework since it does the waits automatically
4538 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004539 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4541 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004542 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004543 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004544 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004545 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004546 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004547 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004548 submit_info.pSignalSemaphores = NULL;
4549
Chris Forbes40028e22016-06-13 09:59:34 +12004550 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004551 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004552
Karl Schultz6addd812016-02-02 17:17:23 -07004553 // Cause validation error by re-submitting cmd buffer that should only be
4554 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004555 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004556
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004557 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004558}
4559
Karl Schultz6addd812016-02-02 17:17:23 -07004560TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004561 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004562 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004563
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004565 "Unable to allocate 1 descriptors of "
4566 "type "
4567 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004568
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004569 ASSERT_NO_FATAL_FAILURE(InitState());
4570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004571
Karl Schultz6addd812016-02-02 17:17:23 -07004572 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4573 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004574 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004575 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4576 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004577
4578 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004579 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4580 ds_pool_ci.pNext = NULL;
4581 ds_pool_ci.flags = 0;
4582 ds_pool_ci.maxSets = 1;
4583 ds_pool_ci.poolSizeCount = 1;
4584 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004585
4586 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004587 err =
4588 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004589 ASSERT_VK_SUCCESS(err);
4590
4591 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004592 dsl_binding.binding = 0;
4593 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4594 dsl_binding.descriptorCount = 1;
4595 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4596 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004597
4598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4600 ds_layout_ci.pNext = NULL;
4601 ds_layout_ci.bindingCount = 1;
4602 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004603
4604 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004605 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4606 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004607 ASSERT_VK_SUCCESS(err);
4608
4609 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004610 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004611 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004612 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004613 alloc_info.descriptorPool = ds_pool;
4614 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004615 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4616 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004617
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004618 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004619
Chia-I Wuf7458c52015-10-26 21:10:41 +08004620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4621 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004622}
4623
Karl Schultz6addd812016-02-02 17:17:23 -07004624TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4625 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004626
Karl Schultz6addd812016-02-02 17:17:23 -07004627 m_errorMonitor->SetDesiredFailureMsg(
4628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4629 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4630 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004631
Tobin Ehlise735c692015-10-08 13:13:50 -06004632 ASSERT_NO_FATAL_FAILURE(InitState());
4633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004634
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004635 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004636 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4637 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004638
4639 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004640 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4641 ds_pool_ci.pNext = NULL;
4642 ds_pool_ci.maxSets = 1;
4643 ds_pool_ci.poolSizeCount = 1;
4644 ds_pool_ci.flags = 0;
4645 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4646 // app can only call vkResetDescriptorPool on this pool.;
4647 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004648
4649 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004650 err =
4651 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004652 ASSERT_VK_SUCCESS(err);
4653
4654 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004655 dsl_binding.binding = 0;
4656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4657 dsl_binding.descriptorCount = 1;
4658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4659 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004660
4661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4663 ds_layout_ci.pNext = NULL;
4664 ds_layout_ci.bindingCount = 1;
4665 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004666
4667 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004668 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4669 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004670 ASSERT_VK_SUCCESS(err);
4671
4672 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004673 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004674 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004675 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004676 alloc_info.descriptorPool = ds_pool;
4677 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004678 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4679 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004680 ASSERT_VK_SUCCESS(err);
4681
4682 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004683 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004684
Chia-I Wuf7458c52015-10-26 21:10:41 +08004685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004687}
4688
Karl Schultz6addd812016-02-02 17:17:23 -07004689TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004690 // Attempt to clear Descriptor Pool with bad object.
4691 // ObjectTracker should catch this.
4692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4693 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004694 uint64_t fake_pool_handle = 0xbaad6001;
4695 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4696 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004697 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004698}
4699
Karl Schultz6addd812016-02-02 17:17:23 -07004700TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004701 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4702 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004703 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004704 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004705
4706 uint64_t fake_set_handle = 0xbaad6001;
4707 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004708 VkResult err;
4709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4710 "Invalid VkDescriptorSet Object 0xbaad6001");
4711
4712 ASSERT_NO_FATAL_FAILURE(InitState());
4713
4714 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4715 layout_bindings[0].binding = 0;
4716 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4717 layout_bindings[0].descriptorCount = 1;
4718 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4719 layout_bindings[0].pImmutableSamplers = NULL;
4720
4721 VkDescriptorSetLayout descriptor_set_layout;
4722 VkDescriptorSetLayoutCreateInfo dslci = {};
4723 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4724 dslci.pNext = NULL;
4725 dslci.bindingCount = 1;
4726 dslci.pBindings = layout_bindings;
4727 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004728 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004729
4730 VkPipelineLayout pipeline_layout;
4731 VkPipelineLayoutCreateInfo plci = {};
4732 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4733 plci.pNext = NULL;
4734 plci.setLayoutCount = 1;
4735 plci.pSetLayouts = &descriptor_set_layout;
4736 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004737 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004738
4739 BeginCommandBuffer();
4740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004741 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004742 m_errorMonitor->VerifyFound();
4743 EndCommandBuffer();
4744 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4745 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004746}
4747
Karl Schultz6addd812016-02-02 17:17:23 -07004748TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004749 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4750 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004751 uint64_t fake_layout_handle = 0xbaad6001;
4752 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4754 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4755
4756 VkPipelineLayout pipeline_layout;
4757 VkPipelineLayoutCreateInfo plci = {};
4758 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4759 plci.pNext = NULL;
4760 plci.setLayoutCount = 1;
4761 plci.pSetLayouts = &bad_layout;
4762 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4763
4764 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004765}
4766
Mark Muellerd4914412016-06-13 17:52:06 -06004767TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4768 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4769 "1) A uniform buffer update must have a valid buffer index."
4770 "2) When using an array of descriptors in a single WriteDescriptor,"
4771 " the descriptor types and stageflags must all be the same."
4772 "3) Immutable Sampler state must match across descriptors");
4773
4774 const char *invalid_BufferInfo_ErrorMessage =
4775 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4776 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4777 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4778 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004779 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004780 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004781 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004782
Mark Muellerd4914412016-06-13 17:52:06 -06004783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4784
4785 ASSERT_NO_FATAL_FAILURE(InitState());
4786 VkDescriptorPoolSize ds_type_count[4] = {};
4787 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4788 ds_type_count[0].descriptorCount = 1;
4789 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4790 ds_type_count[1].descriptorCount = 1;
4791 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4792 ds_type_count[2].descriptorCount = 1;
4793 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4794 ds_type_count[3].descriptorCount = 1;
4795
4796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4798 ds_pool_ci.maxSets = 1;
4799 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4800 ds_pool_ci.pPoolSizes = ds_type_count;
4801
4802 VkDescriptorPool ds_pool;
4803 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4804 ASSERT_VK_SUCCESS(err);
4805
Mark Muellerb9896722016-06-16 09:54:29 -06004806 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004807 layout_binding[0].binding = 0;
4808 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4809 layout_binding[0].descriptorCount = 1;
4810 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4811 layout_binding[0].pImmutableSamplers = NULL;
4812
4813 layout_binding[1].binding = 1;
4814 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4815 layout_binding[1].descriptorCount = 1;
4816 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4817 layout_binding[1].pImmutableSamplers = NULL;
4818
4819 VkSamplerCreateInfo sampler_ci = {};
4820 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4821 sampler_ci.pNext = NULL;
4822 sampler_ci.magFilter = VK_FILTER_NEAREST;
4823 sampler_ci.minFilter = VK_FILTER_NEAREST;
4824 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4825 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4826 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4827 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4828 sampler_ci.mipLodBias = 1.0;
4829 sampler_ci.anisotropyEnable = VK_FALSE;
4830 sampler_ci.maxAnisotropy = 1;
4831 sampler_ci.compareEnable = VK_FALSE;
4832 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4833 sampler_ci.minLod = 1.0;
4834 sampler_ci.maxLod = 1.0;
4835 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4836 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4837 VkSampler sampler;
4838
4839 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4840 ASSERT_VK_SUCCESS(err);
4841
4842 layout_binding[2].binding = 2;
4843 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4844 layout_binding[2].descriptorCount = 1;
4845 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4846 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4847
Mark Muellerd4914412016-06-13 17:52:06 -06004848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4850 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4851 ds_layout_ci.pBindings = layout_binding;
4852 VkDescriptorSetLayout ds_layout;
4853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4854 ASSERT_VK_SUCCESS(err);
4855
4856 VkDescriptorSetAllocateInfo alloc_info = {};
4857 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4858 alloc_info.descriptorSetCount = 1;
4859 alloc_info.descriptorPool = ds_pool;
4860 alloc_info.pSetLayouts = &ds_layout;
4861 VkDescriptorSet descriptorSet;
4862 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4863 ASSERT_VK_SUCCESS(err);
4864
4865 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4866 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4867 pipeline_layout_ci.pNext = NULL;
4868 pipeline_layout_ci.setLayoutCount = 1;
4869 pipeline_layout_ci.pSetLayouts = &ds_layout;
4870
4871 VkPipelineLayout pipeline_layout;
4872 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4873 ASSERT_VK_SUCCESS(err);
4874
Mark Mueller5c838ce2016-06-16 09:54:29 -06004875 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004876 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4877 descriptor_write.dstSet = descriptorSet;
4878 descriptor_write.dstBinding = 0;
4879 descriptor_write.descriptorCount = 1;
4880 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4881
Mark Mueller5c838ce2016-06-16 09:54:29 -06004882 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4884 m_errorMonitor->VerifyFound();
4885
4886 // Create a buffer to update the descriptor with
4887 uint32_t qfi = 0;
4888 VkBufferCreateInfo buffCI = {};
4889 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4890 buffCI.size = 1024;
4891 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4892 buffCI.queueFamilyIndexCount = 1;
4893 buffCI.pQueueFamilyIndices = &qfi;
4894
4895 VkBuffer dyub;
4896 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4897 ASSERT_VK_SUCCESS(err);
4898 VkDescriptorBufferInfo buffInfo = {};
4899 buffInfo.buffer = dyub;
4900 buffInfo.offset = 0;
4901 buffInfo.range = 1024;
4902
4903 descriptor_write.pBufferInfo = &buffInfo;
4904 descriptor_write.descriptorCount = 2;
4905
Mark Mueller5c838ce2016-06-16 09:54:29 -06004906 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4908 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4909 m_errorMonitor->VerifyFound();
4910
Mark Mueller5c838ce2016-06-16 09:54:29 -06004911 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4912 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004913 descriptor_write.dstBinding = 1;
4914 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004915
4916
4917 // Make pImageInfo index non-null to avoid complaints of it missing
4918 VkDescriptorImageInfo imageInfo = {};
4919 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4920 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4923 m_errorMonitor->VerifyFound();
4924
Mark Muellerd4914412016-06-13 17:52:06 -06004925 vkDestroyBuffer(m_device->device(), dyub, NULL);
4926 vkDestroySampler(m_device->device(), sampler, NULL);
4927 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4928 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4929 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4930}
4931
Karl Schultz6addd812016-02-02 17:17:23 -07004932TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004933 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4934 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004935 // Create a valid cmd buffer
4936 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004937 uint64_t fake_pipeline_handle = 0xbaad6001;
4938 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4940 "Invalid VkPipeline Object 0xbaad6001");
4941 ASSERT_NO_FATAL_FAILURE(InitState());
4942 BeginCommandBuffer();
4943 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4944 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4945 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004946 // Now issue a draw call with no pipeline bound
4947 m_errorMonitor->SetDesiredFailureMsg(
4948 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4949 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004950
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004951 BeginCommandBuffer();
4952 Draw(1, 0, 0, 0);
4953 m_errorMonitor->VerifyFound();
4954 // Finally same check once more but with Dispatch/Compute
4955 m_errorMonitor->SetDesiredFailureMsg(
4956 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4957 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004958 BeginCommandBuffer();
4959 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4960 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004961}
4962
Karl Schultz6addd812016-02-02 17:17:23 -07004963TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4964 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4965 // CommandBuffer
4966 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004967
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004969 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004970
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004971 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004972 ASSERT_NO_FATAL_FAILURE(InitViewport());
4973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004974 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004975 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4976 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004977
4978 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004979 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4980 ds_pool_ci.pNext = NULL;
4981 ds_pool_ci.maxSets = 1;
4982 ds_pool_ci.poolSizeCount = 1;
4983 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004984
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004985 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004986 err =
4987 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004989
Tony Barboureb254902015-07-15 12:50:33 -06004990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004991 dsl_binding.binding = 0;
4992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4993 dsl_binding.descriptorCount = 1;
4994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4995 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004996
Tony Barboureb254902015-07-15 12:50:33 -06004997 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004998 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4999 ds_layout_ci.pNext = NULL;
5000 ds_layout_ci.bindingCount = 1;
5001 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005002 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5004 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005005 ASSERT_VK_SUCCESS(err);
5006
5007 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005008 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005010 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005011 alloc_info.descriptorPool = ds_pool;
5012 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5014 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005015 ASSERT_VK_SUCCESS(err);
5016
Tony Barboureb254902015-07-15 12:50:33 -06005017 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005018 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5019 pipeline_layout_ci.pNext = NULL;
5020 pipeline_layout_ci.setLayoutCount = 1;
5021 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005022
5023 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5025 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005026 ASSERT_VK_SUCCESS(err);
5027
Karl Schultz6addd812016-02-02 17:17:23 -07005028 VkShaderObj vs(m_device, bindStateVertShaderText,
5029 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005030 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005031 // on more devices
5032 VkShaderObj fs(m_device, bindStateFragShaderText,
5033 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005034
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005035 VkPipelineObj pipe(m_device);
5036 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005037 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005038 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005039 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005040
5041 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005042 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5043 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5044 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5045 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5046 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005047
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005048 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005049
Chia-I Wuf7458c52015-10-26 21:10:41 +08005050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005053}
5054
Karl Schultz6addd812016-02-02 17:17:23 -07005055TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005056 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005057 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005058
Karl Schultz6addd812016-02-02 17:17:23 -07005059 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005060 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5061 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005062
5063 ASSERT_NO_FATAL_FAILURE(InitState());
5064 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005065 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5066 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005067
5068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5070 ds_pool_ci.pNext = NULL;
5071 ds_pool_ci.maxSets = 1;
5072 ds_pool_ci.poolSizeCount = 1;
5073 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005074
5075 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005076 err =
5077 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005078 ASSERT_VK_SUCCESS(err);
5079
5080 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005081 dsl_binding.binding = 0;
5082 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5083 dsl_binding.descriptorCount = 1;
5084 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5085 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005086
5087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5089 ds_layout_ci.pNext = NULL;
5090 ds_layout_ci.bindingCount = 1;
5091 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005092 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005093 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5094 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005095 ASSERT_VK_SUCCESS(err);
5096
5097 VkDescriptorSet descriptorSet;
5098 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005099 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005100 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005101 alloc_info.descriptorPool = ds_pool;
5102 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005103 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5104 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005105 ASSERT_VK_SUCCESS(err);
5106
Karl Schultz6addd812016-02-02 17:17:23 -07005107 VkBufferView view =
5108 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005109 VkWriteDescriptorSet descriptor_write;
5110 memset(&descriptor_write, 0, sizeof(descriptor_write));
5111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5112 descriptor_write.dstSet = descriptorSet;
5113 descriptor_write.dstBinding = 0;
5114 descriptor_write.descriptorCount = 1;
5115 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5116 descriptor_write.pTexelBufferView = &view;
5117
5118 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5119
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005120 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005121
5122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5123 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5124}
5125
Karl Schultz6addd812016-02-02 17:17:23 -07005126TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5127 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5128 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005129 // 1. No dynamicOffset supplied
5130 // 2. Too many dynamicOffsets supplied
5131 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005132 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005134 " requires 1 dynamicOffsets, but only "
5135 "0 dynamicOffsets are left in "
5136 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005137
5138 ASSERT_NO_FATAL_FAILURE(InitState());
5139 ASSERT_NO_FATAL_FAILURE(InitViewport());
5140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5141
5142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5144 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005145
5146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5148 ds_pool_ci.pNext = NULL;
5149 ds_pool_ci.maxSets = 1;
5150 ds_pool_ci.poolSizeCount = 1;
5151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005152
5153 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005154 err =
5155 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005156 ASSERT_VK_SUCCESS(err);
5157
5158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005159 dsl_binding.binding = 0;
5160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5161 dsl_binding.descriptorCount = 1;
5162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005164
5165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5167 ds_layout_ci.pNext = NULL;
5168 ds_layout_ci.bindingCount = 1;
5169 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005170 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005171 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5172 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005173 ASSERT_VK_SUCCESS(err);
5174
5175 VkDescriptorSet descriptorSet;
5176 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005178 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005179 alloc_info.descriptorPool = ds_pool;
5180 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5182 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5187 pipeline_layout_ci.pNext = NULL;
5188 pipeline_layout_ci.setLayoutCount = 1;
5189 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005190
5191 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5193 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005194 ASSERT_VK_SUCCESS(err);
5195
5196 // Create a buffer to update the descriptor with
5197 uint32_t qfi = 0;
5198 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005199 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5200 buffCI.size = 1024;
5201 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5202 buffCI.queueFamilyIndexCount = 1;
5203 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005204
5205 VkBuffer dyub;
5206 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5207 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005208 // Allocate memory and bind to buffer so we can make it to the appropriate
5209 // error
5210 VkMemoryAllocateInfo mem_alloc = {};
5211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5212 mem_alloc.pNext = NULL;
5213 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005214 mem_alloc.memoryTypeIndex = 0;
5215
5216 VkMemoryRequirements memReqs;
5217 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5218 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5219 0);
5220 if (!pass) {
5221 vkDestroyBuffer(m_device->device(), dyub, NULL);
5222 return;
5223 }
5224
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005225 VkDeviceMemory mem;
5226 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5227 ASSERT_VK_SUCCESS(err);
5228 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5229 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005230 // Correctly update descriptor to avoid "NOT_UPDATED" error
5231 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005232 buffInfo.buffer = dyub;
5233 buffInfo.offset = 0;
5234 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005235
5236 VkWriteDescriptorSet descriptor_write;
5237 memset(&descriptor_write, 0, sizeof(descriptor_write));
5238 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5239 descriptor_write.dstSet = descriptorSet;
5240 descriptor_write.dstBinding = 0;
5241 descriptor_write.descriptorCount = 1;
5242 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5243 descriptor_write.pBufferInfo = &buffInfo;
5244
5245 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5246
5247 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005248 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5249 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5250 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005251 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005252 uint32_t pDynOff[2] = {512, 756};
5253 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005254 m_errorMonitor->SetDesiredFailureMsg(
5255 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005256 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005257 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5258 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5259 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005260 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005261 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5263 " dynamic offset 512 combined with "
5264 "offset 0 and range 1024 that "
5265 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005266 // Create PSO to be used for draw-time errors below
5267 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005268 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005269 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005270 "out gl_PerVertex { \n"
5271 " vec4 gl_Position;\n"
5272 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005273 "void main(){\n"
5274 " gl_Position = vec4(1);\n"
5275 "}\n";
5276 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005277 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005278 "\n"
5279 "layout(location=0) out vec4 x;\n"
5280 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5281 "void main(){\n"
5282 " x = vec4(bar.y);\n"
5283 "}\n";
5284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5286 VkPipelineObj pipe(m_device);
5287 pipe.AddShader(&vs);
5288 pipe.AddShader(&fs);
5289 pipe.AddColorAttachment();
5290 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5291
Karl Schultz6addd812016-02-02 17:17:23 -07005292 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5293 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5294 // This update should succeed, but offset size of 512 will overstep buffer
5295 // /w range 1024 & size 1024
5296 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5297 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5298 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005299 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005300 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005301
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005302 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005303 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005304
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5308}
5309
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005310TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005311 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005312 ASSERT_NO_FATAL_FAILURE(InitState());
5313 ASSERT_NO_FATAL_FAILURE(InitViewport());
5314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5315
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005316 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005317 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005318 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5319 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5320 pipeline_layout_ci.pushConstantRangeCount = 1;
5321 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5322
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005323 //
5324 // Check for invalid push constant ranges in pipeline layouts.
5325 //
5326 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005327 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005328 char const *msg;
5329 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005330
Karl Schultzc81037d2016-05-12 08:11:23 -06005331 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5332 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5333 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5334 "vkCreatePipelineLayout() call has push constants index 0 with "
5335 "size 0."},
5336 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5337 "vkCreatePipelineLayout() call has push constants index 0 with "
5338 "size 1."},
5339 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5340 "vkCreatePipelineLayout() call has push constants index 0 with "
5341 "size 1."},
5342 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5343 "vkCreatePipelineLayout() call has push constants index 0 with "
5344 "size 0."},
5345 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5346 "vkCreatePipelineLayout() call has push constants index 0 with "
5347 "offset 1. Offset must"},
5348 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5349 "vkCreatePipelineLayout() call has push constants index 0 "
5350 "with offset "},
5351 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5352 "vkCreatePipelineLayout() call has push constants "
5353 "index 0 with offset "},
5354 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5355 "vkCreatePipelineLayout() call has push constants index 0 "
5356 "with offset "},
5357 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5358 "vkCreatePipelineLayout() call has push "
5359 "constants index 0 with offset "},
5360 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5361 "vkCreatePipelineLayout() call has push "
5362 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005363 }};
5364
5365 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005366 for (const auto &iter : range_tests) {
5367 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5369 iter.msg);
5370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5371 NULL, &pipeline_layout);
5372 m_errorMonitor->VerifyFound();
5373 if (VK_SUCCESS == err) {
5374 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5375 }
5376 }
5377
5378 // Check for invalid stage flag
5379 pc_range.offset = 0;
5380 pc_range.size = 16;
5381 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005382 m_errorMonitor->SetDesiredFailureMsg(
5383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005384 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5386 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005387 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005388 if (VK_SUCCESS == err) {
5389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5390 }
5391
5392 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005393 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005394 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005395 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005396 char const *msg;
5397 };
5398
Karl Schultzc81037d2016-05-12 08:11:23 -06005399 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005400 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5401 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5402 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5403 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5404 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5405 "vkCreatePipelineLayout() call has push constants with overlapping "
5406 "ranges: 0:[0, 4), 1:[0, 4)"},
5407 {
5408 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5409 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5410 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5411 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5412 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5413 "vkCreatePipelineLayout() call has push constants with "
5414 "overlapping "
5415 "ranges: 3:[12, 20), 4:[16, 20)",
5416 },
5417 {
5418 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5419 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5420 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5421 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5422 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5423 "vkCreatePipelineLayout() call has push constants with "
5424 "overlapping "
5425 "ranges: 0:[16, 20), 1:[12, 20)",
5426 },
5427 {
5428 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5429 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5430 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5431 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5432 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5433 "vkCreatePipelineLayout() call has push constants with "
5434 "overlapping "
5435 "ranges: 0:[16, 20), 3:[12, 20)",
5436 },
5437 {
5438 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5439 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5440 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5441 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5442 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5443 "vkCreatePipelineLayout() call has push constants with "
5444 "overlapping "
5445 "ranges: 0:[16, 20), 2:[4, 100)",
5446 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005447
Karl Schultzc81037d2016-05-12 08:11:23 -06005448 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005449 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005450 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005452 iter.msg);
5453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5454 NULL, &pipeline_layout);
5455 m_errorMonitor->VerifyFound();
5456 if (VK_SUCCESS == err) {
5457 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5458 }
5459 }
5460
5461 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005462 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5463 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5464 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5465 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5466 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5467 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5468 ""},
5469 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5470 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5471 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5472 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5473 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5474 ""}}};
5475 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005476 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5477 m_errorMonitor->ExpectSuccess();
5478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5479 NULL, &pipeline_layout);
5480 m_errorMonitor->VerifyNotFound();
5481 if (VK_SUCCESS == err) {
5482 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5483 }
5484 }
5485
5486 //
5487 // CmdPushConstants tests
5488 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005489 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005490
5491 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005492 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5493 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5494 "vkCmdPushConstants() call has push constants with size 0. Size "
5495 "must be greater than zero and a multiple of 4."},
5496 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5497 "vkCmdPushConstants() call has push constants with size 1. Size "
5498 "must be greater than zero and a multiple of 4."},
5499 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5500 "vkCmdPushConstants() call has push constants with size 1. Size "
5501 "must be greater than zero and a multiple of 4."},
5502 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5503 "vkCmdPushConstants() call has push constants with offset 1. "
5504 "Offset must be a multiple of 4."},
5505 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5506 "vkCmdPushConstants() call has push constants with offset 1. "
5507 "Offset must be a multiple of 4."},
5508 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5509 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5510 "0x1 not within flag-matching ranges in pipeline layout"},
5511 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5512 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5513 "0x1 not within flag-matching ranges in pipeline layout"},
5514 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5515 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5516 "0x1 not within flag-matching ranges in pipeline layout"},
5517 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5518 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5519 "0x1 not within flag-matching ranges in pipeline layout"},
5520 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5521 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5522 "any of the ranges in pipeline layout"},
5523 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5524 0, 16},
5525 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5526 "any of the ranges in pipeline layout"},
5527 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005528 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005529 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005530 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005531 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005532 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005533 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005534 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005535 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005536 "vkCmdPushConstants() call has push constants with offset "},
5537 }};
5538
5539 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005540 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005541 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005542 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005543 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005544 pipeline_layout_ci.pushConstantRangeCount =
5545 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005546 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5548 &pipeline_layout);
5549 ASSERT_VK_SUCCESS(err);
5550 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005551 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5553 iter.msg);
5554 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005555 iter.range.stageFlags, iter.range.offset,
5556 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005557 m_errorMonitor->VerifyFound();
5558 }
5559
5560 // Check for invalid stage flag
5561 m_errorMonitor->SetDesiredFailureMsg(
5562 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5563 "vkCmdPushConstants() call has no stageFlags set.");
5564 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005565 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005566 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005567 EndCommandBuffer();
5568 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5569 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005570
Karl Schultzc81037d2016-05-12 08:11:23 -06005571 // overlapping range tests with cmd
5572 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5573 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5574 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5575 "0x1 not within flag-matching ranges in pipeline layout"},
5576 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5577 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5578 "0x1 not within flag-matching ranges in pipeline layout"},
5579 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5580 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5581 "0x1 not within flag-matching ranges in pipeline layout"},
5582 }};
5583 const VkPushConstantRange pc_range3[] = {
5584 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5585 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5586 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5587 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5588 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5589 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5590 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5591 };
5592 pipeline_layout_ci.pushConstantRangeCount =
5593 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5594 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5595 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5596 &pipeline_layout);
5597 ASSERT_VK_SUCCESS(err);
5598 BeginCommandBuffer();
5599 for (const auto &iter : cmd_overlap_tests) {
5600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5601 iter.msg);
5602 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5603 iter.range.stageFlags, iter.range.offset,
5604 iter.range.size, dummy_values);
5605 m_errorMonitor->VerifyFound();
5606 }
5607 EndCommandBuffer();
5608 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5609 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5610
5611 // positive overlapping range tests with cmd
5612 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5613 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5614 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5615 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5616 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5617 }};
5618 const VkPushConstantRange pc_range4[] = {
5619 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5620 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5621 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5622 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5623 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5624 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5625 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5626 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5627 };
5628 pipeline_layout_ci.pushConstantRangeCount =
5629 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5630 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5631 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5632 &pipeline_layout);
5633 ASSERT_VK_SUCCESS(err);
5634 BeginCommandBuffer();
5635 for (const auto &iter : cmd_overlap_tests_pos) {
5636 m_errorMonitor->ExpectSuccess();
5637 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5638 iter.range.stageFlags, iter.range.offset,
5639 iter.range.size, dummy_values);
5640 m_errorMonitor->VerifyNotFound();
5641 }
5642 EndCommandBuffer();
5643 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005644 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5645}
5646
Karl Schultz6addd812016-02-02 17:17:23 -07005647TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005648 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005649 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005650
5651 ASSERT_NO_FATAL_FAILURE(InitState());
5652 ASSERT_NO_FATAL_FAILURE(InitViewport());
5653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5654
5655 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5656 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005657 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5658 ds_type_count[0].descriptorCount = 10;
5659 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5660 ds_type_count[1].descriptorCount = 2;
5661 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5662 ds_type_count[2].descriptorCount = 2;
5663 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5664 ds_type_count[3].descriptorCount = 5;
5665 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5666 // type
5667 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5668 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5669 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005670
5671 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005672 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5673 ds_pool_ci.pNext = NULL;
5674 ds_pool_ci.maxSets = 5;
5675 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5676 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005677
5678 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005679 err =
5680 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005681 ASSERT_VK_SUCCESS(err);
5682
5683 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5684 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005685 dsl_binding[0].binding = 0;
5686 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5687 dsl_binding[0].descriptorCount = 5;
5688 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5689 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005690
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005691 // Create layout identical to set0 layout but w/ different stageFlags
5692 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005693 dsl_fs_stage_only.binding = 0;
5694 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5695 dsl_fs_stage_only.descriptorCount = 5;
5696 dsl_fs_stage_only.stageFlags =
5697 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5698 // bind time
5699 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5702 ds_layout_ci.pNext = NULL;
5703 ds_layout_ci.bindingCount = 1;
5704 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005705 static const uint32_t NUM_LAYOUTS = 4;
5706 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005707 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005708 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5709 // layout for error case
5710 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5711 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005712 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005713 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5715 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005717 dsl_binding[0].binding = 0;
5718 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005719 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005720 dsl_binding[1].binding = 1;
5721 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5722 dsl_binding[1].descriptorCount = 2;
5723 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5724 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005725 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005726 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005727 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5728 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005729 ASSERT_VK_SUCCESS(err);
5730 dsl_binding[0].binding = 0;
5731 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005732 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005733 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5735 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005736 ASSERT_VK_SUCCESS(err);
5737 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005738 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5740 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005741 ASSERT_VK_SUCCESS(err);
5742
5743 static const uint32_t NUM_SETS = 4;
5744 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5745 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005747 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005748 alloc_info.descriptorPool = ds_pool;
5749 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5751 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005752 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005753 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005754 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005755 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005756 err =
5757 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005758 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005759
5760 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005761 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5762 pipeline_layout_ci.pNext = NULL;
5763 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5764 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005765
5766 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005767 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5768 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005769 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005770 // Create pipelineLayout with only one setLayout
5771 pipeline_layout_ci.setLayoutCount = 1;
5772 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005773 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5774 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005775 ASSERT_VK_SUCCESS(err);
5776 // Create pipelineLayout with 2 descriptor setLayout at index 0
5777 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5778 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005779 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5780 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005781 ASSERT_VK_SUCCESS(err);
5782 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5783 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5784 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5786 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005787 ASSERT_VK_SUCCESS(err);
5788 // Create pipelineLayout with UB type, but stageFlags for FS only
5789 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5790 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005791 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5792 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005793 ASSERT_VK_SUCCESS(err);
5794 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5795 VkDescriptorSetLayout pl_bad_s0[2] = {};
5796 pl_bad_s0[0] = ds_layout_fs_only;
5797 pl_bad_s0[1] = ds_layout[1];
5798 pipeline_layout_ci.setLayoutCount = 2;
5799 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5800 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005801 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5802 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005803 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005804
5805 // Create a buffer to update the descriptor with
5806 uint32_t qfi = 0;
5807 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005808 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5809 buffCI.size = 1024;
5810 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5811 buffCI.queueFamilyIndexCount = 1;
5812 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005813
5814 VkBuffer dyub;
5815 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5816 ASSERT_VK_SUCCESS(err);
5817 // Correctly update descriptor to avoid "NOT_UPDATED" error
5818 static const uint32_t NUM_BUFFS = 5;
5819 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005820 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005821 buffInfo[i].buffer = dyub;
5822 buffInfo[i].offset = 0;
5823 buffInfo[i].range = 1024;
5824 }
Karl Schultz6addd812016-02-02 17:17:23 -07005825 VkImage image;
5826 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5827 const int32_t tex_width = 32;
5828 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005829 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005830 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5831 image_create_info.pNext = NULL;
5832 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5833 image_create_info.format = tex_format;
5834 image_create_info.extent.width = tex_width;
5835 image_create_info.extent.height = tex_height;
5836 image_create_info.extent.depth = 1;
5837 image_create_info.mipLevels = 1;
5838 image_create_info.arrayLayers = 1;
5839 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5840 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5841 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5842 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005843 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5844 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005845
Karl Schultz6addd812016-02-02 17:17:23 -07005846 VkMemoryRequirements memReqs;
5847 VkDeviceMemory imageMem;
5848 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005849 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005850 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5851 memAlloc.pNext = NULL;
5852 memAlloc.allocationSize = 0;
5853 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005854 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5855 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005856 pass =
5857 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005858 ASSERT_TRUE(pass);
5859 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5860 ASSERT_VK_SUCCESS(err);
5861 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5862 ASSERT_VK_SUCCESS(err);
5863
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005864 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005865 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5866 image_view_create_info.image = image;
5867 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5868 image_view_create_info.format = tex_format;
5869 image_view_create_info.subresourceRange.layerCount = 1;
5870 image_view_create_info.subresourceRange.baseMipLevel = 0;
5871 image_view_create_info.subresourceRange.levelCount = 1;
5872 image_view_create_info.subresourceRange.aspectMask =
5873 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005874
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005875 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005876 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5877 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005878 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005879 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005880 imageInfo[0].imageView = view;
5881 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5882 imageInfo[1].imageView = view;
5883 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005884 imageInfo[2].imageView = view;
5885 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5886 imageInfo[3].imageView = view;
5887 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005888
5889 static const uint32_t NUM_SET_UPDATES = 3;
5890 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5891 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5892 descriptor_write[0].dstSet = descriptorSet[0];
5893 descriptor_write[0].dstBinding = 0;
5894 descriptor_write[0].descriptorCount = 5;
5895 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5896 descriptor_write[0].pBufferInfo = buffInfo;
5897 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5898 descriptor_write[1].dstSet = descriptorSet[1];
5899 descriptor_write[1].dstBinding = 0;
5900 descriptor_write[1].descriptorCount = 2;
5901 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5902 descriptor_write[1].pImageInfo = imageInfo;
5903 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5904 descriptor_write[2].dstSet = descriptorSet[1];
5905 descriptor_write[2].dstBinding = 1;
5906 descriptor_write[2].descriptorCount = 2;
5907 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005908 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005909
5910 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005911
Tobin Ehlis88452832015-12-03 09:40:56 -07005912 // Create PSO to be used for draw-time errors below
5913 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005914 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005915 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005916 "out gl_PerVertex {\n"
5917 " vec4 gl_Position;\n"
5918 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005919 "void main(){\n"
5920 " gl_Position = vec4(1);\n"
5921 "}\n";
5922 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005923 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005924 "\n"
5925 "layout(location=0) out vec4 x;\n"
5926 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5927 "void main(){\n"
5928 " x = vec4(bar.y);\n"
5929 "}\n";
5930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005932 VkPipelineObj pipe(m_device);
5933 pipe.AddShader(&vs);
5934 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005935 pipe.AddColorAttachment();
5936 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005937
5938 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005939
Karl Schultz6addd812016-02-02 17:17:23 -07005940 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5941 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5942 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5943 // of PSO
5944 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5945 // cmd_pipeline.c
5946 // due to the fact that cmd_alloc_dset_data() has not been called in
5947 // cmd_bind_graphics_pipeline()
5948 // TODO : Want to cause various binding incompatibility issues here to test
5949 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005950 // First cause various verify_layout_compatibility() fails
5951 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005952 // verify_set_layout_compatibility fail cases:
5953 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5955 " due to: invalid VkPipelineLayout ");
5956 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5957 VK_PIPELINE_BIND_POINT_GRAPHICS,
5958 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5959 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005960 m_errorMonitor->VerifyFound();
5961
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005962 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5964 " attempting to bind set to index 1");
5965 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5966 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5967 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005968 m_errorMonitor->VerifyFound();
5969
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005970 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005971 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5972 // descriptors
5973 m_errorMonitor->SetDesiredFailureMsg(
5974 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005975 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005976 vkCmdBindDescriptorSets(
5977 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5978 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005979 m_errorMonitor->VerifyFound();
5980
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005981 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5982 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005983 m_errorMonitor->SetDesiredFailureMsg(
5984 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005985 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005986 vkCmdBindDescriptorSets(
5987 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5988 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005989 m_errorMonitor->VerifyFound();
5990
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005991 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5992 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005993 m_errorMonitor->SetDesiredFailureMsg(
5994 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005995 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005996 vkCmdBindDescriptorSets(
5997 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5998 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005999 m_errorMonitor->VerifyFound();
6000
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006001 // Cause INFO messages due to disturbing previously bound Sets
6002 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006003 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6004 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6005 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006006 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006007 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006008 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006009 " previously bound as set #0 was disturbed ");
6010 vkCmdBindDescriptorSets(
6011 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6012 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006013 m_errorMonitor->VerifyFound();
6014
Karl Schultz6addd812016-02-02 17:17:23 -07006015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6016 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6017 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006018 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006020 " newly bound as set #0 so set #1 and "
6021 "any subsequent sets were disturbed ");
6022 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6023 VK_PIPELINE_BIND_POINT_GRAPHICS,
6024 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006025 m_errorMonitor->VerifyFound();
6026
Tobin Ehlis88452832015-12-03 09:40:56 -07006027 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006028 // 1. Error due to not binding required set (we actually use same code as
6029 // above to disturb set0)
6030 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6031 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6032 2, &descriptorSet[0], 0, NULL);
6033 vkCmdBindDescriptorSets(
6034 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6035 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6036 m_errorMonitor->SetDesiredFailureMsg(
6037 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6038 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006039 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006040 m_errorMonitor->VerifyFound();
6041
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006042 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006043 // 2. Error due to bound set not being compatible with PSO's
6044 // VkPipelineLayout (diff stageFlags in this case)
6045 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6046 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6047 2, &descriptorSet[0], 0, NULL);
6048 m_errorMonitor->SetDesiredFailureMsg(
6049 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6050 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006051 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006052 m_errorMonitor->VerifyFound();
6053
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006054 // Remaining clean-up
6055 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006056 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006057 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6058 }
6059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006060 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6061 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006062 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006063 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6064 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006065 vkFreeMemory(m_device->device(), imageMem, NULL);
6066 vkDestroyImage(m_device->device(), image, NULL);
6067 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006068}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006069
Karl Schultz6addd812016-02-02 17:17:23 -07006070TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006071
Karl Schultz6addd812016-02-02 17:17:23 -07006072 m_errorMonitor->SetDesiredFailureMsg(
6073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006074 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006075
6076 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006077 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006078 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006079 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006080
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006081 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006082}
6083
Karl Schultz6addd812016-02-02 17:17:23 -07006084TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6085 VkResult err;
6086 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006087
Karl Schultz6addd812016-02-02 17:17:23 -07006088 m_errorMonitor->SetDesiredFailureMsg(
6089 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006090 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006091
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006092 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006093
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006094 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006095 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006096 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006097 cmd.commandPool = m_commandPool;
6098 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006099 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006100
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006101 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006102 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006103
6104 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006105 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006106 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006107 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006108 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006109 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6110 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006111 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006112
6113 // The error should be caught by validation of the BeginCommandBuffer call
6114 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6115
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006116 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006117 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006118}
6119
Karl Schultz6addd812016-02-02 17:17:23 -07006120TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006121 // Cause error due to Begin while recording CB
6122 // Then cause 2 errors for attempting to reset CB w/o having
6123 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6124 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006126 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006127
6128 ASSERT_NO_FATAL_FAILURE(InitState());
6129
6130 // Calls AllocateCommandBuffers
6131 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6132
Karl Schultz6addd812016-02-02 17:17:23 -07006133 // Force the failure by setting the Renderpass and Framebuffer fields with
6134 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006135 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006136 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006137 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6138 cmd_buf_info.pNext = NULL;
6139 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006140 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006141
6142 // Begin CB to transition to recording state
6143 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6144 // Can't re-begin. This should trigger error
6145 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006146 m_errorMonitor->VerifyFound();
6147
Karl Schultz6addd812016-02-02 17:17:23 -07006148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6149 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006150 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6151 // Reset attempt will trigger error due to incorrect CommandPool state
6152 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006153 m_errorMonitor->VerifyFound();
6154
Karl Schultz6addd812016-02-02 17:17:23 -07006155 m_errorMonitor->SetDesiredFailureMsg(
6156 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6157 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006158 // Transition CB to RECORDED state
6159 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6160 // Now attempting to Begin will implicitly reset, which triggers error
6161 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006162 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006163}
6164
Karl Schultz6addd812016-02-02 17:17:23 -07006165TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006166 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006167 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006168
Karl Schultz6addd812016-02-02 17:17:23 -07006169 m_errorMonitor->SetDesiredFailureMsg(
6170 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006171 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6172
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006173 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006175
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006176 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006177 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6178 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006179
6180 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006181 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6182 ds_pool_ci.pNext = NULL;
6183 ds_pool_ci.maxSets = 1;
6184 ds_pool_ci.poolSizeCount = 1;
6185 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006186
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006187 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006188 err =
6189 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006190 ASSERT_VK_SUCCESS(err);
6191
Tony Barboureb254902015-07-15 12:50:33 -06006192 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006193 dsl_binding.binding = 0;
6194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6195 dsl_binding.descriptorCount = 1;
6196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6197 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006198
Tony Barboureb254902015-07-15 12:50:33 -06006199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6201 ds_layout_ci.pNext = NULL;
6202 ds_layout_ci.bindingCount = 1;
6203 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006204
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006205 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6207 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006208 ASSERT_VK_SUCCESS(err);
6209
6210 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006211 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006212 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006213 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006214 alloc_info.descriptorPool = ds_pool;
6215 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006216 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6217 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006218 ASSERT_VK_SUCCESS(err);
6219
Tony Barboureb254902015-07-15 12:50:33 -06006220 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006221 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6222 pipeline_layout_ci.setLayoutCount = 1;
6223 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006224
6225 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006226 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6227 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006228 ASSERT_VK_SUCCESS(err);
6229
Tobin Ehlise68360f2015-10-01 11:15:13 -06006230 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006231 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006232
6233 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006234 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6235 vp_state_ci.scissorCount = 1;
6236 vp_state_ci.pScissors = &sc;
6237 vp_state_ci.viewportCount = 1;
6238 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006239
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006240 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6241 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6242 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6243 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6244 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6245 rs_state_ci.depthClampEnable = VK_FALSE;
6246 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6247 rs_state_ci.depthBiasEnable = VK_FALSE;
6248
Tony Barboureb254902015-07-15 12:50:33 -06006249 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006250 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6251 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006252 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006253 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6254 gp_ci.layout = pipeline_layout;
6255 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006256
6257 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006258 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6259 pc_ci.initialDataSize = 0;
6260 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006261
6262 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006263 VkPipelineCache pipelineCache;
6264
Karl Schultz6addd812016-02-02 17:17:23 -07006265 err =
6266 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006267 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006268 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6269 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006270
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006271 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006272
Chia-I Wuf7458c52015-10-26 21:10:41 +08006273 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6275 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6276 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006277}
Tobin Ehlis912df022015-09-17 08:46:18 -06006278/*// TODO : This test should be good, but needs Tess support in compiler to run
6279TEST_F(VkLayerTest, InvalidPatchControlPoints)
6280{
6281 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006282 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006283
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006285 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6286primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006287
Tobin Ehlis912df022015-09-17 08:46:18 -06006288 ASSERT_NO_FATAL_FAILURE(InitState());
6289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006290
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006291 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006292 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006293 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006294
6295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6297 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006298 ds_pool_ci.poolSizeCount = 1;
6299 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006300
6301 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006302 err = vkCreateDescriptorPool(m_device->device(),
6303VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006304 ASSERT_VK_SUCCESS(err);
6305
6306 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006307 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006309 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6311 dsl_binding.pImmutableSamplers = NULL;
6312
6313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006314 ds_layout_ci.sType =
6315VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006316 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006317 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006318 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006319
6320 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006321 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6322&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006323 ASSERT_VK_SUCCESS(err);
6324
6325 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006326 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6327VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006328 ASSERT_VK_SUCCESS(err);
6329
6330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006331 pipeline_layout_ci.sType =
6332VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006333 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006334 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006335 pipeline_layout_ci.pSetLayouts = &ds_layout;
6336
6337 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006338 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6339&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006340 ASSERT_VK_SUCCESS(err);
6341
6342 VkPipelineShaderStageCreateInfo shaderStages[3];
6343 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6344
Karl Schultz6addd812016-02-02 17:17:23 -07006345 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6346this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006347 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006348 VkShaderObj
6349tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6350this);
6351 VkShaderObj
6352te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6353this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006354
Karl Schultz6addd812016-02-02 17:17:23 -07006355 shaderStages[0].sType =
6356VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006357 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006358 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006359 shaderStages[1].sType =
6360VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006361 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006362 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006363 shaderStages[2].sType =
6364VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006365 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006366 shaderStages[2].shader = te.handle();
6367
6368 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006369 iaCI.sType =
6370VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006371 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006372
6373 VkPipelineTessellationStateCreateInfo tsCI = {};
6374 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6375 tsCI.patchControlPoints = 0; // This will cause an error
6376
6377 VkGraphicsPipelineCreateInfo gp_ci = {};
6378 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6379 gp_ci.pNext = NULL;
6380 gp_ci.stageCount = 3;
6381 gp_ci.pStages = shaderStages;
6382 gp_ci.pVertexInputState = NULL;
6383 gp_ci.pInputAssemblyState = &iaCI;
6384 gp_ci.pTessellationState = &tsCI;
6385 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006386 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006387 gp_ci.pMultisampleState = NULL;
6388 gp_ci.pDepthStencilState = NULL;
6389 gp_ci.pColorBlendState = NULL;
6390 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6391 gp_ci.layout = pipeline_layout;
6392 gp_ci.renderPass = renderPass();
6393
6394 VkPipelineCacheCreateInfo pc_ci = {};
6395 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6396 pc_ci.pNext = NULL;
6397 pc_ci.initialSize = 0;
6398 pc_ci.initialData = 0;
6399 pc_ci.maxSize = 0;
6400
6401 VkPipeline pipeline;
6402 VkPipelineCache pipelineCache;
6403
Karl Schultz6addd812016-02-02 17:17:23 -07006404 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6405&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006406 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006407 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6408&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006409
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006410 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006411
Chia-I Wuf7458c52015-10-26 21:10:41 +08006412 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6413 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6414 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006416}
6417*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006418// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006419TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006420 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006421
Karl Schultz6addd812016-02-02 17:17:23 -07006422 m_errorMonitor->SetDesiredFailureMsg(
6423 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006424 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6425
Tobin Ehlise68360f2015-10-01 11:15:13 -06006426 ASSERT_NO_FATAL_FAILURE(InitState());
6427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006428
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006429 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006430 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6431 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006432
6433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6435 ds_pool_ci.maxSets = 1;
6436 ds_pool_ci.poolSizeCount = 1;
6437 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006438
6439 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006440 err =
6441 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006442 ASSERT_VK_SUCCESS(err);
6443
6444 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006445 dsl_binding.binding = 0;
6446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6447 dsl_binding.descriptorCount = 1;
6448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006449
6450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6452 ds_layout_ci.bindingCount = 1;
6453 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006454
6455 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6457 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006458 ASSERT_VK_SUCCESS(err);
6459
6460 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006461 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006463 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006464 alloc_info.descriptorPool = ds_pool;
6465 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6467 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006468 ASSERT_VK_SUCCESS(err);
6469
6470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6472 pipeline_layout_ci.setLayoutCount = 1;
6473 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006474
6475 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6477 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006478 ASSERT_VK_SUCCESS(err);
6479
6480 VkViewport vp = {}; // Just need dummy vp to point to
6481
6482 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006483 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6484 vp_state_ci.scissorCount = 0;
6485 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6486 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006487
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006488 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6489 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6490 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6491 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6492 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6493 rs_state_ci.depthClampEnable = VK_FALSE;
6494 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6495 rs_state_ci.depthBiasEnable = VK_FALSE;
6496
Cody Northropeb3a6c12015-10-05 14:44:45 -06006497 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006498 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006499
Karl Schultz6addd812016-02-02 17:17:23 -07006500 VkShaderObj vs(m_device, bindStateVertShaderText,
6501 VK_SHADER_STAGE_VERTEX_BIT, this);
6502 VkShaderObj fs(m_device, bindStateFragShaderText,
6503 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006504 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006505 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006506 shaderStages[0] = vs.GetStageCreateInfo();
6507 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006508
6509 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006510 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6511 gp_ci.stageCount = 2;
6512 gp_ci.pStages = shaderStages;
6513 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006514 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6516 gp_ci.layout = pipeline_layout;
6517 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006518
6519 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006520 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006521
6522 VkPipeline pipeline;
6523 VkPipelineCache pipelineCache;
6524
Karl Schultz6addd812016-02-02 17:17:23 -07006525 err =
6526 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006527 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006528 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6529 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006530
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006531 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006532
Chia-I Wuf7458c52015-10-26 21:10:41 +08006533 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006537}
Karl Schultz6addd812016-02-02 17:17:23 -07006538// Don't set viewport state in PSO. This is an error b/c we always need this
6539// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006540// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006541TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006542 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006543 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006544
Karl Schultz6addd812016-02-02 17:17:23 -07006545 m_errorMonitor->SetDesiredFailureMsg(
6546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006547 "Gfx Pipeline pViewportState is null. Even if ");
6548
Tobin Ehlise68360f2015-10-01 11:15:13 -06006549 ASSERT_NO_FATAL_FAILURE(InitState());
6550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006551
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006552 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006553 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6554 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006555
6556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6558 ds_pool_ci.maxSets = 1;
6559 ds_pool_ci.poolSizeCount = 1;
6560 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006561
6562 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006563 err =
6564 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006565 ASSERT_VK_SUCCESS(err);
6566
6567 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006568 dsl_binding.binding = 0;
6569 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6570 dsl_binding.descriptorCount = 1;
6571 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006572
6573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6575 ds_layout_ci.bindingCount = 1;
6576 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006577
6578 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6580 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006581 ASSERT_VK_SUCCESS(err);
6582
6583 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006584 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006586 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006587 alloc_info.descriptorPool = ds_pool;
6588 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6590 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006591 ASSERT_VK_SUCCESS(err);
6592
6593 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006594 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6595 pipeline_layout_ci.setLayoutCount = 1;
6596 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006597
6598 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006599 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6600 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006601 ASSERT_VK_SUCCESS(err);
6602
6603 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6604 // Set scissor as dynamic to avoid second error
6605 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6607 dyn_state_ci.dynamicStateCount = 1;
6608 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006609
Cody Northropeb3a6c12015-10-05 14:44:45 -06006610 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006611 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006612
Karl Schultz6addd812016-02-02 17:17:23 -07006613 VkShaderObj vs(m_device, bindStateVertShaderText,
6614 VK_SHADER_STAGE_VERTEX_BIT, this);
6615 VkShaderObj fs(m_device, bindStateFragShaderText,
6616 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006617 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006618 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006619 shaderStages[0] = vs.GetStageCreateInfo();
6620 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006621
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006622
6623 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6624 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6625 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6626 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6627 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6628 rs_state_ci.depthClampEnable = VK_FALSE;
6629 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6630 rs_state_ci.depthBiasEnable = VK_FALSE;
6631
Tobin Ehlise68360f2015-10-01 11:15:13 -06006632 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006633 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6634 gp_ci.stageCount = 2;
6635 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006636 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006637 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6638 // should cause validation error
6639 gp_ci.pDynamicState = &dyn_state_ci;
6640 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6641 gp_ci.layout = pipeline_layout;
6642 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006643
6644 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006645 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006646
6647 VkPipeline pipeline;
6648 VkPipelineCache pipelineCache;
6649
Karl Schultz6addd812016-02-02 17:17:23 -07006650 err =
6651 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006652 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006653 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6654 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006655
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006656 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006657
Chia-I Wuf7458c52015-10-26 21:10:41 +08006658 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6660 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6661 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006662}
6663// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006664// Then run second test where dynamic scissor count doesn't match PSO scissor
6665// count
6666TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6667 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006668
Karl Schultz6addd812016-02-02 17:17:23 -07006669 m_errorMonitor->SetDesiredFailureMsg(
6670 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006671 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6672
Tobin Ehlise68360f2015-10-01 11:15:13 -06006673 ASSERT_NO_FATAL_FAILURE(InitState());
6674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006675
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006676 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006677 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6678 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006679
6680 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006681 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6682 ds_pool_ci.maxSets = 1;
6683 ds_pool_ci.poolSizeCount = 1;
6684 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006685
6686 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006687 err =
6688 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006689 ASSERT_VK_SUCCESS(err);
6690
6691 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006692 dsl_binding.binding = 0;
6693 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6694 dsl_binding.descriptorCount = 1;
6695 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006696
6697 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006698 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6699 ds_layout_ci.bindingCount = 1;
6700 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006701
6702 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6704 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006705 ASSERT_VK_SUCCESS(err);
6706
6707 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006708 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006709 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006710 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006711 alloc_info.descriptorPool = ds_pool;
6712 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6714 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006715 ASSERT_VK_SUCCESS(err);
6716
6717 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006718 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6719 pipeline_layout_ci.setLayoutCount = 1;
6720 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006721
6722 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006723 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6724 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006725 ASSERT_VK_SUCCESS(err);
6726
6727 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006728 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6729 vp_state_ci.viewportCount = 1;
6730 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6731 vp_state_ci.scissorCount = 1;
6732 vp_state_ci.pScissors =
6733 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006734
6735 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6736 // Set scissor as dynamic to avoid that error
6737 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006738 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6739 dyn_state_ci.dynamicStateCount = 1;
6740 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006741
Cody Northropeb3a6c12015-10-05 14:44:45 -06006742 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006743 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006744
Karl Schultz6addd812016-02-02 17:17:23 -07006745 VkShaderObj vs(m_device, bindStateVertShaderText,
6746 VK_SHADER_STAGE_VERTEX_BIT, this);
6747 VkShaderObj fs(m_device, bindStateFragShaderText,
6748 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006749 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006750 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006751 shaderStages[0] = vs.GetStageCreateInfo();
6752 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006753
Cody Northropf6622dc2015-10-06 10:33:21 -06006754 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6755 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6756 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006757 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006758 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006759 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006760 vi_ci.pVertexAttributeDescriptions = nullptr;
6761
6762 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6763 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6764 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6765
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006766 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006767 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006768 rs_ci.pNext = nullptr;
6769
Mark Youngc89c6312016-03-31 16:03:20 -06006770 VkPipelineColorBlendAttachmentState att = {};
6771 att.blendEnable = VK_FALSE;
6772 att.colorWriteMask = 0xf;
6773
Cody Northropf6622dc2015-10-06 10:33:21 -06006774 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6775 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6776 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006777 cb_ci.attachmentCount = 1;
6778 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006779
Tobin Ehlise68360f2015-10-01 11:15:13 -06006780 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006781 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6782 gp_ci.stageCount = 2;
6783 gp_ci.pStages = shaderStages;
6784 gp_ci.pVertexInputState = &vi_ci;
6785 gp_ci.pInputAssemblyState = &ia_ci;
6786 gp_ci.pViewportState = &vp_state_ci;
6787 gp_ci.pRasterizationState = &rs_ci;
6788 gp_ci.pColorBlendState = &cb_ci;
6789 gp_ci.pDynamicState = &dyn_state_ci;
6790 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6791 gp_ci.layout = pipeline_layout;
6792 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006793
6794 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006796
6797 VkPipeline pipeline;
6798 VkPipelineCache pipelineCache;
6799
Karl Schultz6addd812016-02-02 17:17:23 -07006800 err =
6801 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006802 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006803 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6804 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006806 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006807
Tobin Ehlisd332f282015-10-02 11:00:56 -06006808 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006809 // First need to successfully create the PSO from above by setting
6810 // pViewports
6811 m_errorMonitor->SetDesiredFailureMsg(
6812 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6813 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6814 "scissorCount is 1. These counts must match.");
6815
6816 VkViewport vp = {}; // Just need dummy vp to point to
6817 vp_state_ci.pViewports = &vp;
6818 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6819 &gp_ci, NULL, &pipeline);
6820 ASSERT_VK_SUCCESS(err);
6821 BeginCommandBuffer();
6822 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6823 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6824 VkRect2D scissors[2] = {}; // don't care about data
6825 // Count of 2 doesn't match PSO count of 1
6826 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6827 Draw(1, 0, 0, 0);
6828
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006829 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006830
6831 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006835 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006836}
6837// Create PSO w/o non-zero scissorCount but no scissor data
6838// Then run second test where dynamic viewportCount doesn't match PSO
6839// viewportCount
6840TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6841 VkResult err;
6842
6843 m_errorMonitor->SetDesiredFailureMsg(
6844 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6845 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6846
6847 ASSERT_NO_FATAL_FAILURE(InitState());
6848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6849
6850 VkDescriptorPoolSize ds_type_count = {};
6851 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6852 ds_type_count.descriptorCount = 1;
6853
6854 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6855 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6856 ds_pool_ci.maxSets = 1;
6857 ds_pool_ci.poolSizeCount = 1;
6858 ds_pool_ci.pPoolSizes = &ds_type_count;
6859
6860 VkDescriptorPool ds_pool;
6861 err =
6862 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6863 ASSERT_VK_SUCCESS(err);
6864
6865 VkDescriptorSetLayoutBinding dsl_binding = {};
6866 dsl_binding.binding = 0;
6867 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6868 dsl_binding.descriptorCount = 1;
6869 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6870
6871 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6872 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6873 ds_layout_ci.bindingCount = 1;
6874 ds_layout_ci.pBindings = &dsl_binding;
6875
6876 VkDescriptorSetLayout ds_layout;
6877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6878 &ds_layout);
6879 ASSERT_VK_SUCCESS(err);
6880
6881 VkDescriptorSet descriptorSet;
6882 VkDescriptorSetAllocateInfo alloc_info = {};
6883 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6884 alloc_info.descriptorSetCount = 1;
6885 alloc_info.descriptorPool = ds_pool;
6886 alloc_info.pSetLayouts = &ds_layout;
6887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6888 &descriptorSet);
6889 ASSERT_VK_SUCCESS(err);
6890
6891 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6892 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6893 pipeline_layout_ci.setLayoutCount = 1;
6894 pipeline_layout_ci.pSetLayouts = &ds_layout;
6895
6896 VkPipelineLayout pipeline_layout;
6897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6898 &pipeline_layout);
6899 ASSERT_VK_SUCCESS(err);
6900
6901 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6902 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6903 vp_state_ci.scissorCount = 1;
6904 vp_state_ci.pScissors =
6905 NULL; // Null scissor w/ count of 1 should cause error
6906 vp_state_ci.viewportCount = 1;
6907 vp_state_ci.pViewports =
6908 NULL; // vp is dynamic (below) so this won't cause error
6909
6910 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6911 // Set scissor as dynamic to avoid that error
6912 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6913 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6914 dyn_state_ci.dynamicStateCount = 1;
6915 dyn_state_ci.pDynamicStates = &vp_state;
6916
6917 VkPipelineShaderStageCreateInfo shaderStages[2];
6918 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6919
6920 VkShaderObj vs(m_device, bindStateVertShaderText,
6921 VK_SHADER_STAGE_VERTEX_BIT, this);
6922 VkShaderObj fs(m_device, bindStateFragShaderText,
6923 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006924 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006925 // but add it to be able to run on more devices
6926 shaderStages[0] = vs.GetStageCreateInfo();
6927 shaderStages[1] = fs.GetStageCreateInfo();
6928
6929 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6930 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6931 vi_ci.pNext = nullptr;
6932 vi_ci.vertexBindingDescriptionCount = 0;
6933 vi_ci.pVertexBindingDescriptions = nullptr;
6934 vi_ci.vertexAttributeDescriptionCount = 0;
6935 vi_ci.pVertexAttributeDescriptions = nullptr;
6936
6937 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6938 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6939 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6940
6941 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6942 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6943 rs_ci.pNext = nullptr;
6944
Mark Youngc89c6312016-03-31 16:03:20 -06006945 VkPipelineColorBlendAttachmentState att = {};
6946 att.blendEnable = VK_FALSE;
6947 att.colorWriteMask = 0xf;
6948
Karl Schultz6addd812016-02-02 17:17:23 -07006949 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6950 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6951 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006952 cb_ci.attachmentCount = 1;
6953 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006954
6955 VkGraphicsPipelineCreateInfo gp_ci = {};
6956 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6957 gp_ci.stageCount = 2;
6958 gp_ci.pStages = shaderStages;
6959 gp_ci.pVertexInputState = &vi_ci;
6960 gp_ci.pInputAssemblyState = &ia_ci;
6961 gp_ci.pViewportState = &vp_state_ci;
6962 gp_ci.pRasterizationState = &rs_ci;
6963 gp_ci.pColorBlendState = &cb_ci;
6964 gp_ci.pDynamicState = &dyn_state_ci;
6965 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6966 gp_ci.layout = pipeline_layout;
6967 gp_ci.renderPass = renderPass();
6968
6969 VkPipelineCacheCreateInfo pc_ci = {};
6970 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6971
6972 VkPipeline pipeline;
6973 VkPipelineCache pipelineCache;
6974
6975 err =
6976 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6977 ASSERT_VK_SUCCESS(err);
6978 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6979 &gp_ci, NULL, &pipeline);
6980
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006981 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006982
6983 // Now hit second fail case where we set scissor w/ different count than PSO
6984 // First need to successfully create the PSO from above by setting
6985 // pViewports
6986 m_errorMonitor->SetDesiredFailureMsg(
6987 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6988 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6989 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006990
Tobin Ehlisd332f282015-10-02 11:00:56 -06006991 VkRect2D sc = {}; // Just need dummy vp to point to
6992 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006993 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6994 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006995 ASSERT_VK_SUCCESS(err);
6996 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006997 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6998 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006999 VkViewport viewports[2] = {}; // don't care about data
7000 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007001 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007002 Draw(1, 0, 0, 0);
7003
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007004 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007005
Chia-I Wuf7458c52015-10-26 21:10:41 +08007006 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7008 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7009 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007010 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007011}
7012
Mark Young7394fdd2016-03-31 14:56:43 -06007013TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7014 VkResult err;
7015
7016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007017 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007018
7019 ASSERT_NO_FATAL_FAILURE(InitState());
7020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7021
7022 VkDescriptorPoolSize ds_type_count = {};
7023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7024 ds_type_count.descriptorCount = 1;
7025
7026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7028 ds_pool_ci.maxSets = 1;
7029 ds_pool_ci.poolSizeCount = 1;
7030 ds_pool_ci.pPoolSizes = &ds_type_count;
7031
7032 VkDescriptorPool ds_pool;
7033 err =
7034 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7035 ASSERT_VK_SUCCESS(err);
7036
7037 VkDescriptorSetLayoutBinding dsl_binding = {};
7038 dsl_binding.binding = 0;
7039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7040 dsl_binding.descriptorCount = 1;
7041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7042
7043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7045 ds_layout_ci.bindingCount = 1;
7046 ds_layout_ci.pBindings = &dsl_binding;
7047
7048 VkDescriptorSetLayout ds_layout;
7049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7050 &ds_layout);
7051 ASSERT_VK_SUCCESS(err);
7052
7053 VkDescriptorSet descriptorSet;
7054 VkDescriptorSetAllocateInfo alloc_info = {};
7055 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7056 alloc_info.descriptorSetCount = 1;
7057 alloc_info.descriptorPool = ds_pool;
7058 alloc_info.pSetLayouts = &ds_layout;
7059 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7060 &descriptorSet);
7061 ASSERT_VK_SUCCESS(err);
7062
7063 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7064 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7065 pipeline_layout_ci.setLayoutCount = 1;
7066 pipeline_layout_ci.pSetLayouts = &ds_layout;
7067
7068 VkPipelineLayout pipeline_layout;
7069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7070 &pipeline_layout);
7071 ASSERT_VK_SUCCESS(err);
7072
7073 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7074 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7075 vp_state_ci.scissorCount = 1;
7076 vp_state_ci.pScissors = NULL;
7077 vp_state_ci.viewportCount = 1;
7078 vp_state_ci.pViewports = NULL;
7079
7080 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7081 VK_DYNAMIC_STATE_SCISSOR,
7082 VK_DYNAMIC_STATE_LINE_WIDTH};
7083 // Set scissor as dynamic to avoid that error
7084 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7085 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7086 dyn_state_ci.dynamicStateCount = 2;
7087 dyn_state_ci.pDynamicStates = dynamic_states;
7088
7089 VkPipelineShaderStageCreateInfo shaderStages[2];
7090 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7091
7092 VkShaderObj vs(m_device, bindStateVertShaderText,
7093 VK_SHADER_STAGE_VERTEX_BIT, this);
7094 VkShaderObj fs(m_device, bindStateFragShaderText,
7095 VK_SHADER_STAGE_FRAGMENT_BIT,
7096 this); // TODO - We shouldn't need a fragment shader
7097 // but add it to be able to run on more devices
7098 shaderStages[0] = vs.GetStageCreateInfo();
7099 shaderStages[1] = fs.GetStageCreateInfo();
7100
7101 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7102 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7103 vi_ci.pNext = nullptr;
7104 vi_ci.vertexBindingDescriptionCount = 0;
7105 vi_ci.pVertexBindingDescriptions = nullptr;
7106 vi_ci.vertexAttributeDescriptionCount = 0;
7107 vi_ci.pVertexAttributeDescriptions = nullptr;
7108
7109 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7110 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7111 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7112
7113 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7114 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7115 rs_ci.pNext = nullptr;
7116
Mark Young47107952016-05-02 15:59:55 -06007117 // Check too low (line width of -1.0f).
7118 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007119
7120 VkPipelineColorBlendAttachmentState att = {};
7121 att.blendEnable = VK_FALSE;
7122 att.colorWriteMask = 0xf;
7123
7124 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7125 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7126 cb_ci.pNext = nullptr;
7127 cb_ci.attachmentCount = 1;
7128 cb_ci.pAttachments = &att;
7129
7130 VkGraphicsPipelineCreateInfo gp_ci = {};
7131 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7132 gp_ci.stageCount = 2;
7133 gp_ci.pStages = shaderStages;
7134 gp_ci.pVertexInputState = &vi_ci;
7135 gp_ci.pInputAssemblyState = &ia_ci;
7136 gp_ci.pViewportState = &vp_state_ci;
7137 gp_ci.pRasterizationState = &rs_ci;
7138 gp_ci.pColorBlendState = &cb_ci;
7139 gp_ci.pDynamicState = &dyn_state_ci;
7140 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7141 gp_ci.layout = pipeline_layout;
7142 gp_ci.renderPass = renderPass();
7143
7144 VkPipelineCacheCreateInfo pc_ci = {};
7145 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7146
7147 VkPipeline pipeline;
7148 VkPipelineCache pipelineCache;
7149
7150 err =
7151 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7152 ASSERT_VK_SUCCESS(err);
7153 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7154 &gp_ci, NULL, &pipeline);
7155
7156 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007158
7159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7160 "Attempt to set lineWidth to 65536");
7161
7162 // Check too high (line width of 65536.0f).
7163 rs_ci.lineWidth = 65536.0f;
7164
7165 err =
7166 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7167 ASSERT_VK_SUCCESS(err);
7168 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7169 &gp_ci, NULL, &pipeline);
7170
7171 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007172 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007173
7174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007175 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007176
7177 dyn_state_ci.dynamicStateCount = 3;
7178
7179 rs_ci.lineWidth = 1.0f;
7180
7181 err =
7182 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7183 ASSERT_VK_SUCCESS(err);
7184 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7185 &gp_ci, NULL, &pipeline);
7186 BeginCommandBuffer();
7187 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7188 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7189
7190 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007191 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007192 m_errorMonitor->VerifyFound();
7193
7194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7195 "Attempt to set lineWidth to 65536");
7196
7197 // Check too high with dynamic setting.
7198 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7199 m_errorMonitor->VerifyFound();
7200 EndCommandBuffer();
7201
7202 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7203 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7205 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007206 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007207}
7208
Karl Schultz6addd812016-02-02 17:17:23 -07007209TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007210 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007211 m_errorMonitor->SetDesiredFailureMsg(
7212 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007213 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007214
7215 ASSERT_NO_FATAL_FAILURE(InitState());
7216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007217
Tony Barbourfe3351b2015-07-28 10:17:20 -06007218 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007219 // Don't care about RenderPass handle b/c error should be flagged before
7220 // that
7221 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7222 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007223
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007224 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007225}
7226
Karl Schultz6addd812016-02-02 17:17:23 -07007227TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007228 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007229 m_errorMonitor->SetDesiredFailureMsg(
7230 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007231 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007232
7233 ASSERT_NO_FATAL_FAILURE(InitState());
7234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007235
Tony Barbourfe3351b2015-07-28 10:17:20 -06007236 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007237 // Just create a dummy Renderpass that's non-NULL so we can get to the
7238 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007239 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007240 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7241 rp_begin.pNext = NULL;
7242 rp_begin.renderPass = renderPass();
7243 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007244
Karl Schultz6addd812016-02-02 17:17:23 -07007245 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7246 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007247
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007248 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007249}
7250
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007251TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7252 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7253 "the number of renderPass attachments that use loadOp"
7254 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7255
7256 ASSERT_NO_FATAL_FAILURE(InitState());
7257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7258
7259 // Create a renderPass with a single attachment that uses loadOp CLEAR
7260 VkAttachmentReference attach = {};
7261 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7262 VkSubpassDescription subpass = {};
7263 subpass.inputAttachmentCount = 1;
7264 subpass.pInputAttachments = &attach;
7265 VkRenderPassCreateInfo rpci = {};
7266 rpci.subpassCount = 1;
7267 rpci.pSubpasses = &subpass;
7268 rpci.attachmentCount = 1;
7269 VkAttachmentDescription attach_desc = {};
7270 attach_desc.format = VK_FORMAT_UNDEFINED;
7271 // Set loadOp to CLEAR
7272 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7273 rpci.pAttachments = &attach_desc;
7274 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7275 VkRenderPass rp;
7276 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7277
7278 VkCommandBufferInheritanceInfo hinfo = {};
7279 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7280 hinfo.renderPass = VK_NULL_HANDLE;
7281 hinfo.subpass = 0;
7282 hinfo.framebuffer = VK_NULL_HANDLE;
7283 hinfo.occlusionQueryEnable = VK_FALSE;
7284 hinfo.queryFlags = 0;
7285 hinfo.pipelineStatistics = 0;
7286 VkCommandBufferBeginInfo info = {};
7287 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7288 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7289 info.pInheritanceInfo = &hinfo;
7290
7291 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7292 VkRenderPassBeginInfo rp_begin = {};
7293 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7294 rp_begin.pNext = NULL;
7295 rp_begin.renderPass = renderPass();
7296 rp_begin.framebuffer = framebuffer();
7297 rp_begin.clearValueCount = 0; // Should be 1
7298
7299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7300 " has a clearValueCount of 0 but the "
7301 "actual number of attachments in "
7302 "renderPass ");
7303
7304 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7305 VK_SUBPASS_CONTENTS_INLINE);
7306
7307 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007308
7309 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007310}
7311
Cody Northrop3bb4d962016-05-09 16:15:57 -06007312TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7313
7314 TEST_DESCRIPTION("End a command buffer with an active render pass");
7315
7316 m_errorMonitor->SetDesiredFailureMsg(
7317 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7318 "It is invalid to issue this call inside an active render pass");
7319
7320 ASSERT_NO_FATAL_FAILURE(InitState());
7321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7322
7323 // The framework's BeginCommandBuffer calls CreateRenderPass
7324 BeginCommandBuffer();
7325
7326 // Call directly into vkEndCommandBuffer instead of the
7327 // the framework's EndCommandBuffer, which inserts a
7328 // vkEndRenderPass
7329 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7330
7331 m_errorMonitor->VerifyFound();
7332
7333 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7334 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7335}
7336
Karl Schultz6addd812016-02-02 17:17:23 -07007337TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007338 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007339 m_errorMonitor->SetDesiredFailureMsg(
7340 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007341 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007342
7343 ASSERT_NO_FATAL_FAILURE(InitState());
7344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007345
7346 // Renderpass is started here
7347 BeginCommandBuffer();
7348
7349 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 vk_testing::Buffer dstBuffer;
7351 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007354
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007355 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007356}
7357
Karl Schultz6addd812016-02-02 17:17:23 -07007358TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007359 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007360 m_errorMonitor->SetDesiredFailureMsg(
7361 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007362 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007363
7364 ASSERT_NO_FATAL_FAILURE(InitState());
7365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007366
7367 // Renderpass is started here
7368 BeginCommandBuffer();
7369
7370 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007371 vk_testing::Buffer dstBuffer;
7372 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007373
Karl Schultz6addd812016-02-02 17:17:23 -07007374 VkDeviceSize dstOffset = 0;
7375 VkDeviceSize dataSize = 1024;
7376 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007377
Karl Schultz6addd812016-02-02 17:17:23 -07007378 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7379 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007380
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007381 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007382}
7383
Karl Schultz6addd812016-02-02 17:17:23 -07007384TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007385 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007386 m_errorMonitor->SetDesiredFailureMsg(
7387 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007388 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007389
7390 ASSERT_NO_FATAL_FAILURE(InitState());
7391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007392
7393 // Renderpass is started here
7394 BeginCommandBuffer();
7395
Michael Lentine0a369f62016-02-03 16:51:46 -06007396 VkClearColorValue clear_color;
7397 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007398 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7400 const int32_t tex_width = 32;
7401 const int32_t tex_height = 32;
7402 VkImageCreateInfo image_create_info = {};
7403 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7404 image_create_info.pNext = NULL;
7405 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7406 image_create_info.format = tex_format;
7407 image_create_info.extent.width = tex_width;
7408 image_create_info.extent.height = tex_height;
7409 image_create_info.extent.depth = 1;
7410 image_create_info.mipLevels = 1;
7411 image_create_info.arrayLayers = 1;
7412 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7413 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7414 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007415
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007416 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007417 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7418 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007419
Karl Schultz6addd812016-02-02 17:17:23 -07007420 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7421 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007422
Karl Schultz6addd812016-02-02 17:17:23 -07007423 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7424 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007425
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007426 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007427}
7428
Karl Schultz6addd812016-02-02 17:17:23 -07007429TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007430 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007431 m_errorMonitor->SetDesiredFailureMsg(
7432 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007433 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007434
7435 ASSERT_NO_FATAL_FAILURE(InitState());
7436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007437
7438 // Renderpass is started here
7439 BeginCommandBuffer();
7440
7441 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007442 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007443 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7444 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7445 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7446 image_create_info.extent.width = 64;
7447 image_create_info.extent.height = 64;
7448 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7449 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007450
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007451 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007452 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7453 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007454
Karl Schultz6addd812016-02-02 17:17:23 -07007455 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7456 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007457
Karl Schultz6addd812016-02-02 17:17:23 -07007458 vkCmdClearDepthStencilImage(
7459 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7460 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7461 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007462
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007463 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007464}
7465
Karl Schultz6addd812016-02-02 17:17:23 -07007466TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007467 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007468 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007469
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007471 "vkCmdClearAttachments: This call "
7472 "must be issued inside an active "
7473 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007474
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007475 ASSERT_NO_FATAL_FAILURE(InitState());
7476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007477
7478 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007479 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007480 ASSERT_VK_SUCCESS(err);
7481
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007482 VkClearAttachment color_attachment;
7483 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7484 color_attachment.clearValue.color.float32[0] = 0;
7485 color_attachment.clearValue.color.float32[1] = 0;
7486 color_attachment.clearValue.color.float32[2] = 0;
7487 color_attachment.clearValue.color.float32[3] = 0;
7488 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007489 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7490 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7491 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007492
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007493 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007494}
7495
Karl Schultz9e66a292016-04-21 15:57:51 -06007496TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7497 // Try to add a buffer memory barrier with no buffer.
7498 m_errorMonitor->SetDesiredFailureMsg(
7499 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7500 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7501
7502 ASSERT_NO_FATAL_FAILURE(InitState());
7503 BeginCommandBuffer();
7504
7505 VkBufferMemoryBarrier buf_barrier = {};
7506 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7507 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7508 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7509 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7510 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7511 buf_barrier.buffer = VK_NULL_HANDLE;
7512 buf_barrier.offset = 0;
7513 buf_barrier.size = VK_WHOLE_SIZE;
7514 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7515 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7516 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7517
7518 m_errorMonitor->VerifyFound();
7519}
7520
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007521TEST_F(VkLayerTest, InvalidBarriers) {
7522 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7523
7524 m_errorMonitor->SetDesiredFailureMsg(
7525 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7526
7527 ASSERT_NO_FATAL_FAILURE(InitState());
7528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7529
7530 VkMemoryBarrier mem_barrier = {};
7531 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7532 mem_barrier.pNext = NULL;
7533 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7534 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7535 BeginCommandBuffer();
7536 // BeginCommandBuffer() starts a render pass
7537 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7538 VK_PIPELINE_STAGE_HOST_BIT,
7539 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7540 &mem_barrier, 0, nullptr, 0, nullptr);
7541 m_errorMonitor->VerifyFound();
7542
7543 m_errorMonitor->SetDesiredFailureMsg(
7544 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7545 "Image Layout cannot be transitioned to UNDEFINED");
7546 VkImageObj image(m_device);
7547 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7548 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7549 ASSERT_TRUE(image.initialized());
7550 VkImageMemoryBarrier img_barrier = {};
7551 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7552 img_barrier.pNext = NULL;
7553 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7554 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7555 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7556 // New layout can't be UNDEFINED
7557 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7558 img_barrier.image = image.handle();
7559 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7560 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7561 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7562 img_barrier.subresourceRange.baseArrayLayer = 0;
7563 img_barrier.subresourceRange.baseMipLevel = 0;
7564 img_barrier.subresourceRange.layerCount = 1;
7565 img_barrier.subresourceRange.levelCount = 1;
7566 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7567 VK_PIPELINE_STAGE_HOST_BIT,
7568 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7569 nullptr, 1, &img_barrier);
7570 m_errorMonitor->VerifyFound();
7571 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7572
7573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7574 "Subresource must have the sum of the "
7575 "baseArrayLayer");
7576 // baseArrayLayer + layerCount must be <= image's arrayLayers
7577 img_barrier.subresourceRange.baseArrayLayer = 1;
7578 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7579 VK_PIPELINE_STAGE_HOST_BIT,
7580 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7581 nullptr, 1, &img_barrier);
7582 m_errorMonitor->VerifyFound();
7583 img_barrier.subresourceRange.baseArrayLayer = 0;
7584
7585 m_errorMonitor->SetDesiredFailureMsg(
7586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7587 "Subresource must have the sum of the baseMipLevel");
7588 // baseMipLevel + levelCount must be <= image's mipLevels
7589 img_barrier.subresourceRange.baseMipLevel = 1;
7590 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7591 VK_PIPELINE_STAGE_HOST_BIT,
7592 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7593 nullptr, 1, &img_barrier);
7594 m_errorMonitor->VerifyFound();
7595 img_barrier.subresourceRange.baseMipLevel = 0;
7596
7597 m_errorMonitor->SetDesiredFailureMsg(
7598 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7599 "Buffer Barriers cannot be used during a render pass");
7600 vk_testing::Buffer buffer;
7601 buffer.init(*m_device, 256);
7602 VkBufferMemoryBarrier buf_barrier = {};
7603 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7604 buf_barrier.pNext = NULL;
7605 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7606 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7607 buf_barrier.buffer = buffer.handle();
7608 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7609 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7610 buf_barrier.offset = 0;
7611 buf_barrier.size = VK_WHOLE_SIZE;
7612 // Can't send buffer barrier during a render pass
7613 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7614 VK_PIPELINE_STAGE_HOST_BIT,
7615 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7616 &buf_barrier, 0, nullptr);
7617 m_errorMonitor->VerifyFound();
7618 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7619
7620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7621 "which is not less than total size");
7622 buf_barrier.offset = 257;
7623 // Offset greater than total size
7624 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7625 VK_PIPELINE_STAGE_HOST_BIT,
7626 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7627 &buf_barrier, 0, nullptr);
7628 m_errorMonitor->VerifyFound();
7629 buf_barrier.offset = 0;
7630
7631 m_errorMonitor->SetDesiredFailureMsg(
7632 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7633 buf_barrier.size = 257;
7634 // Size greater than total size
7635 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7636 VK_PIPELINE_STAGE_HOST_BIT,
7637 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7638 &buf_barrier, 0, nullptr);
7639 m_errorMonitor->VerifyFound();
7640 buf_barrier.size = VK_WHOLE_SIZE;
7641
7642 m_errorMonitor->SetDesiredFailureMsg(
7643 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7644 "Image is a depth and stencil format and thus must "
7645 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7646 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7647 VkDepthStencilObj ds_image(m_device);
7648 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7649 ASSERT_TRUE(ds_image.initialized());
7650 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7651 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7652 img_barrier.image = ds_image.handle();
7653 // Leave aspectMask at COLOR on purpose
7654 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7655 VK_PIPELINE_STAGE_HOST_BIT,
7656 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7657 nullptr, 1, &img_barrier);
7658 m_errorMonitor->VerifyFound();
7659}
7660
Karl Schultz6addd812016-02-02 17:17:23 -07007661TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007662 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007663 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007664
Karl Schultz6addd812016-02-02 17:17:23 -07007665 m_errorMonitor->SetDesiredFailureMsg(
7666 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007667 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7668
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007669 ASSERT_NO_FATAL_FAILURE(InitState());
7670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007671 uint32_t qfi = 0;
7672 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007673 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7674 buffCI.size = 1024;
7675 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7676 buffCI.queueFamilyIndexCount = 1;
7677 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007678
7679 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007680 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007681 ASSERT_VK_SUCCESS(err);
7682
7683 BeginCommandBuffer();
7684 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007685 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7686 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007687 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007688 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7689 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007690
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007691 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007692
Chia-I Wuf7458c52015-10-26 21:10:41 +08007693 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007694}
7695
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007696TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7697 // Create an out-of-range queueFamilyIndex
7698 m_errorMonitor->SetDesiredFailureMsg(
7699 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007700 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7701 "of the indices specified when the device was created, via the "
7702 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007703
7704 ASSERT_NO_FATAL_FAILURE(InitState());
7705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7706 VkBufferCreateInfo buffCI = {};
7707 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7708 buffCI.size = 1024;
7709 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7710 buffCI.queueFamilyIndexCount = 1;
7711 // Introduce failure by specifying invalid queue_family_index
7712 uint32_t qfi = 777;
7713 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007714 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007715
7716 VkBuffer ib;
7717 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7718
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007719 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007720 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007721}
7722
Karl Schultz6addd812016-02-02 17:17:23 -07007723TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7724 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7725 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007726
Karl Schultz6addd812016-02-02 17:17:23 -07007727 m_errorMonitor->SetDesiredFailureMsg(
7728 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007729 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007730
7731 ASSERT_NO_FATAL_FAILURE(InitState());
7732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007733
7734 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007735 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007736 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7737 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007738
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007739 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007740}
7741
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007742TEST_F(VkLayerTest, DSUsageBitsErrors) {
7743 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7744 "that do not have correct usage bits sets.");
7745 VkResult err;
7746
7747 ASSERT_NO_FATAL_FAILURE(InitState());
7748 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7749 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7750 ds_type_count[i].type = VkDescriptorType(i);
7751 ds_type_count[i].descriptorCount = 1;
7752 }
7753 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7754 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7755 ds_pool_ci.pNext = NULL;
7756 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7757 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7758 ds_pool_ci.pPoolSizes = ds_type_count;
7759
7760 VkDescriptorPool ds_pool;
7761 err =
7762 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7763 ASSERT_VK_SUCCESS(err);
7764
7765 // Create 10 layouts where each has a single descriptor of different type
7766 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7767 {};
7768 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7769 dsl_binding[i].binding = 0;
7770 dsl_binding[i].descriptorType = VkDescriptorType(i);
7771 dsl_binding[i].descriptorCount = 1;
7772 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7773 dsl_binding[i].pImmutableSamplers = NULL;
7774 }
7775
7776 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7777 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7778 ds_layout_ci.pNext = NULL;
7779 ds_layout_ci.bindingCount = 1;
7780 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7781 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7782 ds_layout_ci.pBindings = dsl_binding + i;
7783 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7784 NULL, ds_layouts + i);
7785 ASSERT_VK_SUCCESS(err);
7786 }
7787 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7788 VkDescriptorSetAllocateInfo alloc_info = {};
7789 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7790 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7791 alloc_info.descriptorPool = ds_pool;
7792 alloc_info.pSetLayouts = ds_layouts;
7793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7794 descriptor_sets);
7795 ASSERT_VK_SUCCESS(err);
7796
7797 // Create a buffer & bufferView to be used for invalid updates
7798 VkBufferCreateInfo buff_ci = {};
7799 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7800 // This usage is not valid for any descriptor type
7801 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7802 buff_ci.size = 256;
7803 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7804 VkBuffer buffer;
7805 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7806 ASSERT_VK_SUCCESS(err);
7807
7808 VkBufferViewCreateInfo buff_view_ci = {};
7809 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7810 buff_view_ci.buffer = buffer;
7811 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7812 buff_view_ci.range = VK_WHOLE_SIZE;
7813 VkBufferView buff_view;
7814 err =
7815 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7816 ASSERT_VK_SUCCESS(err);
7817
7818 // Create an image to be used for invalid updates
7819 VkImageCreateInfo image_ci = {};
7820 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7821 image_ci.imageType = VK_IMAGE_TYPE_2D;
7822 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7823 image_ci.extent.width = 64;
7824 image_ci.extent.height = 64;
7825 image_ci.extent.depth = 1;
7826 image_ci.mipLevels = 1;
7827 image_ci.arrayLayers = 1;
7828 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7829 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7830 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7831 // This usage is not valid for any descriptor type
7832 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7833 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7834 VkImage image;
7835 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7836 ASSERT_VK_SUCCESS(err);
7837 // Bind memory to image
7838 VkMemoryRequirements mem_reqs;
7839 VkDeviceMemory image_mem;
7840 bool pass;
7841 VkMemoryAllocateInfo mem_alloc = {};
7842 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7843 mem_alloc.pNext = NULL;
7844 mem_alloc.allocationSize = 0;
7845 mem_alloc.memoryTypeIndex = 0;
7846 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7847 mem_alloc.allocationSize = mem_reqs.size;
7848 pass =
7849 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7850 ASSERT_TRUE(pass);
7851 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7852 ASSERT_VK_SUCCESS(err);
7853 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7854 ASSERT_VK_SUCCESS(err);
7855 // Now create view for image
7856 VkImageViewCreateInfo image_view_ci = {};
7857 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7858 image_view_ci.image = image;
7859 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7860 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7861 image_view_ci.subresourceRange.layerCount = 1;
7862 image_view_ci.subresourceRange.baseArrayLayer = 0;
7863 image_view_ci.subresourceRange.levelCount = 1;
7864 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7865 VkImageView image_view;
7866 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7867 &image_view);
7868 ASSERT_VK_SUCCESS(err);
7869
7870 VkDescriptorBufferInfo buff_info = {};
7871 buff_info.buffer = buffer;
7872 VkDescriptorImageInfo img_info = {};
7873 img_info.imageView = image_view;
7874 VkWriteDescriptorSet descriptor_write = {};
7875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7876 descriptor_write.dstBinding = 0;
7877 descriptor_write.descriptorCount = 1;
7878 descriptor_write.pTexelBufferView = &buff_view;
7879 descriptor_write.pBufferInfo = &buff_info;
7880 descriptor_write.pImageInfo = &img_info;
7881
7882 // These error messages align with VkDescriptorType struct
7883 const char *error_msgs[] = {
7884 "", // placeholder, no error for SAMPLER descriptor
7885 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7886 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7887 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7888 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7889 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7890 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7891 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7892 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7893 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7894 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7895 // Start loop at 1 as SAMPLER desc type has no usage bit error
7896 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7897 descriptor_write.descriptorType = VkDescriptorType(i);
7898 descriptor_write.dstSet = descriptor_sets[i];
7899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7900 error_msgs[i]);
7901
7902 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7903 NULL);
7904
7905 m_errorMonitor->VerifyFound();
7906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7907 }
7908 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7909 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007910 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007911 vkDestroyImageView(m_device->device(), image_view, NULL);
7912 vkDestroyBuffer(m_device->device(), buffer, NULL);
7913 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7914 vkFreeDescriptorSets(m_device->device(), ds_pool,
7915 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7917}
7918
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06007919TEST_F(VkLayerTest, DSAspectBitsErrors) {
7920 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
7921 // are set, but could expand this test to hit more cases.
7922 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
7923 "that do not have correct aspect bits sets.");
7924 VkResult err;
7925
7926 ASSERT_NO_FATAL_FAILURE(InitState());
7927 VkDescriptorPoolSize ds_type_count = {};
7928 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7929 ds_type_count.descriptorCount = 1;
7930
7931 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7932 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7933 ds_pool_ci.pNext = NULL;
7934 ds_pool_ci.maxSets = 5;
7935 ds_pool_ci.poolSizeCount = 1;
7936 ds_pool_ci.pPoolSizes = &ds_type_count;
7937
7938 VkDescriptorPool ds_pool;
7939 err =
7940 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7941 ASSERT_VK_SUCCESS(err);
7942
7943 VkDescriptorSetLayoutBinding dsl_binding = {};
7944 dsl_binding.binding = 0;
7945 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7946 dsl_binding.descriptorCount = 1;
7947 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7948 dsl_binding.pImmutableSamplers = NULL;
7949
7950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7952 ds_layout_ci.pNext = NULL;
7953 ds_layout_ci.bindingCount = 1;
7954 ds_layout_ci.pBindings = &dsl_binding;
7955 VkDescriptorSetLayout ds_layout;
7956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7957 &ds_layout);
7958 ASSERT_VK_SUCCESS(err);
7959
7960 VkDescriptorSet descriptor_set = {};
7961 VkDescriptorSetAllocateInfo alloc_info = {};
7962 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7963 alloc_info.descriptorSetCount = 1;
7964 alloc_info.descriptorPool = ds_pool;
7965 alloc_info.pSetLayouts = &ds_layout;
7966 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7967 &descriptor_set);
7968 ASSERT_VK_SUCCESS(err);
7969
7970 // Create an image to be used for invalid updates
7971 VkImageCreateInfo image_ci = {};
7972 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7973 image_ci.imageType = VK_IMAGE_TYPE_2D;
7974 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
7975 image_ci.extent.width = 64;
7976 image_ci.extent.height = 64;
7977 image_ci.extent.depth = 1;
7978 image_ci.mipLevels = 1;
7979 image_ci.arrayLayers = 1;
7980 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7981 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7982 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7983 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7984 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7985 VkImage image;
7986 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7987 ASSERT_VK_SUCCESS(err);
7988 // Bind memory to image
7989 VkMemoryRequirements mem_reqs;
7990 VkDeviceMemory image_mem;
7991 bool pass;
7992 VkMemoryAllocateInfo mem_alloc = {};
7993 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7994 mem_alloc.pNext = NULL;
7995 mem_alloc.allocationSize = 0;
7996 mem_alloc.memoryTypeIndex = 0;
7997 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7998 mem_alloc.allocationSize = mem_reqs.size;
7999 pass =
8000 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8001 ASSERT_TRUE(pass);
8002 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8003 ASSERT_VK_SUCCESS(err);
8004 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8005 ASSERT_VK_SUCCESS(err);
8006 // Now create view for image
8007 VkImageViewCreateInfo image_view_ci = {};
8008 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8009 image_view_ci.image = image;
8010 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8011 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8012 image_view_ci.subresourceRange.layerCount = 1;
8013 image_view_ci.subresourceRange.baseArrayLayer = 0;
8014 image_view_ci.subresourceRange.levelCount = 1;
8015 // Setting both depth & stencil aspect bits is illegal for descriptor
8016 image_view_ci.subresourceRange.aspectMask =
8017 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8018
8019 VkImageView image_view;
8020 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8021 &image_view);
8022 ASSERT_VK_SUCCESS(err);
8023
8024 VkDescriptorImageInfo img_info = {};
8025 img_info.imageView = image_view;
8026 VkWriteDescriptorSet descriptor_write = {};
8027 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8028 descriptor_write.dstBinding = 0;
8029 descriptor_write.descriptorCount = 1;
8030 descriptor_write.pTexelBufferView = NULL;
8031 descriptor_write.pBufferInfo = NULL;
8032 descriptor_write.pImageInfo = &img_info;
8033 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8034 descriptor_write.dstSet = descriptor_set;
8035 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8036 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8038 error_msg);
8039
8040 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8041
8042 m_errorMonitor->VerifyFound();
8043 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8044 vkDestroyImage(m_device->device(), image, NULL);
8045 vkFreeMemory(m_device->device(), image_mem, NULL);
8046 vkDestroyImageView(m_device->device(), image_view, NULL);
8047 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8049}
8050
Karl Schultz6addd812016-02-02 17:17:23 -07008051TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008052 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008053 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008054
Karl Schultz6addd812016-02-02 17:17:23 -07008055 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008056 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8057 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8058 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008059
Tobin Ehlis3b780662015-05-28 12:11:26 -06008060 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008061 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008063 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8064 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008065
8066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8068 ds_pool_ci.pNext = NULL;
8069 ds_pool_ci.maxSets = 1;
8070 ds_pool_ci.poolSizeCount = 1;
8071 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008072
Tobin Ehlis3b780662015-05-28 12:11:26 -06008073 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008074 err =
8075 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008076 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008077 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008078 dsl_binding.binding = 0;
8079 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8080 dsl_binding.descriptorCount = 1;
8081 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8082 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008083
Tony Barboureb254902015-07-15 12:50:33 -06008084 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008085 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8086 ds_layout_ci.pNext = NULL;
8087 ds_layout_ci.bindingCount = 1;
8088 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008089
Tobin Ehlis3b780662015-05-28 12:11:26 -06008090 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8092 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008093 ASSERT_VK_SUCCESS(err);
8094
8095 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008096 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008097 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008098 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008099 alloc_info.descriptorPool = ds_pool;
8100 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008101 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8102 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008103 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008104
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008105 VkSamplerCreateInfo sampler_ci = {};
8106 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8107 sampler_ci.pNext = NULL;
8108 sampler_ci.magFilter = VK_FILTER_NEAREST;
8109 sampler_ci.minFilter = VK_FILTER_NEAREST;
8110 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8111 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8112 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8113 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8114 sampler_ci.mipLodBias = 1.0;
8115 sampler_ci.anisotropyEnable = VK_FALSE;
8116 sampler_ci.maxAnisotropy = 1;
8117 sampler_ci.compareEnable = VK_FALSE;
8118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8119 sampler_ci.minLod = 1.0;
8120 sampler_ci.maxLod = 1.0;
8121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8122 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8123 VkSampler sampler;
8124 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8125 ASSERT_VK_SUCCESS(err);
8126
8127 VkDescriptorImageInfo info = {};
8128 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008129
8130 VkWriteDescriptorSet descriptor_write;
8131 memset(&descriptor_write, 0, sizeof(descriptor_write));
8132 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008134 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008135 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008136 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008137 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008138
8139 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8140
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008141 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008142
Chia-I Wuf7458c52015-10-26 21:10:41 +08008143 vkDestroySampler(m_device->device(), sampler, NULL);
8144 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8145 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008146}
8147
Karl Schultz6addd812016-02-02 17:17:23 -07008148TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008149 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008150 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008151
Karl Schultz6addd812016-02-02 17:17:23 -07008152 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008153 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8154 " binding #0 with 1 total descriptors but update of 1 descriptors "
8155 "starting at binding offset of 0 combined with update array element "
8156 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008157
Tobin Ehlis3b780662015-05-28 12:11:26 -06008158 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008159 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008160 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008161 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8162 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008163
8164 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008165 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8166 ds_pool_ci.pNext = NULL;
8167 ds_pool_ci.maxSets = 1;
8168 ds_pool_ci.poolSizeCount = 1;
8169 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008170
Tobin Ehlis3b780662015-05-28 12:11:26 -06008171 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008172 err =
8173 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008174 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008175
Tony Barboureb254902015-07-15 12:50:33 -06008176 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008177 dsl_binding.binding = 0;
8178 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8179 dsl_binding.descriptorCount = 1;
8180 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8181 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008182
8183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8185 ds_layout_ci.pNext = NULL;
8186 ds_layout_ci.bindingCount = 1;
8187 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008188
Tobin Ehlis3b780662015-05-28 12:11:26 -06008189 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8191 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008192 ASSERT_VK_SUCCESS(err);
8193
8194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008197 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008198 alloc_info.descriptorPool = ds_pool;
8199 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8201 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008202 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008203
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008204 // Correctly update descriptor to avoid "NOT_UPDATED" error
8205 VkDescriptorBufferInfo buff_info = {};
8206 buff_info.buffer =
8207 VkBuffer(0); // Don't care about buffer handle for this test
8208 buff_info.offset = 0;
8209 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008210
8211 VkWriteDescriptorSet descriptor_write;
8212 memset(&descriptor_write, 0, sizeof(descriptor_write));
8213 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008214 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008215 descriptor_write.dstArrayElement =
8216 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008217 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008218 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8219 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008220
8221 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8222
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008223 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008224
Chia-I Wuf7458c52015-10-26 21:10:41 +08008225 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8226 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008227}
8228
Karl Schultz6addd812016-02-02 17:17:23 -07008229TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8230 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8231 // index 2
8232 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008233
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8235 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008236
Tobin Ehlis3b780662015-05-28 12:11:26 -06008237 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008238 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008239 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008240 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8241 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008242
8243 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008244 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8245 ds_pool_ci.pNext = NULL;
8246 ds_pool_ci.maxSets = 1;
8247 ds_pool_ci.poolSizeCount = 1;
8248 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008249
Tobin Ehlis3b780662015-05-28 12:11:26 -06008250 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008251 err =
8252 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008253 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008254
Tony Barboureb254902015-07-15 12:50:33 -06008255 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008256 dsl_binding.binding = 0;
8257 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8258 dsl_binding.descriptorCount = 1;
8259 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8260 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008261
8262 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008263 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8264 ds_layout_ci.pNext = NULL;
8265 ds_layout_ci.bindingCount = 1;
8266 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008267 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8269 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008270 ASSERT_VK_SUCCESS(err);
8271
8272 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008273 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008275 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008276 alloc_info.descriptorPool = ds_pool;
8277 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8279 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008280 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008281
Tony Barboureb254902015-07-15 12:50:33 -06008282 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008283 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8284 sampler_ci.pNext = NULL;
8285 sampler_ci.magFilter = VK_FILTER_NEAREST;
8286 sampler_ci.minFilter = VK_FILTER_NEAREST;
8287 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8288 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8289 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8290 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8291 sampler_ci.mipLodBias = 1.0;
8292 sampler_ci.anisotropyEnable = VK_FALSE;
8293 sampler_ci.maxAnisotropy = 1;
8294 sampler_ci.compareEnable = VK_FALSE;
8295 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8296 sampler_ci.minLod = 1.0;
8297 sampler_ci.maxLod = 1.0;
8298 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8299 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008300
Tobin Ehlis3b780662015-05-28 12:11:26 -06008301 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008302 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008303 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008304
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008305 VkDescriptorImageInfo info = {};
8306 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008307
8308 VkWriteDescriptorSet descriptor_write;
8309 memset(&descriptor_write, 0, sizeof(descriptor_write));
8310 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008311 descriptor_write.dstSet = descriptorSet;
8312 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008313 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008314 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008315 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008316 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008317
8318 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8319
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008320 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008321
Chia-I Wuf7458c52015-10-26 21:10:41 +08008322 vkDestroySampler(m_device->device(), sampler, NULL);
8323 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8324 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008325}
8326
Karl Schultz6addd812016-02-02 17:17:23 -07008327TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8328 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8329 // types
8330 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008331
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008333 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008334
Tobin Ehlis3b780662015-05-28 12:11:26 -06008335 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008336
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008337 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008338 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8339 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008340
8341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8343 ds_pool_ci.pNext = NULL;
8344 ds_pool_ci.maxSets = 1;
8345 ds_pool_ci.poolSizeCount = 1;
8346 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008347
Tobin Ehlis3b780662015-05-28 12:11:26 -06008348 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008349 err =
8350 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008351 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008352 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008353 dsl_binding.binding = 0;
8354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8355 dsl_binding.descriptorCount = 1;
8356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8357 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008358
Tony Barboureb254902015-07-15 12:50:33 -06008359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8361 ds_layout_ci.pNext = NULL;
8362 ds_layout_ci.bindingCount = 1;
8363 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008364
Tobin Ehlis3b780662015-05-28 12:11:26 -06008365 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008366 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8367 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008373 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008374 alloc_info.descriptorPool = ds_pool;
8375 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8377 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008378 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008379
Tony Barboureb254902015-07-15 12:50:33 -06008380 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008381 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8382 sampler_ci.pNext = NULL;
8383 sampler_ci.magFilter = VK_FILTER_NEAREST;
8384 sampler_ci.minFilter = VK_FILTER_NEAREST;
8385 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8386 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8387 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8388 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8389 sampler_ci.mipLodBias = 1.0;
8390 sampler_ci.anisotropyEnable = VK_FALSE;
8391 sampler_ci.maxAnisotropy = 1;
8392 sampler_ci.compareEnable = VK_FALSE;
8393 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8394 sampler_ci.minLod = 1.0;
8395 sampler_ci.maxLod = 1.0;
8396 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8397 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008398 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008399 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008400 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008401
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008402 VkDescriptorImageInfo info = {};
8403 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008404
8405 VkWriteDescriptorSet descriptor_write;
8406 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008407 descriptor_write.sType =
8408 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008409 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008410 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008411 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008412 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008413 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008414
8415 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8416
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008417 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008418
Chia-I Wuf7458c52015-10-26 21:10:41 +08008419 vkDestroySampler(m_device->device(), sampler, NULL);
8420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8421 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008422}
8423
Karl Schultz6addd812016-02-02 17:17:23 -07008424TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008425 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008426 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008427
Karl Schultz6addd812016-02-02 17:17:23 -07008428 m_errorMonitor->SetDesiredFailureMsg(
8429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008430 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008431
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008432 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008433 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8434 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008435 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008436 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8437 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008438
8439 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008440 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8441 ds_pool_ci.pNext = NULL;
8442 ds_pool_ci.maxSets = 1;
8443 ds_pool_ci.poolSizeCount = 1;
8444 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008445
8446 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008447 err =
8448 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008449 ASSERT_VK_SUCCESS(err);
8450
8451 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008452 dsl_binding.binding = 0;
8453 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8454 dsl_binding.descriptorCount = 1;
8455 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8456 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008457
8458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8460 ds_layout_ci.pNext = NULL;
8461 ds_layout_ci.bindingCount = 1;
8462 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008463 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008464 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8465 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008466 ASSERT_VK_SUCCESS(err);
8467
8468 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008469 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008470 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008471 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008472 alloc_info.descriptorPool = ds_pool;
8473 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008474 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8475 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008476 ASSERT_VK_SUCCESS(err);
8477
Karl Schultz6addd812016-02-02 17:17:23 -07008478 VkSampler sampler =
8479 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008480
8481 VkDescriptorImageInfo descriptor_info;
8482 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8483 descriptor_info.sampler = sampler;
8484
8485 VkWriteDescriptorSet descriptor_write;
8486 memset(&descriptor_write, 0, sizeof(descriptor_write));
8487 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008488 descriptor_write.dstSet = descriptorSet;
8489 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008490 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008491 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8492 descriptor_write.pImageInfo = &descriptor_info;
8493
8494 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008496 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008497
Chia-I Wuf7458c52015-10-26 21:10:41 +08008498 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8499 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008500}
8501
Karl Schultz6addd812016-02-02 17:17:23 -07008502TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8503 // Create a single combined Image/Sampler descriptor and send it an invalid
8504 // imageView
8505 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008506
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8508 "Attempted write update to combined "
8509 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008510 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008511
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008512 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008513 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008514 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8515 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008516
8517 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008518 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8519 ds_pool_ci.pNext = NULL;
8520 ds_pool_ci.maxSets = 1;
8521 ds_pool_ci.poolSizeCount = 1;
8522 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008523
8524 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008525 err =
8526 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008527 ASSERT_VK_SUCCESS(err);
8528
8529 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008530 dsl_binding.binding = 0;
8531 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8532 dsl_binding.descriptorCount = 1;
8533 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8534 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008535
8536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8538 ds_layout_ci.pNext = NULL;
8539 ds_layout_ci.bindingCount = 1;
8540 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008541 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008542 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8543 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008544 ASSERT_VK_SUCCESS(err);
8545
8546 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008547 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008548 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008549 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008550 alloc_info.descriptorPool = ds_pool;
8551 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8553 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008554 ASSERT_VK_SUCCESS(err);
8555
8556 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008557 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8558 sampler_ci.pNext = NULL;
8559 sampler_ci.magFilter = VK_FILTER_NEAREST;
8560 sampler_ci.minFilter = VK_FILTER_NEAREST;
8561 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8562 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8563 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8564 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8565 sampler_ci.mipLodBias = 1.0;
8566 sampler_ci.anisotropyEnable = VK_FALSE;
8567 sampler_ci.maxAnisotropy = 1;
8568 sampler_ci.compareEnable = VK_FALSE;
8569 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8570 sampler_ci.minLod = 1.0;
8571 sampler_ci.maxLod = 1.0;
8572 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8573 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008574
8575 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008576 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008577 ASSERT_VK_SUCCESS(err);
8578
Karl Schultz6addd812016-02-02 17:17:23 -07008579 VkImageView view =
8580 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008581
8582 VkDescriptorImageInfo descriptor_info;
8583 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8584 descriptor_info.sampler = sampler;
8585 descriptor_info.imageView = view;
8586
8587 VkWriteDescriptorSet descriptor_write;
8588 memset(&descriptor_write, 0, sizeof(descriptor_write));
8589 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008590 descriptor_write.dstSet = descriptorSet;
8591 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008592 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008593 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8594 descriptor_write.pImageInfo = &descriptor_info;
8595
8596 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8597
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008598 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008599
Chia-I Wuf7458c52015-10-26 21:10:41 +08008600 vkDestroySampler(m_device->device(), sampler, NULL);
8601 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008603}
8604
Karl Schultz6addd812016-02-02 17:17:23 -07008605TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8606 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8607 // into the other
8608 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008609
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8611 " binding #1 with type "
8612 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8613 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008614
Tobin Ehlis04356f92015-10-27 16:35:27 -06008615 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008616 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008617 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008618 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8619 ds_type_count[0].descriptorCount = 1;
8620 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8621 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008622
8623 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008624 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8625 ds_pool_ci.pNext = NULL;
8626 ds_pool_ci.maxSets = 1;
8627 ds_pool_ci.poolSizeCount = 2;
8628 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008629
8630 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008631 err =
8632 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008633 ASSERT_VK_SUCCESS(err);
8634 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008635 dsl_binding[0].binding = 0;
8636 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8637 dsl_binding[0].descriptorCount = 1;
8638 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8639 dsl_binding[0].pImmutableSamplers = NULL;
8640 dsl_binding[1].binding = 1;
8641 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8642 dsl_binding[1].descriptorCount = 1;
8643 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8644 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008645
8646 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008647 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8648 ds_layout_ci.pNext = NULL;
8649 ds_layout_ci.bindingCount = 2;
8650 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008651
8652 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008653 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8654 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008655 ASSERT_VK_SUCCESS(err);
8656
8657 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008658 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008659 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008660 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008661 alloc_info.descriptorPool = ds_pool;
8662 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008663 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8664 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008665 ASSERT_VK_SUCCESS(err);
8666
8667 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008668 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8669 sampler_ci.pNext = NULL;
8670 sampler_ci.magFilter = VK_FILTER_NEAREST;
8671 sampler_ci.minFilter = VK_FILTER_NEAREST;
8672 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8673 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8674 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8675 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8676 sampler_ci.mipLodBias = 1.0;
8677 sampler_ci.anisotropyEnable = VK_FALSE;
8678 sampler_ci.maxAnisotropy = 1;
8679 sampler_ci.compareEnable = VK_FALSE;
8680 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8681 sampler_ci.minLod = 1.0;
8682 sampler_ci.maxLod = 1.0;
8683 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8684 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008685
8686 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008687 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008688 ASSERT_VK_SUCCESS(err);
8689
8690 VkDescriptorImageInfo info = {};
8691 info.sampler = sampler;
8692
8693 VkWriteDescriptorSet descriptor_write;
8694 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8695 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008696 descriptor_write.dstSet = descriptorSet;
8697 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008698 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008699 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8700 descriptor_write.pImageInfo = &info;
8701 // This write update should succeed
8702 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8703 // Now perform a copy update that fails due to type mismatch
8704 VkCopyDescriptorSet copy_ds_update;
8705 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8706 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8707 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008708 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008709 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008710 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008711 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008712 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8713
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008714 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008715 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008716 m_errorMonitor->SetDesiredFailureMsg(
8717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008718 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008719 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8720 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8721 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008722 copy_ds_update.srcBinding =
8723 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008724 copy_ds_update.dstSet = descriptorSet;
8725 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008726 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008727 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8728
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008729 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008730
Tobin Ehlis04356f92015-10-27 16:35:27 -06008731 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008732 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008733 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8734 "update array offset of 0 and update of "
8735 "5 descriptors oversteps total number "
8736 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008737
Tobin Ehlis04356f92015-10-27 16:35:27 -06008738 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8739 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8740 copy_ds_update.srcSet = descriptorSet;
8741 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008742 copy_ds_update.dstSet = descriptorSet;
8743 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008744 copy_ds_update.descriptorCount =
8745 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008746 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8747
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008748 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008749
Chia-I Wuf7458c52015-10-26 21:10:41 +08008750 vkDestroySampler(m_device->device(), sampler, NULL);
8751 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8752 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008753}
8754
Karl Schultz6addd812016-02-02 17:17:23 -07008755TEST_F(VkLayerTest, NumSamplesMismatch) {
8756 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8757 // sampleCount
8758 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008759
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008761 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008762
Tobin Ehlis3b780662015-05-28 12:11:26 -06008763 ASSERT_NO_FATAL_FAILURE(InitState());
8764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008765 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008766 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008767 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008768
8769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8771 ds_pool_ci.pNext = NULL;
8772 ds_pool_ci.maxSets = 1;
8773 ds_pool_ci.poolSizeCount = 1;
8774 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008775
Tobin Ehlis3b780662015-05-28 12:11:26 -06008776 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008777 err =
8778 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008779 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008780
Tony Barboureb254902015-07-15 12:50:33 -06008781 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008782 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008783 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008784 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008785 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8786 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008787
Tony Barboureb254902015-07-15 12:50:33 -06008788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8790 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008791 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008792 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008793
Tobin Ehlis3b780662015-05-28 12:11:26 -06008794 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008795 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8796 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008797 ASSERT_VK_SUCCESS(err);
8798
8799 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008800 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008802 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008803 alloc_info.descriptorPool = ds_pool;
8804 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8806 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008807 ASSERT_VK_SUCCESS(err);
8808
Tony Barboureb254902015-07-15 12:50:33 -06008809 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008810 pipe_ms_state_ci.sType =
8811 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8812 pipe_ms_state_ci.pNext = NULL;
8813 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8814 pipe_ms_state_ci.sampleShadingEnable = 0;
8815 pipe_ms_state_ci.minSampleShading = 1.0;
8816 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008817
Tony Barboureb254902015-07-15 12:50:33 -06008818 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008819 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8820 pipeline_layout_ci.pNext = NULL;
8821 pipeline_layout_ci.setLayoutCount = 1;
8822 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008823
8824 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008825 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8826 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008827 ASSERT_VK_SUCCESS(err);
8828
Karl Schultz6addd812016-02-02 17:17:23 -07008829 VkShaderObj vs(m_device, bindStateVertShaderText,
8830 VK_SHADER_STAGE_VERTEX_BIT, this);
8831 VkShaderObj fs(m_device, bindStateFragShaderText,
8832 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008833 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008834 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008835 VkPipelineObj pipe(m_device);
8836 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008837 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008838 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008839 pipe.SetMSAA(&pipe_ms_state_ci);
8840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008841
Tony Barbourfe3351b2015-07-28 10:17:20 -06008842 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008843 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8844 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008845
Mark Young29927482016-05-04 14:38:51 -06008846 // Render triangle (the error should trigger on the attempt to draw).
8847 Draw(3, 1, 0, 0);
8848
8849 // Finalize recording of the command buffer
8850 EndCommandBuffer();
8851
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008852 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008853
Chia-I Wuf7458c52015-10-26 21:10:41 +08008854 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008857}
Mark Young29927482016-05-04 14:38:51 -06008858
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008859TEST_F(VkLayerTest, RenderPassIncompatible) {
8860 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8861 "Initial case is drawing with an active renderpass that's "
8862 "not compatible with the bound PSO's creation renderpass");
8863 VkResult err;
8864
8865 ASSERT_NO_FATAL_FAILURE(InitState());
8866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8867
8868 VkDescriptorSetLayoutBinding dsl_binding = {};
8869 dsl_binding.binding = 0;
8870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8871 dsl_binding.descriptorCount = 1;
8872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8873 dsl_binding.pImmutableSamplers = NULL;
8874
8875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8877 ds_layout_ci.pNext = NULL;
8878 ds_layout_ci.bindingCount = 1;
8879 ds_layout_ci.pBindings = &dsl_binding;
8880
8881 VkDescriptorSetLayout ds_layout;
8882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8883 &ds_layout);
8884 ASSERT_VK_SUCCESS(err);
8885
8886 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8887 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8888 pipeline_layout_ci.pNext = NULL;
8889 pipeline_layout_ci.setLayoutCount = 1;
8890 pipeline_layout_ci.pSetLayouts = &ds_layout;
8891
8892 VkPipelineLayout pipeline_layout;
8893 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8894 &pipeline_layout);
8895 ASSERT_VK_SUCCESS(err);
8896
8897 VkShaderObj vs(m_device, bindStateVertShaderText,
8898 VK_SHADER_STAGE_VERTEX_BIT, this);
8899 VkShaderObj fs(m_device, bindStateFragShaderText,
8900 VK_SHADER_STAGE_FRAGMENT_BIT,
8901 this); // We shouldn't need a fragment shader
8902 // but add it to be able to run on more devices
8903 // Create a renderpass that will be incompatible with default renderpass
8904 VkAttachmentReference attach = {};
8905 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8906 VkAttachmentReference color_att = {};
8907 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8908 VkSubpassDescription subpass = {};
8909 subpass.inputAttachmentCount = 1;
8910 subpass.pInputAttachments = &attach;
8911 subpass.colorAttachmentCount = 1;
8912 subpass.pColorAttachments = &color_att;
8913 VkRenderPassCreateInfo rpci = {};
8914 rpci.subpassCount = 1;
8915 rpci.pSubpasses = &subpass;
8916 rpci.attachmentCount = 1;
8917 VkAttachmentDescription attach_desc = {};
8918 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8919 // Format incompatible with PSO RP color attach format RGBA8_UNORM
8920 attach_desc.format = VK_FORMAT_UNDEFINED;
8921 rpci.pAttachments = &attach_desc;
8922 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8923 VkRenderPass rp;
8924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8925 VkPipelineObj pipe(m_device);
8926 pipe.AddShader(&vs);
8927 pipe.AddShader(&fs);
8928 pipe.AddColorAttachment();
8929 VkViewport view_port = {};
8930 m_viewports.push_back(view_port);
8931 pipe.SetViewport(m_viewports);
8932 VkRect2D rect = {};
8933 m_scissors.push_back(rect);
8934 pipe.SetScissor(m_scissors);
8935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8936
8937 VkCommandBufferInheritanceInfo cbii = {};
8938 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8939 cbii.renderPass = rp;
8940 cbii.subpass = 0;
8941 VkCommandBufferBeginInfo cbbi = {};
8942 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8943 cbbi.pInheritanceInfo = &cbii;
8944 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
8945 VkRenderPassBeginInfo rpbi = {};
8946 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8947 rpbi.framebuffer = m_framebuffer;
8948 rpbi.renderPass = rp;
8949 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
8950 VK_SUBPASS_CONTENTS_INLINE);
8951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8952 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8953
8954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8955 " is incompatible w/ gfx pipeline ");
8956 // Render triangle (the error should trigger on the attempt to draw).
8957 Draw(3, 1, 0, 0);
8958
8959 // Finalize recording of the command buffer
8960 EndCommandBuffer();
8961
8962 m_errorMonitor->VerifyFound();
8963
8964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8966 vkDestroyRenderPass(m_device->device(), rp, NULL);
8967}
8968
Mark Youngc89c6312016-03-31 16:03:20 -06008969TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8970 // Create Pipeline where the number of blend attachments doesn't match the
8971 // number of color attachments. In this case, we don't add any color
8972 // blend attachments even though we have a color attachment.
8973 VkResult err;
8974
8975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008976 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008977
8978 ASSERT_NO_FATAL_FAILURE(InitState());
8979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8980 VkDescriptorPoolSize ds_type_count = {};
8981 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8982 ds_type_count.descriptorCount = 1;
8983
8984 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8985 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8986 ds_pool_ci.pNext = NULL;
8987 ds_pool_ci.maxSets = 1;
8988 ds_pool_ci.poolSizeCount = 1;
8989 ds_pool_ci.pPoolSizes = &ds_type_count;
8990
8991 VkDescriptorPool ds_pool;
8992 err =
8993 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8994 ASSERT_VK_SUCCESS(err);
8995
8996 VkDescriptorSetLayoutBinding dsl_binding = {};
8997 dsl_binding.binding = 0;
8998 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8999 dsl_binding.descriptorCount = 1;
9000 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9001 dsl_binding.pImmutableSamplers = NULL;
9002
9003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9005 ds_layout_ci.pNext = NULL;
9006 ds_layout_ci.bindingCount = 1;
9007 ds_layout_ci.pBindings = &dsl_binding;
9008
9009 VkDescriptorSetLayout ds_layout;
9010 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9011 &ds_layout);
9012 ASSERT_VK_SUCCESS(err);
9013
9014 VkDescriptorSet descriptorSet;
9015 VkDescriptorSetAllocateInfo alloc_info = {};
9016 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9017 alloc_info.descriptorSetCount = 1;
9018 alloc_info.descriptorPool = ds_pool;
9019 alloc_info.pSetLayouts = &ds_layout;
9020 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9021 &descriptorSet);
9022 ASSERT_VK_SUCCESS(err);
9023
9024 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9025 pipe_ms_state_ci.sType =
9026 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9027 pipe_ms_state_ci.pNext = NULL;
9028 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9029 pipe_ms_state_ci.sampleShadingEnable = 0;
9030 pipe_ms_state_ci.minSampleShading = 1.0;
9031 pipe_ms_state_ci.pSampleMask = NULL;
9032
9033 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9034 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9035 pipeline_layout_ci.pNext = NULL;
9036 pipeline_layout_ci.setLayoutCount = 1;
9037 pipeline_layout_ci.pSetLayouts = &ds_layout;
9038
9039 VkPipelineLayout pipeline_layout;
9040 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9041 &pipeline_layout);
9042 ASSERT_VK_SUCCESS(err);
9043
9044 VkShaderObj vs(m_device, bindStateVertShaderText,
9045 VK_SHADER_STAGE_VERTEX_BIT, this);
9046 VkShaderObj fs(m_device, bindStateFragShaderText,
9047 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009048 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009049 // but add it to be able to run on more devices
9050 VkPipelineObj pipe(m_device);
9051 pipe.AddShader(&vs);
9052 pipe.AddShader(&fs);
9053 pipe.SetMSAA(&pipe_ms_state_ci);
9054 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9055
9056 BeginCommandBuffer();
9057 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9058 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9059
Mark Young29927482016-05-04 14:38:51 -06009060 // Render triangle (the error should trigger on the attempt to draw).
9061 Draw(3, 1, 0, 0);
9062
9063 // Finalize recording of the command buffer
9064 EndCommandBuffer();
9065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009066 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009067
9068 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9070 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9071}
Mark Young29927482016-05-04 14:38:51 -06009072
Mark Muellerd4914412016-06-13 17:52:06 -06009073TEST_F(VkLayerTest, MissingClearAttachment) {
9074 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9075 "structure passed to vkCmdClearAttachments");
9076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9077 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9078 "reference array of active subpass 0");
9079
9080 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9081 m_errorMonitor->VerifyFound();
9082}
9083
Karl Schultz6addd812016-02-02 17:17:23 -07009084TEST_F(VkLayerTest, ClearCmdNoDraw) {
9085 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9086 // to issuing a Draw
9087 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009088
Karl Schultz6addd812016-02-02 17:17:23 -07009089 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009090 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009091 "vkCmdClearAttachments() issued on CB object ");
9092
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009093 ASSERT_NO_FATAL_FAILURE(InitState());
9094 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009095
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009096 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009097 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9098 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009099
9100 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009101 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9102 ds_pool_ci.pNext = NULL;
9103 ds_pool_ci.maxSets = 1;
9104 ds_pool_ci.poolSizeCount = 1;
9105 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009106
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009107 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009108 err =
9109 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009110 ASSERT_VK_SUCCESS(err);
9111
Tony Barboureb254902015-07-15 12:50:33 -06009112 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009113 dsl_binding.binding = 0;
9114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9115 dsl_binding.descriptorCount = 1;
9116 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9117 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009118
Tony Barboureb254902015-07-15 12:50:33 -06009119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9121 ds_layout_ci.pNext = NULL;
9122 ds_layout_ci.bindingCount = 1;
9123 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009124
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009125 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9127 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009128 ASSERT_VK_SUCCESS(err);
9129
9130 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009131 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009132 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009133 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009134 alloc_info.descriptorPool = ds_pool;
9135 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009136 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9137 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009138 ASSERT_VK_SUCCESS(err);
9139
Tony Barboureb254902015-07-15 12:50:33 -06009140 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009141 pipe_ms_state_ci.sType =
9142 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9143 pipe_ms_state_ci.pNext = NULL;
9144 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9145 pipe_ms_state_ci.sampleShadingEnable = 0;
9146 pipe_ms_state_ci.minSampleShading = 1.0;
9147 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009148
Tony Barboureb254902015-07-15 12:50:33 -06009149 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009150 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9151 pipeline_layout_ci.pNext = NULL;
9152 pipeline_layout_ci.setLayoutCount = 1;
9153 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009154
9155 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009156 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9157 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009158 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009159
Karl Schultz6addd812016-02-02 17:17:23 -07009160 VkShaderObj vs(m_device, bindStateVertShaderText,
9161 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009162 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009163 // on more devices
9164 VkShaderObj fs(m_device, bindStateFragShaderText,
9165 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009166
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009167 VkPipelineObj pipe(m_device);
9168 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009169 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009170 pipe.SetMSAA(&pipe_ms_state_ci);
9171 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009172
9173 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009174
Karl Schultz6addd812016-02-02 17:17:23 -07009175 // Main thing we care about for this test is that the VkImage obj we're
9176 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009177 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009178 VkClearAttachment color_attachment;
9179 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9180 color_attachment.clearValue.color.float32[0] = 1.0;
9181 color_attachment.clearValue.color.float32[1] = 1.0;
9182 color_attachment.clearValue.color.float32[2] = 1.0;
9183 color_attachment.clearValue.color.float32[3] = 1.0;
9184 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009185 VkClearRect clear_rect = {
9186 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009187
Karl Schultz6addd812016-02-02 17:17:23 -07009188 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9189 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009190
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009191 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009192
Chia-I Wuf7458c52015-10-26 21:10:41 +08009193 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9194 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009196}
9197
Karl Schultz6addd812016-02-02 17:17:23 -07009198TEST_F(VkLayerTest, VtxBufferBadIndex) {
9199 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009200
Karl Schultz6addd812016-02-02 17:17:23 -07009201 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009202 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009203 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009204
Tobin Ehlis502480b2015-06-24 15:53:07 -06009205 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009206 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009208
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009209 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009210 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9211 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009212
9213 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009214 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9215 ds_pool_ci.pNext = NULL;
9216 ds_pool_ci.maxSets = 1;
9217 ds_pool_ci.poolSizeCount = 1;
9218 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009219
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009220 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009221 err =
9222 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009223 ASSERT_VK_SUCCESS(err);
9224
Tony Barboureb254902015-07-15 12:50:33 -06009225 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009226 dsl_binding.binding = 0;
9227 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9228 dsl_binding.descriptorCount = 1;
9229 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9230 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009231
Tony Barboureb254902015-07-15 12:50:33 -06009232 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009233 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9234 ds_layout_ci.pNext = NULL;
9235 ds_layout_ci.bindingCount = 1;
9236 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009237
Tobin Ehlis502480b2015-06-24 15:53:07 -06009238 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009239 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9240 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009241 ASSERT_VK_SUCCESS(err);
9242
9243 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009244 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009245 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009246 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009247 alloc_info.descriptorPool = ds_pool;
9248 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9250 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009251 ASSERT_VK_SUCCESS(err);
9252
Tony Barboureb254902015-07-15 12:50:33 -06009253 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009254 pipe_ms_state_ci.sType =
9255 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9256 pipe_ms_state_ci.pNext = NULL;
9257 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9258 pipe_ms_state_ci.sampleShadingEnable = 0;
9259 pipe_ms_state_ci.minSampleShading = 1.0;
9260 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009261
Tony Barboureb254902015-07-15 12:50:33 -06009262 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009263 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9264 pipeline_layout_ci.pNext = NULL;
9265 pipeline_layout_ci.setLayoutCount = 1;
9266 pipeline_layout_ci.pSetLayouts = &ds_layout;
9267 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009268
Karl Schultz6addd812016-02-02 17:17:23 -07009269 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9270 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009271 ASSERT_VK_SUCCESS(err);
9272
Karl Schultz6addd812016-02-02 17:17:23 -07009273 VkShaderObj vs(m_device, bindStateVertShaderText,
9274 VK_SHADER_STAGE_VERTEX_BIT, this);
9275 VkShaderObj fs(m_device, bindStateFragShaderText,
9276 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009277 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009278 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009279 VkPipelineObj pipe(m_device);
9280 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009281 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009282 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009283 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009284 pipe.SetViewport(m_viewports);
9285 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009287
9288 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009289 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9290 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009291 // Don't care about actual data, just need to get to draw to flag error
9292 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009293 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9294 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009295 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009296 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009298 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009299
Chia-I Wuf7458c52015-10-26 21:10:41 +08009300 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9301 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9302 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009303}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009304// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9305TEST_F(VkLayerTest, InvalidImageLayout) {
9306 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9307 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9308 "images in the wrong layout when they're copied or transitioned.");
9309 // 3 in ValidateCmdBufImageLayouts
9310 // * -1 Attempt to submit cmd buf w/ deleted image
9311 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9312 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9313 m_errorMonitor->SetDesiredFailureMsg(
9314 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9315 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9316
9317 ASSERT_NO_FATAL_FAILURE(InitState());
9318 // Create src & dst images to use for copy operations
9319 VkImage src_image;
9320 VkImage dst_image;
9321
9322 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9323 const int32_t tex_width = 32;
9324 const int32_t tex_height = 32;
9325
9326 VkImageCreateInfo image_create_info = {};
9327 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9328 image_create_info.pNext = NULL;
9329 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9330 image_create_info.format = tex_format;
9331 image_create_info.extent.width = tex_width;
9332 image_create_info.extent.height = tex_height;
9333 image_create_info.extent.depth = 1;
9334 image_create_info.mipLevels = 1;
9335 image_create_info.arrayLayers = 4;
9336 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9337 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9338 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9339 image_create_info.flags = 0;
9340
9341 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9342 ASSERT_VK_SUCCESS(err);
9343 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9344 ASSERT_VK_SUCCESS(err);
9345
9346 BeginCommandBuffer();
9347 VkImageCopy copyRegion;
9348 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9349 copyRegion.srcSubresource.mipLevel = 0;
9350 copyRegion.srcSubresource.baseArrayLayer = 0;
9351 copyRegion.srcSubresource.layerCount = 1;
9352 copyRegion.srcOffset.x = 0;
9353 copyRegion.srcOffset.y = 0;
9354 copyRegion.srcOffset.z = 0;
9355 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9356 copyRegion.dstSubresource.mipLevel = 0;
9357 copyRegion.dstSubresource.baseArrayLayer = 0;
9358 copyRegion.dstSubresource.layerCount = 1;
9359 copyRegion.dstOffset.x = 0;
9360 copyRegion.dstOffset.y = 0;
9361 copyRegion.dstOffset.z = 0;
9362 copyRegion.extent.width = 1;
9363 copyRegion.extent.height = 1;
9364 copyRegion.extent.depth = 1;
9365 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9366 m_errorMonitor->VerifyFound();
9367 // Now cause error due to src image layout changing
9368 m_errorMonitor->SetDesiredFailureMsg(
9369 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9370 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9371 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9372 m_errorMonitor->VerifyFound();
9373 // Final src error is due to bad layout type
9374 m_errorMonitor->SetDesiredFailureMsg(
9375 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9376 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9377 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9378 m_errorMonitor->VerifyFound();
9379 // Now verify same checks for dst
9380 m_errorMonitor->SetDesiredFailureMsg(
9381 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9382 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9383 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9384 m_errorMonitor->VerifyFound();
9385 // Now cause error due to src image layout changing
9386 m_errorMonitor->SetDesiredFailureMsg(
9387 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9389 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9390 m_errorMonitor->VerifyFound();
9391 m_errorMonitor->SetDesiredFailureMsg(
9392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9393 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9394 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9395 m_errorMonitor->VerifyFound();
9396 // Now cause error due to bad image layout transition in PipelineBarrier
9397 VkImageMemoryBarrier image_barrier[1] = {};
9398 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9399 image_barrier[0].image = src_image;
9400 image_barrier[0].subresourceRange.layerCount = 2;
9401 image_barrier[0].subresourceRange.levelCount = 2;
9402 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9403 m_errorMonitor->SetDesiredFailureMsg(
9404 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9405 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9406 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9407 m_errorMonitor->VerifyFound();
9408
9409 // Finally some layout errors at RenderPass create time
9410 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9411 VkAttachmentReference attach = {};
9412 // perf warning for GENERAL layout w/ non-DS input attachment
9413 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9414 VkSubpassDescription subpass = {};
9415 subpass.inputAttachmentCount = 1;
9416 subpass.pInputAttachments = &attach;
9417 VkRenderPassCreateInfo rpci = {};
9418 rpci.subpassCount = 1;
9419 rpci.pSubpasses = &subpass;
9420 rpci.attachmentCount = 1;
9421 VkAttachmentDescription attach_desc = {};
9422 attach_desc.format = VK_FORMAT_UNDEFINED;
9423 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009424 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009425 VkRenderPass rp;
9426 m_errorMonitor->SetDesiredFailureMsg(
9427 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9428 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9429 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9430 m_errorMonitor->VerifyFound();
9431 // error w/ non-general layout
9432 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9433
9434 m_errorMonitor->SetDesiredFailureMsg(
9435 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9436 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9437 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9438 m_errorMonitor->VerifyFound();
9439 subpass.inputAttachmentCount = 0;
9440 subpass.colorAttachmentCount = 1;
9441 subpass.pColorAttachments = &attach;
9442 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9443 // perf warning for GENERAL layout on color attachment
9444 m_errorMonitor->SetDesiredFailureMsg(
9445 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9446 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9447 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9448 m_errorMonitor->VerifyFound();
9449 // error w/ non-color opt or GENERAL layout for color attachment
9450 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9451 m_errorMonitor->SetDesiredFailureMsg(
9452 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9453 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9454 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9455 m_errorMonitor->VerifyFound();
9456 subpass.colorAttachmentCount = 0;
9457 subpass.pDepthStencilAttachment = &attach;
9458 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9459 // perf warning for GENERAL layout on DS attachment
9460 m_errorMonitor->SetDesiredFailureMsg(
9461 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9462 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9463 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9464 m_errorMonitor->VerifyFound();
9465 // error w/ non-ds opt or GENERAL layout for color attachment
9466 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9467 m_errorMonitor->SetDesiredFailureMsg(
9468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9469 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9470 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9471 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009472 // For this error we need a valid renderpass so create default one
9473 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9474 attach.attachment = 0;
9475 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9476 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9477 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9478 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9479 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9480 // Can't do a CLEAR load on READ_ONLY initialLayout
9481 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9482 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9483 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9485 " with invalid first layout "
9486 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9487 "ONLY_OPTIMAL");
9488 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9489 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009490
9491 vkDestroyImage(m_device->device(), src_image, NULL);
9492 vkDestroyImage(m_device->device(), dst_image, NULL);
9493}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009494#endif // DRAW_STATE_TESTS
9495
Tobin Ehlis0788f522015-05-26 16:11:58 -06009496#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009497#if GTEST_IS_THREADSAFE
9498struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009500 VkEvent event;
9501 bool bailout;
9502};
9503
Karl Schultz6addd812016-02-02 17:17:23 -07009504extern "C" void *AddToCommandBuffer(void *arg) {
9505 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009506
Karl Schultz6addd812016-02-02 17:17:23 -07009507 for (int i = 0; i < 10000; i++) {
9508 vkCmdSetEvent(data->commandBuffer, data->event,
9509 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009510 if (data->bailout) {
9511 break;
9512 }
9513 }
9514 return NULL;
9515}
9516
Karl Schultz6addd812016-02-02 17:17:23 -07009517TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009518 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009519
Karl Schultz6addd812016-02-02 17:17:23 -07009520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9521 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009522
Mike Stroyanaccf7692015-05-12 16:00:45 -06009523 ASSERT_NO_FATAL_FAILURE(InitState());
9524 ASSERT_NO_FATAL_FAILURE(InitViewport());
9525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9526
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009527 // Calls AllocateCommandBuffers
9528 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009529
9530 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009531 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009532
9533 VkEventCreateInfo event_info;
9534 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009535 VkResult err;
9536
9537 memset(&event_info, 0, sizeof(event_info));
9538 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9539
Chia-I Wuf7458c52015-10-26 21:10:41 +08009540 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009541 ASSERT_VK_SUCCESS(err);
9542
Mike Stroyanaccf7692015-05-12 16:00:45 -06009543 err = vkResetEvent(device(), event);
9544 ASSERT_VK_SUCCESS(err);
9545
9546 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009547 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009548 data.event = event;
9549 data.bailout = false;
9550 m_errorMonitor->SetBailout(&data.bailout);
9551 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009552 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009553 // Add many entries to command buffer from this thread at the same time.
9554 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009555
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009556 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009557 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009558
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009559 m_errorMonitor->SetBailout(NULL);
9560
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009561 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009562
Chia-I Wuf7458c52015-10-26 21:10:41 +08009563 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009564}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009565#endif // GTEST_IS_THREADSAFE
9566#endif // THREADING_TESTS
9567
Chris Forbes9f7ff632015-05-25 11:13:08 +12009568#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009569TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009571 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009572
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009573 ASSERT_NO_FATAL_FAILURE(InitState());
9574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9575
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009576 VkShaderModule module;
9577 VkShaderModuleCreateInfo moduleCreateInfo;
9578 struct icd_spv_header spv;
9579
9580 spv.magic = ICD_SPV_MAGIC;
9581 spv.version = ICD_SPV_VERSION;
9582 spv.gen_magic = 0;
9583
9584 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9585 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009586 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009587 moduleCreateInfo.codeSize = 4;
9588 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009589 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009590
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009591 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009592}
9593
Karl Schultz6addd812016-02-02 17:17:23 -07009594TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009596 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009597
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009598 ASSERT_NO_FATAL_FAILURE(InitState());
9599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9600
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009601 VkShaderModule module;
9602 VkShaderModuleCreateInfo moduleCreateInfo;
9603 struct icd_spv_header spv;
9604
9605 spv.magic = ~ICD_SPV_MAGIC;
9606 spv.version = ICD_SPV_VERSION;
9607 spv.gen_magic = 0;
9608
9609 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9610 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009611 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009612 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9613 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009614 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009615
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009616 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009617}
9618
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009619#if 0
9620// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009621TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009623 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009624
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009625 ASSERT_NO_FATAL_FAILURE(InitState());
9626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9627
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009628 VkShaderModule module;
9629 VkShaderModuleCreateInfo moduleCreateInfo;
9630 struct icd_spv_header spv;
9631
9632 spv.magic = ICD_SPV_MAGIC;
9633 spv.version = ~ICD_SPV_VERSION;
9634 spv.gen_magic = 0;
9635
9636 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9637 moduleCreateInfo.pNext = NULL;
9638
Karl Schultz6addd812016-02-02 17:17:23 -07009639 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009640 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9641 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009642 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009644 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009645}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009646#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009647
Karl Schultz6addd812016-02-02 17:17:23 -07009648TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009650 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009651
Chris Forbes9f7ff632015-05-25 11:13:08 +12009652 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009654
9655 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009656 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009657 "\n"
9658 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009659 "out gl_PerVertex {\n"
9660 " vec4 gl_Position;\n"
9661 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009662 "void main(){\n"
9663 " gl_Position = vec4(1);\n"
9664 " x = 0;\n"
9665 "}\n";
9666 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009667 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009668 "\n"
9669 "layout(location=0) out vec4 color;\n"
9670 "void main(){\n"
9671 " color = vec4(1);\n"
9672 "}\n";
9673
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009674 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9675 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009676
9677 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009678 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009679 pipe.AddShader(&vs);
9680 pipe.AddShader(&fs);
9681
Chris Forbes9f7ff632015-05-25 11:13:08 +12009682 VkDescriptorSetObj descriptorSet(m_device);
9683 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009684 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009685
Tony Barbour5781e8f2015-08-04 16:23:11 -06009686 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009687
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009688 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009689}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009690
Karl Schultz6addd812016-02-02 17:17:23 -07009691TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009693 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009694
Chris Forbes59cb88d2015-05-25 11:13:13 +12009695 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009696 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009697
9698 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009699 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009700 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009701 "out gl_PerVertex {\n"
9702 " vec4 gl_Position;\n"
9703 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009704 "void main(){\n"
9705 " gl_Position = vec4(1);\n"
9706 "}\n";
9707 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009708 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009709 "\n"
9710 "layout(location=0) in float x;\n"
9711 "layout(location=0) out vec4 color;\n"
9712 "void main(){\n"
9713 " color = vec4(x);\n"
9714 "}\n";
9715
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9717 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009718
9719 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009720 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009721 pipe.AddShader(&vs);
9722 pipe.AddShader(&fs);
9723
Chris Forbes59cb88d2015-05-25 11:13:13 +12009724 VkDescriptorSetObj descriptorSet(m_device);
9725 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009726 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009727
Tony Barbour5781e8f2015-08-04 16:23:11 -06009728 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009729
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009730 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009731}
9732
Karl Schultz6addd812016-02-02 17:17:23 -07009733TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009735 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009736
9737 ASSERT_NO_FATAL_FAILURE(InitState());
9738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9739
9740 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009741 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009742 "\n"
9743 "out gl_PerVertex {\n"
9744 " vec4 gl_Position;\n"
9745 "};\n"
9746 "void main(){\n"
9747 " gl_Position = vec4(1);\n"
9748 "}\n";
9749 char const *fsSource =
9750 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009751 "\n"
9752 "in block { layout(location=0) float x; } ins;\n"
9753 "layout(location=0) out vec4 color;\n"
9754 "void main(){\n"
9755 " color = vec4(ins.x);\n"
9756 "}\n";
9757
9758 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9759 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9760
9761 VkPipelineObj pipe(m_device);
9762 pipe.AddColorAttachment();
9763 pipe.AddShader(&vs);
9764 pipe.AddShader(&fs);
9765
9766 VkDescriptorSetObj descriptorSet(m_device);
9767 descriptorSet.AppendDummy();
9768 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9769
9770 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009772 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009773}
9774
Karl Schultz6addd812016-02-02 17:17:23 -07009775TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009777 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009778 "output arr[2] of float32' vs 'ptr to "
9779 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009780
9781 ASSERT_NO_FATAL_FAILURE(InitState());
9782 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9783
9784 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009785 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009786 "\n"
9787 "layout(location=0) out float x[2];\n"
9788 "out gl_PerVertex {\n"
9789 " vec4 gl_Position;\n"
9790 "};\n"
9791 "void main(){\n"
9792 " x[0] = 0; x[1] = 0;\n"
9793 " gl_Position = vec4(1);\n"
9794 "}\n";
9795 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009796 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009797 "\n"
9798 "layout(location=0) in float x[3];\n"
9799 "layout(location=0) out vec4 color;\n"
9800 "void main(){\n"
9801 " color = vec4(x[0] + x[1] + x[2]);\n"
9802 "}\n";
9803
9804 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9805 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9806
9807 VkPipelineObj pipe(m_device);
9808 pipe.AddColorAttachment();
9809 pipe.AddShader(&vs);
9810 pipe.AddShader(&fs);
9811
9812 VkDescriptorSetObj descriptorSet(m_device);
9813 descriptorSet.AppendDummy();
9814 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9815
9816 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009818 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009819}
9820
Karl Schultz6addd812016-02-02 17:17:23 -07009821TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009823 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009824
Chris Forbesb56af562015-05-25 11:13:17 +12009825 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009827
9828 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009829 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009830 "\n"
9831 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009832 "out gl_PerVertex {\n"
9833 " vec4 gl_Position;\n"
9834 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009835 "void main(){\n"
9836 " x = 0;\n"
9837 " gl_Position = vec4(1);\n"
9838 "}\n";
9839 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009840 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009841 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009842 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009843 "layout(location=0) out vec4 color;\n"
9844 "void main(){\n"
9845 " color = vec4(x);\n"
9846 "}\n";
9847
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9849 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009850
9851 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009852 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009853 pipe.AddShader(&vs);
9854 pipe.AddShader(&fs);
9855
Chris Forbesb56af562015-05-25 11:13:17 +12009856 VkDescriptorSetObj descriptorSet(m_device);
9857 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009858 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009859
Tony Barbour5781e8f2015-08-04 16:23:11 -06009860 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009862 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009863}
9864
Karl Schultz6addd812016-02-02 17:17:23 -07009865TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009867 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009868
9869 ASSERT_NO_FATAL_FAILURE(InitState());
9870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9871
9872 char const *vsSource =
9873 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009874 "\n"
9875 "out block { layout(location=0) int x; } outs;\n"
9876 "out gl_PerVertex {\n"
9877 " vec4 gl_Position;\n"
9878 "};\n"
9879 "void main(){\n"
9880 " outs.x = 0;\n"
9881 " gl_Position = vec4(1);\n"
9882 "}\n";
9883 char const *fsSource =
9884 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009885 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009886 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009887 "layout(location=0) out vec4 color;\n"
9888 "void main(){\n"
9889 " color = vec4(ins.x);\n"
9890 "}\n";
9891
9892 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9893 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9894
9895 VkPipelineObj pipe(m_device);
9896 pipe.AddColorAttachment();
9897 pipe.AddShader(&vs);
9898 pipe.AddShader(&fs);
9899
9900 VkDescriptorSetObj descriptorSet(m_device);
9901 descriptorSet.AppendDummy();
9902 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9903
9904 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9905
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009906 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009907}
9908
9909TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9911 "location 0.0 which is not written by vertex shader");
9912
9913 ASSERT_NO_FATAL_FAILURE(InitState());
9914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9915
9916 char const *vsSource =
9917 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009918 "\n"
9919 "out block { layout(location=1) float x; } outs;\n"
9920 "out gl_PerVertex {\n"
9921 " vec4 gl_Position;\n"
9922 "};\n"
9923 "void main(){\n"
9924 " outs.x = 0;\n"
9925 " gl_Position = vec4(1);\n"
9926 "}\n";
9927 char const *fsSource =
9928 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009929 "\n"
9930 "in block { layout(location=0) float x; } ins;\n"
9931 "layout(location=0) out vec4 color;\n"
9932 "void main(){\n"
9933 " color = vec4(ins.x);\n"
9934 "}\n";
9935
9936 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9937 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9938
9939 VkPipelineObj pipe(m_device);
9940 pipe.AddColorAttachment();
9941 pipe.AddShader(&vs);
9942 pipe.AddShader(&fs);
9943
9944 VkDescriptorSetObj descriptorSet(m_device);
9945 descriptorSet.AppendDummy();
9946 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9947
9948 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9949
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009950 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009951}
9952
9953TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9955 "location 0.1 which is not written by vertex shader");
9956
9957 ASSERT_NO_FATAL_FAILURE(InitState());
9958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9959
9960 char const *vsSource =
9961 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009962 "\n"
9963 "out block { layout(location=0, component=0) float x; } outs;\n"
9964 "out gl_PerVertex {\n"
9965 " vec4 gl_Position;\n"
9966 "};\n"
9967 "void main(){\n"
9968 " outs.x = 0;\n"
9969 " gl_Position = vec4(1);\n"
9970 "}\n";
9971 char const *fsSource =
9972 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009973 "\n"
9974 "in block { layout(location=0, component=1) float x; } ins;\n"
9975 "layout(location=0) out vec4 color;\n"
9976 "void main(){\n"
9977 " color = vec4(ins.x);\n"
9978 "}\n";
9979
9980 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9982
9983 VkPipelineObj pipe(m_device);
9984 pipe.AddColorAttachment();
9985 pipe.AddShader(&vs);
9986 pipe.AddShader(&fs);
9987
9988 VkDescriptorSetObj descriptorSet(m_device);
9989 descriptorSet.AppendDummy();
9990 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9991
9992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9993
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009994 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009995}
9996
Karl Schultz6addd812016-02-02 17:17:23 -07009997TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009999 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010000
Chris Forbesde136e02015-05-25 11:13:28 +120010001 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010003
10004 VkVertexInputBindingDescription input_binding;
10005 memset(&input_binding, 0, sizeof(input_binding));
10006
10007 VkVertexInputAttributeDescription input_attrib;
10008 memset(&input_attrib, 0, sizeof(input_attrib));
10009 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10010
10011 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010012 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010013 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010014 "out gl_PerVertex {\n"
10015 " vec4 gl_Position;\n"
10016 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010017 "void main(){\n"
10018 " gl_Position = vec4(1);\n"
10019 "}\n";
10020 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010021 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010022 "\n"
10023 "layout(location=0) out vec4 color;\n"
10024 "void main(){\n"
10025 " color = vec4(1);\n"
10026 "}\n";
10027
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010030
10031 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010032 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010033 pipe.AddShader(&vs);
10034 pipe.AddShader(&fs);
10035
10036 pipe.AddVertexInputBindings(&input_binding, 1);
10037 pipe.AddVertexInputAttribs(&input_attrib, 1);
10038
Chris Forbesde136e02015-05-25 11:13:28 +120010039 VkDescriptorSetObj descriptorSet(m_device);
10040 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010041 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010042
Tony Barbour5781e8f2015-08-04 16:23:11 -060010043 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010044
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010045 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010046}
10047
Karl Schultz6addd812016-02-02 17:17:23 -070010048TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010050 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010051
10052 ASSERT_NO_FATAL_FAILURE(InitState());
10053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10054
10055 VkVertexInputBindingDescription input_binding;
10056 memset(&input_binding, 0, sizeof(input_binding));
10057
10058 VkVertexInputAttributeDescription input_attrib;
10059 memset(&input_attrib, 0, sizeof(input_attrib));
10060 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10061
10062 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010063 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010064 "\n"
10065 "layout(location=1) in float x;\n"
10066 "out gl_PerVertex {\n"
10067 " vec4 gl_Position;\n"
10068 "};\n"
10069 "void main(){\n"
10070 " gl_Position = vec4(x);\n"
10071 "}\n";
10072 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010073 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010074 "\n"
10075 "layout(location=0) out vec4 color;\n"
10076 "void main(){\n"
10077 " color = vec4(1);\n"
10078 "}\n";
10079
10080 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10081 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10082
10083 VkPipelineObj pipe(m_device);
10084 pipe.AddColorAttachment();
10085 pipe.AddShader(&vs);
10086 pipe.AddShader(&fs);
10087
10088 pipe.AddVertexInputBindings(&input_binding, 1);
10089 pipe.AddVertexInputAttribs(&input_attrib, 1);
10090
10091 VkDescriptorSetObj descriptorSet(m_device);
10092 descriptorSet.AppendDummy();
10093 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10094
10095 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10096
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010097 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010098}
10099
Karl Schultz6addd812016-02-02 17:17:23 -070010100TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10101 m_errorMonitor->SetDesiredFailureMsg(
10102 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010103 "VS consumes input at location 0 but not provided");
10104
Chris Forbes62e8e502015-05-25 11:13:29 +120010105 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010107
10108 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010109 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010110 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010111 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010112 "out gl_PerVertex {\n"
10113 " vec4 gl_Position;\n"
10114 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010115 "void main(){\n"
10116 " gl_Position = x;\n"
10117 "}\n";
10118 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010119 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010120 "\n"
10121 "layout(location=0) out vec4 color;\n"
10122 "void main(){\n"
10123 " color = vec4(1);\n"
10124 "}\n";
10125
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010126 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10127 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010128
10129 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010130 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010131 pipe.AddShader(&vs);
10132 pipe.AddShader(&fs);
10133
Chris Forbes62e8e502015-05-25 11:13:29 +120010134 VkDescriptorSetObj descriptorSet(m_device);
10135 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010136 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010137
Tony Barbour5781e8f2015-08-04 16:23:11 -060010138 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010139
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010140 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010141}
10142
Karl Schultz6addd812016-02-02 17:17:23 -070010143TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10144 m_errorMonitor->SetDesiredFailureMsg(
10145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010146 "location 0 does not match VS input type");
10147
Chris Forbesc97d98e2015-05-25 11:13:31 +120010148 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010149 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010150
10151 VkVertexInputBindingDescription input_binding;
10152 memset(&input_binding, 0, sizeof(input_binding));
10153
10154 VkVertexInputAttributeDescription input_attrib;
10155 memset(&input_attrib, 0, sizeof(input_attrib));
10156 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10157
10158 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010159 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010160 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010161 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010162 "out gl_PerVertex {\n"
10163 " vec4 gl_Position;\n"
10164 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010165 "void main(){\n"
10166 " gl_Position = vec4(x);\n"
10167 "}\n";
10168 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010169 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010170 "\n"
10171 "layout(location=0) out vec4 color;\n"
10172 "void main(){\n"
10173 " color = vec4(1);\n"
10174 "}\n";
10175
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010176 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10177 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010178
10179 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010180 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010181 pipe.AddShader(&vs);
10182 pipe.AddShader(&fs);
10183
10184 pipe.AddVertexInputBindings(&input_binding, 1);
10185 pipe.AddVertexInputAttribs(&input_attrib, 1);
10186
Chris Forbesc97d98e2015-05-25 11:13:31 +120010187 VkDescriptorSetObj descriptorSet(m_device);
10188 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010190
Tony Barbour5781e8f2015-08-04 16:23:11 -060010191 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010192
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010193 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010194}
10195
Chris Forbesc68b43c2016-04-06 11:18:47 +120010196TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10197 m_errorMonitor->SetDesiredFailureMsg(
10198 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10199 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10200
10201 ASSERT_NO_FATAL_FAILURE(InitState());
10202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10203
10204 char const *vsSource =
10205 "#version 450\n"
10206 "\n"
10207 "out gl_PerVertex {\n"
10208 " vec4 gl_Position;\n"
10209 "};\n"
10210 "void main(){\n"
10211 " gl_Position = vec4(1);\n"
10212 "}\n";
10213 char const *fsSource =
10214 "#version 450\n"
10215 "\n"
10216 "layout(location=0) out vec4 color;\n"
10217 "void main(){\n"
10218 " color = vec4(1);\n"
10219 "}\n";
10220
10221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10223
10224 VkPipelineObj pipe(m_device);
10225 pipe.AddColorAttachment();
10226 pipe.AddShader(&vs);
10227 pipe.AddShader(&vs);
10228 pipe.AddShader(&fs);
10229
10230 VkDescriptorSetObj descriptorSet(m_device);
10231 descriptorSet.AppendDummy();
10232 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10233
10234 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010236 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010237}
10238
Karl Schultz6addd812016-02-02 17:17:23 -070010239TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010240 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010241
10242 ASSERT_NO_FATAL_FAILURE(InitState());
10243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10244
10245 VkVertexInputBindingDescription input_binding;
10246 memset(&input_binding, 0, sizeof(input_binding));
10247
10248 VkVertexInputAttributeDescription input_attribs[2];
10249 memset(input_attribs, 0, sizeof(input_attribs));
10250
10251 for (int i = 0; i < 2; i++) {
10252 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10253 input_attribs[i].location = i;
10254 }
10255
10256 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010257 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010258 "\n"
10259 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010260 "out gl_PerVertex {\n"
10261 " vec4 gl_Position;\n"
10262 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010263 "void main(){\n"
10264 " gl_Position = x[0] + x[1];\n"
10265 "}\n";
10266 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010267 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010268 "\n"
10269 "layout(location=0) out vec4 color;\n"
10270 "void main(){\n"
10271 " color = vec4(1);\n"
10272 "}\n";
10273
10274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10275 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10276
10277 VkPipelineObj pipe(m_device);
10278 pipe.AddColorAttachment();
10279 pipe.AddShader(&vs);
10280 pipe.AddShader(&fs);
10281
10282 pipe.AddVertexInputBindings(&input_binding, 1);
10283 pipe.AddVertexInputAttribs(input_attribs, 2);
10284
10285 VkDescriptorSetObj descriptorSet(m_device);
10286 descriptorSet.AppendDummy();
10287 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10288
10289 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10290
10291 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010292 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010293}
10294
Chris Forbes2682b242015-11-24 11:13:14 +130010295TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10296{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010297 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010298
10299 ASSERT_NO_FATAL_FAILURE(InitState());
10300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10301
10302 VkVertexInputBindingDescription input_binding;
10303 memset(&input_binding, 0, sizeof(input_binding));
10304
10305 VkVertexInputAttributeDescription input_attribs[2];
10306 memset(input_attribs, 0, sizeof(input_attribs));
10307
10308 for (int i = 0; i < 2; i++) {
10309 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10310 input_attribs[i].location = i;
10311 }
10312
10313 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010314 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010315 "\n"
10316 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010317 "out gl_PerVertex {\n"
10318 " vec4 gl_Position;\n"
10319 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010320 "void main(){\n"
10321 " gl_Position = x[0] + x[1];\n"
10322 "}\n";
10323 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010324 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010325 "\n"
10326 "layout(location=0) out vec4 color;\n"
10327 "void main(){\n"
10328 " color = vec4(1);\n"
10329 "}\n";
10330
10331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10333
10334 VkPipelineObj pipe(m_device);
10335 pipe.AddColorAttachment();
10336 pipe.AddShader(&vs);
10337 pipe.AddShader(&fs);
10338
10339 pipe.AddVertexInputBindings(&input_binding, 1);
10340 pipe.AddVertexInputAttribs(input_attribs, 2);
10341
10342 VkDescriptorSetObj descriptorSet(m_device);
10343 descriptorSet.AppendDummy();
10344 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10345
10346 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10347
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010348 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010349}
Chris Forbes2682b242015-11-24 11:13:14 +130010350
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010351TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10352{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010353 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010354
10355 ASSERT_NO_FATAL_FAILURE(InitState());
10356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10357
10358 char const *vsSource =
10359 "#version 450\n"
10360 "out gl_PerVertex {\n"
10361 " vec4 gl_Position;\n"
10362 "};\n"
10363 "void main(){\n"
10364 " gl_Position = vec4(0);\n"
10365 "}\n";
10366 char const *fsSource =
10367 "#version 450\n"
10368 "\n"
10369 "layout(location=0) out vec4 color;\n"
10370 "void main(){\n"
10371 " color = vec4(1);\n"
10372 "}\n";
10373
10374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10376
10377 VkPipelineObj pipe(m_device);
10378 pipe.AddColorAttachment();
10379 pipe.AddShader(&vs);
10380 pipe.AddShader(&fs);
10381
10382 VkDescriptorSetObj descriptorSet(m_device);
10383 descriptorSet.AppendDummy();
10384 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10385
10386 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010388 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010389}
10390
Chris Forbes912c9192016-04-05 17:50:35 +120010391TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10392{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010393 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010394
10395 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10396
10397 ASSERT_NO_FATAL_FAILURE(InitState());
10398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10399
10400 char const *vsSource =
10401 "#version 450\n"
10402 "out gl_PerVertex {\n"
10403 " vec4 gl_Position;\n"
10404 "};\n"
10405 "layout(location=0) out vec3 x;\n"
10406 "layout(location=1) out ivec3 y;\n"
10407 "layout(location=2) out vec3 z;\n"
10408 "void main(){\n"
10409 " gl_Position = vec4(0);\n"
10410 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10411 "}\n";
10412 char const *fsSource =
10413 "#version 450\n"
10414 "\n"
10415 "layout(location=0) out vec4 color;\n"
10416 "layout(location=0) in float x;\n"
10417 "layout(location=1) flat in int y;\n"
10418 "layout(location=2) in vec2 z;\n"
10419 "void main(){\n"
10420 " color = vec4(1 + x + y + z.x);\n"
10421 "}\n";
10422
10423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10425
10426 VkPipelineObj pipe(m_device);
10427 pipe.AddColorAttachment();
10428 pipe.AddShader(&vs);
10429 pipe.AddShader(&fs);
10430
10431 VkDescriptorSetObj descriptorSet(m_device);
10432 descriptorSet.AppendDummy();
10433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10434
10435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010437 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010438}
10439
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010440TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10441{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010442 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010443
10444 ASSERT_NO_FATAL_FAILURE(InitState());
10445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10446
Chris Forbesc1e852d2016-04-04 19:26:42 +120010447 if (!m_device->phy().features().tessellationShader) {
10448 printf("Device does not support tessellation shaders; skipped.\n");
10449 return;
10450 }
10451
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010452 char const *vsSource =
10453 "#version 450\n"
10454 "void main(){}\n";
10455 char const *tcsSource =
10456 "#version 450\n"
10457 "layout(location=0) out int x[];\n"
10458 "layout(vertices=3) out;\n"
10459 "void main(){\n"
10460 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10461 " gl_TessLevelInner[0] = 1;\n"
10462 " x[gl_InvocationID] = gl_InvocationID;\n"
10463 "}\n";
10464 char const *tesSource =
10465 "#version 450\n"
10466 "layout(triangles, equal_spacing, cw) in;\n"
10467 "layout(location=0) in int x[];\n"
10468 "out gl_PerVertex { vec4 gl_Position; };\n"
10469 "void main(){\n"
10470 " gl_Position.xyz = gl_TessCoord;\n"
10471 " gl_Position.w = x[0] + x[1] + x[2];\n"
10472 "}\n";
10473 char const *fsSource =
10474 "#version 450\n"
10475 "layout(location=0) out vec4 color;\n"
10476 "void main(){\n"
10477 " color = vec4(1);\n"
10478 "}\n";
10479
10480 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10481 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10482 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10484
10485 VkPipelineInputAssemblyStateCreateInfo iasci{
10486 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10487 nullptr,
10488 0,
10489 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10490 VK_FALSE};
10491
Chris Forbesb4cacb62016-04-04 19:15:00 +120010492 VkPipelineTessellationStateCreateInfo tsci{
10493 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10494 nullptr,
10495 0,
10496 3};
10497
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010498 VkPipelineObj pipe(m_device);
10499 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010500 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010501 pipe.AddColorAttachment();
10502 pipe.AddShader(&vs);
10503 pipe.AddShader(&tcs);
10504 pipe.AddShader(&tes);
10505 pipe.AddShader(&fs);
10506
10507 VkDescriptorSetObj descriptorSet(m_device);
10508 descriptorSet.AppendDummy();
10509 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10510
10511 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10512
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010513 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010514}
10515
Chris Forbesa0ab8152016-04-20 13:34:27 +120010516TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10517{
10518 m_errorMonitor->ExpectSuccess();
10519
10520 ASSERT_NO_FATAL_FAILURE(InitState());
10521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10522
10523 if (!m_device->phy().features().geometryShader) {
10524 printf("Device does not support geometry shaders; skipped.\n");
10525 return;
10526 }
10527
10528 char const *vsSource =
10529 "#version 450\n"
10530 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10531 "void main(){\n"
10532 " vs_out.x = vec4(1);\n"
10533 "}\n";
10534 char const *gsSource =
10535 "#version 450\n"
10536 "layout(triangles) in;\n"
10537 "layout(triangle_strip, max_vertices=3) out;\n"
10538 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10539 "out gl_PerVertex { vec4 gl_Position; };\n"
10540 "void main() {\n"
10541 " gl_Position = gs_in[0].x;\n"
10542 " EmitVertex();\n"
10543 "}\n";
10544 char const *fsSource =
10545 "#version 450\n"
10546 "layout(location=0) out vec4 color;\n"
10547 "void main(){\n"
10548 " color = vec4(1);\n"
10549 "}\n";
10550
10551 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10552 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10553 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10554
10555 VkPipelineObj pipe(m_device);
10556 pipe.AddColorAttachment();
10557 pipe.AddShader(&vs);
10558 pipe.AddShader(&gs);
10559 pipe.AddShader(&fs);
10560
10561 VkDescriptorSetObj descriptorSet(m_device);
10562 descriptorSet.AppendDummy();
10563 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10564
10565 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10566
10567 m_errorMonitor->VerifyNotFound();
10568}
10569
Chris Forbesa0193bc2016-04-04 19:19:47 +120010570TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10571{
10572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10573 "is per-vertex in tessellation control shader stage "
10574 "but per-patch in tessellation evaluation shader stage");
10575
10576 ASSERT_NO_FATAL_FAILURE(InitState());
10577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10578
Chris Forbesc1e852d2016-04-04 19:26:42 +120010579 if (!m_device->phy().features().tessellationShader) {
10580 printf("Device does not support tessellation shaders; skipped.\n");
10581 return;
10582 }
10583
Chris Forbesa0193bc2016-04-04 19:19:47 +120010584 char const *vsSource =
10585 "#version 450\n"
10586 "void main(){}\n";
10587 char const *tcsSource =
10588 "#version 450\n"
10589 "layout(location=0) out int x[];\n"
10590 "layout(vertices=3) out;\n"
10591 "void main(){\n"
10592 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10593 " gl_TessLevelInner[0] = 1;\n"
10594 " x[gl_InvocationID] = gl_InvocationID;\n"
10595 "}\n";
10596 char const *tesSource =
10597 "#version 450\n"
10598 "layout(triangles, equal_spacing, cw) in;\n"
10599 "layout(location=0) patch in int x;\n"
10600 "out gl_PerVertex { vec4 gl_Position; };\n"
10601 "void main(){\n"
10602 " gl_Position.xyz = gl_TessCoord;\n"
10603 " gl_Position.w = x;\n"
10604 "}\n";
10605 char const *fsSource =
10606 "#version 450\n"
10607 "layout(location=0) out vec4 color;\n"
10608 "void main(){\n"
10609 " color = vec4(1);\n"
10610 "}\n";
10611
10612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10613 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10614 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10615 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10616
10617 VkPipelineInputAssemblyStateCreateInfo iasci{
10618 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10619 nullptr,
10620 0,
10621 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10622 VK_FALSE};
10623
10624 VkPipelineTessellationStateCreateInfo tsci{
10625 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10626 nullptr,
10627 0,
10628 3};
10629
10630 VkPipelineObj pipe(m_device);
10631 pipe.SetInputAssembly(&iasci);
10632 pipe.SetTessellation(&tsci);
10633 pipe.AddColorAttachment();
10634 pipe.AddShader(&vs);
10635 pipe.AddShader(&tcs);
10636 pipe.AddShader(&tes);
10637 pipe.AddShader(&fs);
10638
10639 VkDescriptorSetObj descriptorSet(m_device);
10640 descriptorSet.AppendDummy();
10641 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10642
10643 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010645 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010646}
10647
Karl Schultz6addd812016-02-02 17:17:23 -070010648TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10649 m_errorMonitor->SetDesiredFailureMsg(
10650 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010651 "Duplicate vertex input binding descriptions for binding 0");
10652
Chris Forbes280ba2c2015-06-12 11:16:41 +120010653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010655
10656 /* Two binding descriptions for binding 0 */
10657 VkVertexInputBindingDescription input_bindings[2];
10658 memset(input_bindings, 0, sizeof(input_bindings));
10659
10660 VkVertexInputAttributeDescription input_attrib;
10661 memset(&input_attrib, 0, sizeof(input_attrib));
10662 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10663
10664 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010665 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010666 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010667 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010668 "out gl_PerVertex {\n"
10669 " vec4 gl_Position;\n"
10670 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010671 "void main(){\n"
10672 " gl_Position = vec4(x);\n"
10673 "}\n";
10674 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010675 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010676 "\n"
10677 "layout(location=0) out vec4 color;\n"
10678 "void main(){\n"
10679 " color = vec4(1);\n"
10680 "}\n";
10681
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010682 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10683 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010684
10685 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010686 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010687 pipe.AddShader(&vs);
10688 pipe.AddShader(&fs);
10689
10690 pipe.AddVertexInputBindings(input_bindings, 2);
10691 pipe.AddVertexInputAttribs(&input_attrib, 1);
10692
Chris Forbes280ba2c2015-06-12 11:16:41 +120010693 VkDescriptorSetObj descriptorSet(m_device);
10694 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010696
Tony Barbour5781e8f2015-08-04 16:23:11 -060010697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010698
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010699 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010700}
Chris Forbes8f68b562015-05-25 11:13:32 +120010701
Chris Forbes35efec72016-04-21 14:32:08 +120010702TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10703 m_errorMonitor->ExpectSuccess();
10704
10705 ASSERT_NO_FATAL_FAILURE(InitState());
10706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10707
10708 if (!m_device->phy().features().tessellationShader) {
10709 printf("Device does not support 64bit vertex attributes; skipped.\n");
10710 return;
10711 }
10712
10713 VkVertexInputBindingDescription input_bindings[1];
10714 memset(input_bindings, 0, sizeof(input_bindings));
10715
10716 VkVertexInputAttributeDescription input_attribs[4];
10717 memset(input_attribs, 0, sizeof(input_attribs));
10718 input_attribs[0].location = 0;
10719 input_attribs[0].offset = 0;
10720 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10721 input_attribs[1].location = 2;
10722 input_attribs[1].offset = 32;
10723 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10724 input_attribs[2].location = 4;
10725 input_attribs[2].offset = 64;
10726 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10727 input_attribs[3].location = 6;
10728 input_attribs[3].offset = 96;
10729 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10730
10731 char const *vsSource =
10732 "#version 450\n"
10733 "\n"
10734 "layout(location=0) in dmat4 x;\n"
10735 "out gl_PerVertex {\n"
10736 " vec4 gl_Position;\n"
10737 "};\n"
10738 "void main(){\n"
10739 " gl_Position = vec4(x[0][0]);\n"
10740 "}\n";
10741 char const *fsSource =
10742 "#version 450\n"
10743 "\n"
10744 "layout(location=0) out vec4 color;\n"
10745 "void main(){\n"
10746 " color = vec4(1);\n"
10747 "}\n";
10748
10749 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10750 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10751
10752 VkPipelineObj pipe(m_device);
10753 pipe.AddColorAttachment();
10754 pipe.AddShader(&vs);
10755 pipe.AddShader(&fs);
10756
10757 pipe.AddVertexInputBindings(input_bindings, 1);
10758 pipe.AddVertexInputAttribs(input_attribs, 4);
10759
10760 VkDescriptorSetObj descriptorSet(m_device);
10761 descriptorSet.AppendDummy();
10762 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10763
10764 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10765
10766 m_errorMonitor->VerifyNotFound();
10767}
10768
Karl Schultz6addd812016-02-02 17:17:23 -070010769TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010771 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010772
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010773 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010774
10775 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010776 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010777 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010778 "out gl_PerVertex {\n"
10779 " vec4 gl_Position;\n"
10780 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010781 "void main(){\n"
10782 " gl_Position = vec4(1);\n"
10783 "}\n";
10784 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010785 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010786 "\n"
10787 "void main(){\n"
10788 "}\n";
10789
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010792
10793 VkPipelineObj pipe(m_device);
10794 pipe.AddShader(&vs);
10795 pipe.AddShader(&fs);
10796
Chia-I Wu08accc62015-07-07 11:50:03 +080010797 /* set up CB 0, not written */
10798 pipe.AddColorAttachment();
10799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010800
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010801 VkDescriptorSetObj descriptorSet(m_device);
10802 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010803 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010804
Tony Barbour5781e8f2015-08-04 16:23:11 -060010805 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010806
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010807 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010808}
10809
Karl Schultz6addd812016-02-02 17:17:23 -070010810TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010811 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010812 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010813 "FS writes to output location 1 with no matching attachment");
10814
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010815 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010816
10817 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010818 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010819 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010820 "out gl_PerVertex {\n"
10821 " vec4 gl_Position;\n"
10822 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010823 "void main(){\n"
10824 " gl_Position = vec4(1);\n"
10825 "}\n";
10826 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010827 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010828 "\n"
10829 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010830 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010831 "void main(){\n"
10832 " x = vec4(1);\n"
10833 " y = vec4(1);\n"
10834 "}\n";
10835
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010836 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10837 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010838
10839 VkPipelineObj pipe(m_device);
10840 pipe.AddShader(&vs);
10841 pipe.AddShader(&fs);
10842
Chia-I Wu08accc62015-07-07 11:50:03 +080010843 /* set up CB 0, not written */
10844 pipe.AddColorAttachment();
10845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010846 /* FS writes CB 1, but we don't configure it */
10847
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010848 VkDescriptorSetObj descriptorSet(m_device);
10849 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010850 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010851
Tony Barbour5781e8f2015-08-04 16:23:11 -060010852 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010853
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010854 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010855}
10856
Karl Schultz6addd812016-02-02 17:17:23 -070010857TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010859 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010860
Chris Forbesa36d69e2015-05-25 11:13:44 +120010861 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010862
10863 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010864 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010865 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010866 "out gl_PerVertex {\n"
10867 " vec4 gl_Position;\n"
10868 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010869 "void main(){\n"
10870 " gl_Position = vec4(1);\n"
10871 "}\n";
10872 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010873 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010874 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010875 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010876 "void main(){\n"
10877 " x = ivec4(1);\n"
10878 "}\n";
10879
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010880 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10881 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010882
10883 VkPipelineObj pipe(m_device);
10884 pipe.AddShader(&vs);
10885 pipe.AddShader(&fs);
10886
Chia-I Wu08accc62015-07-07 11:50:03 +080010887 /* set up CB 0; type is UNORM by default */
10888 pipe.AddColorAttachment();
10889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010890
Chris Forbesa36d69e2015-05-25 11:13:44 +120010891 VkDescriptorSetObj descriptorSet(m_device);
10892 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010893 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010894
Tony Barbour5781e8f2015-08-04 16:23:11 -060010895 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010896
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010897 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010898}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010899
Karl Schultz6addd812016-02-02 17:17:23 -070010900TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010902 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010903
Chris Forbes556c76c2015-08-14 12:04:59 +120010904 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010905
10906 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010907 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010908 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010909 "out gl_PerVertex {\n"
10910 " vec4 gl_Position;\n"
10911 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010912 "void main(){\n"
10913 " gl_Position = vec4(1);\n"
10914 "}\n";
10915 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010916 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010917 "\n"
10918 "layout(location=0) out vec4 x;\n"
10919 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10920 "void main(){\n"
10921 " x = vec4(bar.y);\n"
10922 "}\n";
10923
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010926
Chris Forbes556c76c2015-08-14 12:04:59 +120010927 VkPipelineObj pipe(m_device);
10928 pipe.AddShader(&vs);
10929 pipe.AddShader(&fs);
10930
10931 /* set up CB 0; type is UNORM by default */
10932 pipe.AddColorAttachment();
10933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10934
10935 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010936 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010937
10938 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10939
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010940 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010941}
10942
Chris Forbes5c59e902016-02-26 16:56:09 +130010943TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10945 "not declared in layout");
10946
10947 ASSERT_NO_FATAL_FAILURE(InitState());
10948
10949 char const *vsSource =
10950 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010951 "\n"
10952 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10953 "out gl_PerVertex {\n"
10954 " vec4 gl_Position;\n"
10955 "};\n"
10956 "void main(){\n"
10957 " gl_Position = vec4(consts.x);\n"
10958 "}\n";
10959 char const *fsSource =
10960 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010961 "\n"
10962 "layout(location=0) out vec4 x;\n"
10963 "void main(){\n"
10964 " x = vec4(1);\n"
10965 "}\n";
10966
10967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10969
10970 VkPipelineObj pipe(m_device);
10971 pipe.AddShader(&vs);
10972 pipe.AddShader(&fs);
10973
10974 /* set up CB 0; type is UNORM by default */
10975 pipe.AddColorAttachment();
10976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10977
10978 VkDescriptorSetObj descriptorSet(m_device);
10979 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10980
10981 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10982
10983 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010984 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010985}
10986
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010987TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10988 m_errorMonitor->SetDesiredFailureMsg(
10989 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10990 "Shader uses descriptor slot 0.0");
10991
10992 ASSERT_NO_FATAL_FAILURE(InitState());
10993
10994 char const *csSource =
10995 "#version 450\n"
10996 "\n"
10997 "layout(local_size_x=1) in;\n"
10998 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10999 "void main(){\n"
11000 " x = vec4(1);\n"
11001 "}\n";
11002
11003 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11004
11005 VkDescriptorSetObj descriptorSet(m_device);
11006 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11007
11008 VkComputePipelineCreateInfo cpci = {
11009 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11010 nullptr, 0, {
11011 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11012 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11013 cs.handle(), "main", nullptr
11014 },
11015 descriptorSet.GetPipelineLayout(),
11016 VK_NULL_HANDLE, -1
11017 };
11018
11019 VkPipeline pipe;
11020 VkResult err = vkCreateComputePipelines(
11021 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11022
11023 m_errorMonitor->VerifyFound();
11024
11025 if (err == VK_SUCCESS) {
11026 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11027 }
11028}
11029
11030TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11031 m_errorMonitor->ExpectSuccess();
11032
11033 ASSERT_NO_FATAL_FAILURE(InitState());
11034
11035 char const *csSource =
11036 "#version 450\n"
11037 "\n"
11038 "layout(local_size_x=1) in;\n"
11039 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11040 "void main(){\n"
11041 " // x is not used.\n"
11042 "}\n";
11043
11044 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11045
11046 VkDescriptorSetObj descriptorSet(m_device);
11047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11048
11049 VkComputePipelineCreateInfo cpci = {
11050 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11051 nullptr, 0, {
11052 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11053 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11054 cs.handle(), "main", nullptr
11055 },
11056 descriptorSet.GetPipelineLayout(),
11057 VK_NULL_HANDLE, -1
11058 };
11059
11060 VkPipeline pipe;
11061 VkResult err = vkCreateComputePipelines(
11062 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11063
11064 m_errorMonitor->VerifyNotFound();
11065
11066 if (err == VK_SUCCESS) {
11067 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11068 }
11069}
11070
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011071#endif // SHADER_CHECKER_TESTS
11072
11073#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011074TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011075 m_errorMonitor->SetDesiredFailureMsg(
11076 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011077 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011078
11079 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011080
11081 // Create an image
11082 VkImage image;
11083
Karl Schultz6addd812016-02-02 17:17:23 -070011084 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11085 const int32_t tex_width = 32;
11086 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011087
11088 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011089 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11090 image_create_info.pNext = NULL;
11091 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11092 image_create_info.format = tex_format;
11093 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011094 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011095 image_create_info.extent.depth = 1;
11096 image_create_info.mipLevels = 1;
11097 image_create_info.arrayLayers = 1;
11098 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11099 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11100 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11101 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011102
11103 // Introduce error by sending down a bogus width extent
11104 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011105 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011106
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011107 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011108}
11109
Mark Youngc48c4c12016-04-11 14:26:49 -060011110TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11111 m_errorMonitor->SetDesiredFailureMsg(
11112 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11113 "CreateImage extents is 0 for at least one required dimension");
11114
11115 ASSERT_NO_FATAL_FAILURE(InitState());
11116
11117 // Create an image
11118 VkImage image;
11119
11120 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11121 const int32_t tex_width = 32;
11122 const int32_t tex_height = 32;
11123
11124 VkImageCreateInfo image_create_info = {};
11125 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11126 image_create_info.pNext = NULL;
11127 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11128 image_create_info.format = tex_format;
11129 image_create_info.extent.width = tex_width;
11130 image_create_info.extent.height = tex_height;
11131 image_create_info.extent.depth = 1;
11132 image_create_info.mipLevels = 1;
11133 image_create_info.arrayLayers = 1;
11134 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11135 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11136 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11137 image_create_info.flags = 0;
11138
11139 // Introduce error by sending down a bogus width extent
11140 image_create_info.extent.width = 0;
11141 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11142
11143 m_errorMonitor->VerifyFound();
11144}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011145#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011146
Tobin Ehliscde08892015-09-22 10:11:37 -060011147#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011148TEST_F(VkLayerTest, InvalidImageView) {
11149 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011150
Karl Schultz6addd812016-02-02 17:17:23 -070011151 m_errorMonitor->SetDesiredFailureMsg(
11152 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011153 "vkCreateImageView called with baseMipLevel 10 ");
11154
Tobin Ehliscde08892015-09-22 10:11:37 -060011155 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011156
Mike Stroyana3082432015-09-25 13:39:21 -060011157 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011158 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011159
Karl Schultz6addd812016-02-02 17:17:23 -070011160 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11161 const int32_t tex_width = 32;
11162 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011163
11164 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011165 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11166 image_create_info.pNext = NULL;
11167 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11168 image_create_info.format = tex_format;
11169 image_create_info.extent.width = tex_width;
11170 image_create_info.extent.height = tex_height;
11171 image_create_info.extent.depth = 1;
11172 image_create_info.mipLevels = 1;
11173 image_create_info.arrayLayers = 1;
11174 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11175 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11176 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11177 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011178
Chia-I Wuf7458c52015-10-26 21:10:41 +080011179 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011180 ASSERT_VK_SUCCESS(err);
11181
11182 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011183 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11184 image_view_create_info.image = image;
11185 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11186 image_view_create_info.format = tex_format;
11187 image_view_create_info.subresourceRange.layerCount = 1;
11188 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11189 image_view_create_info.subresourceRange.levelCount = 1;
11190 image_view_create_info.subresourceRange.aspectMask =
11191 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011192
11193 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011194 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11195 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011197 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011198 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011199}
Mike Stroyana3082432015-09-25 13:39:21 -060011200
Karl Schultz6addd812016-02-02 17:17:23 -070011201TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011202 TEST_DESCRIPTION(
11203 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011205 "vkCreateImageView: Color image "
11206 "formats must have ONLY the "
11207 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011208
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011209 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011210
Karl Schultz6addd812016-02-02 17:17:23 -070011211 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011212 VkImageObj image(m_device);
11213 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11214 VK_IMAGE_TILING_LINEAR, 0);
11215 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011216
11217 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011218 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011219 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011220 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11221 image_view_create_info.format = tex_format;
11222 image_view_create_info.subresourceRange.baseMipLevel = 0;
11223 image_view_create_info.subresourceRange.levelCount = 1;
11224 // Cause an error by setting an invalid image aspect
11225 image_view_create_info.subresourceRange.aspectMask =
11226 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011227
11228 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011229 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011231 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011232}
11233
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011234TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011235 VkResult err;
11236 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011237
Karl Schultz6addd812016-02-02 17:17:23 -070011238 m_errorMonitor->SetDesiredFailureMsg(
11239 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011240 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011241
Mike Stroyana3082432015-09-25 13:39:21 -060011242 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011243
11244 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011245 VkImage srcImage;
11246 VkImage dstImage;
11247 VkDeviceMemory srcMem;
11248 VkDeviceMemory destMem;
11249 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011250
11251 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011252 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11253 image_create_info.pNext = NULL;
11254 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11255 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11256 image_create_info.extent.width = 32;
11257 image_create_info.extent.height = 32;
11258 image_create_info.extent.depth = 1;
11259 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011260 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011261 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11262 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11263 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11264 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011265
Karl Schultz6addd812016-02-02 17:17:23 -070011266 err =
11267 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011268 ASSERT_VK_SUCCESS(err);
11269
Karl Schultz6addd812016-02-02 17:17:23 -070011270 err =
11271 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011272 ASSERT_VK_SUCCESS(err);
11273
11274 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011275 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011276 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11277 memAlloc.pNext = NULL;
11278 memAlloc.allocationSize = 0;
11279 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011280
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011281 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011282 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011283 pass =
11284 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011285 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011286 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011287 ASSERT_VK_SUCCESS(err);
11288
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011289 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011290 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011291 pass =
11292 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011293 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011294 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011295 ASSERT_VK_SUCCESS(err);
11296
11297 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11298 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011299 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011300 ASSERT_VK_SUCCESS(err);
11301
11302 BeginCommandBuffer();
11303 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011304 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011305 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011306 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011307 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011308 copyRegion.srcOffset.x = 0;
11309 copyRegion.srcOffset.y = 0;
11310 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011311 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011312 copyRegion.dstSubresource.mipLevel = 0;
11313 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011314 // Introduce failure by forcing the dst layerCount to differ from src
11315 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011316 copyRegion.dstOffset.x = 0;
11317 copyRegion.dstOffset.y = 0;
11318 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011319 copyRegion.extent.width = 1;
11320 copyRegion.extent.height = 1;
11321 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011322 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11323 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011324 EndCommandBuffer();
11325
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011326 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011327
Chia-I Wuf7458c52015-10-26 21:10:41 +080011328 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011329 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011330 vkFreeMemory(m_device->device(), srcMem, NULL);
11331 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011332}
11333
Tony Barbourd6673642016-05-05 14:46:39 -060011334TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11335
11336 TEST_DESCRIPTION("Creating images with unsuported formats ");
11337
11338 ASSERT_NO_FATAL_FAILURE(InitState());
11339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11340 VkImageObj image(m_device);
11341 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11342 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11343 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11344 VK_IMAGE_TILING_OPTIMAL, 0);
11345 ASSERT_TRUE(image.initialized());
11346
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011347 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11348 VkImageCreateInfo image_create_info;
11349 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11350 image_create_info.pNext = NULL;
11351 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11352 image_create_info.format = VK_FORMAT_UNDEFINED;
11353 image_create_info.extent.width = 32;
11354 image_create_info.extent.height = 32;
11355 image_create_info.extent.depth = 1;
11356 image_create_info.mipLevels = 1;
11357 image_create_info.arrayLayers = 1;
11358 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11359 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11360 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11361 image_create_info.flags = 0;
11362
11363 m_errorMonitor->SetDesiredFailureMsg(
11364 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11365 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11366
11367 VkImage localImage;
11368 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11369 m_errorMonitor->VerifyFound();
11370
Tony Barbourd6673642016-05-05 14:46:39 -060011371 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011372 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011373 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11374 VkFormat format = static_cast<VkFormat>(f);
11375 VkFormatProperties fProps = m_device->format_properties(format);
11376 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11377 fProps.optimalTilingFeatures == 0) {
11378 unsupported = format;
11379 break;
11380 }
11381 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011382
Tony Barbourd6673642016-05-05 14:46:39 -060011383 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011384 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011386 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011387
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011388 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011389 m_errorMonitor->VerifyFound();
11390 }
11391}
11392
11393TEST_F(VkLayerTest, ImageLayerViewTests) {
11394 VkResult ret;
11395 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11396
11397 ASSERT_NO_FATAL_FAILURE(InitState());
11398
11399 VkImageObj image(m_device);
11400 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11401 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11402 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11403 VK_IMAGE_TILING_OPTIMAL, 0);
11404 ASSERT_TRUE(image.initialized());
11405
11406 VkImageView imgView;
11407 VkImageViewCreateInfo imgViewInfo = {};
11408 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11409 imgViewInfo.image = image.handle();
11410 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11411 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11412 imgViewInfo.subresourceRange.layerCount = 1;
11413 imgViewInfo.subresourceRange.baseMipLevel = 0;
11414 imgViewInfo.subresourceRange.levelCount = 1;
11415 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11416
11417 m_errorMonitor->SetDesiredFailureMsg(
11418 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11419 "vkCreateImageView called with baseMipLevel");
11420 // View can't have baseMipLevel >= image's mipLevels - Expect
11421 // VIEW_CREATE_ERROR
11422 imgViewInfo.subresourceRange.baseMipLevel = 1;
11423 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11424 m_errorMonitor->VerifyFound();
11425 imgViewInfo.subresourceRange.baseMipLevel = 0;
11426
11427 m_errorMonitor->SetDesiredFailureMsg(
11428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11429 "vkCreateImageView called with baseArrayLayer");
11430 // View can't have baseArrayLayer >= image's arraySize - Expect
11431 // VIEW_CREATE_ERROR
11432 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11433 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11434 m_errorMonitor->VerifyFound();
11435 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11436
11437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11438 "vkCreateImageView called with 0 in "
11439 "pCreateInfo->subresourceRange."
11440 "levelCount");
11441 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11442 imgViewInfo.subresourceRange.levelCount = 0;
11443 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11444 m_errorMonitor->VerifyFound();
11445 imgViewInfo.subresourceRange.levelCount = 1;
11446
11447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11448 "vkCreateImageView called with 0 in "
11449 "pCreateInfo->subresourceRange."
11450 "layerCount");
11451 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11452 imgViewInfo.subresourceRange.layerCount = 0;
11453 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11454 m_errorMonitor->VerifyFound();
11455 imgViewInfo.subresourceRange.layerCount = 1;
11456
11457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11458 "but both must be color formats");
11459 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11460 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11461 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11462 m_errorMonitor->VerifyFound();
11463 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11464
11465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11466 "Formats MUST be IDENTICAL unless "
11467 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11468 "was set on image creation.");
11469 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11470 // VIEW_CREATE_ERROR
11471 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11472 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11473 m_errorMonitor->VerifyFound();
11474 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11475
11476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11477 "can support ImageViews with "
11478 "differing formats but they must be "
11479 "in the same compatibility class.");
11480 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11481 // VIEW_CREATE_ERROR
11482 VkImageCreateInfo mutImgInfo = image.create_info();
11483 VkImage mutImage;
11484 mutImgInfo.format = VK_FORMAT_R8_UINT;
11485 assert(
11486 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11487 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11488 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11489 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11490 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11491 ASSERT_VK_SUCCESS(ret);
11492 imgViewInfo.image = mutImage;
11493 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11494 m_errorMonitor->VerifyFound();
11495 imgViewInfo.image = image.handle();
11496 vkDestroyImage(m_device->handle(), mutImage, NULL);
11497}
11498
11499TEST_F(VkLayerTest, MiscImageLayerTests) {
11500
11501 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11502
11503 ASSERT_NO_FATAL_FAILURE(InitState());
11504
11505 VkImageObj image(m_device);
11506 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11507 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11508 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11509 VK_IMAGE_TILING_OPTIMAL, 0);
11510 ASSERT_TRUE(image.initialized());
11511
11512 m_errorMonitor->SetDesiredFailureMsg(
11513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11514 "number of layers in image subresource is zero");
11515 vk_testing::Buffer buffer;
11516 VkMemoryPropertyFlags reqs = 0;
11517 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11518 VkBufferImageCopy region = {};
11519 region.bufferRowLength = 128;
11520 region.bufferImageHeight = 128;
11521 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11522 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11523 region.imageSubresource.layerCount = 0;
11524 region.imageExtent.height = 4;
11525 region.imageExtent.width = 4;
11526 region.imageExtent.depth = 1;
11527 m_commandBuffer->BeginCommandBuffer();
11528 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11529 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11530 1, &region);
11531 m_errorMonitor->VerifyFound();
11532 region.imageSubresource.layerCount = 1;
11533
11534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11535 "aspectMasks for each region must "
11536 "specify only COLOR or DEPTH or "
11537 "STENCIL");
11538 // Expect MISMATCHED_IMAGE_ASPECT
11539 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11540 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11541 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11542 1, &region);
11543 m_errorMonitor->VerifyFound();
11544 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11545
11546 m_errorMonitor->SetDesiredFailureMsg(
11547 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11548 "If the format of srcImage is a depth, stencil, depth stencil or "
11549 "integer-based format then filter must be VK_FILTER_NEAREST");
11550 // Expect INVALID_FILTER
11551 VkImageObj intImage1(m_device);
11552 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11553 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11554 0);
11555 VkImageObj intImage2(m_device);
11556 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11557 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11558 0);
11559 VkImageBlit blitRegion = {};
11560 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11561 blitRegion.srcSubresource.baseArrayLayer = 0;
11562 blitRegion.srcSubresource.layerCount = 1;
11563 blitRegion.srcSubresource.mipLevel = 0;
11564 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11565 blitRegion.dstSubresource.baseArrayLayer = 0;
11566 blitRegion.dstSubresource.layerCount = 1;
11567 blitRegion.dstSubresource.mipLevel = 0;
11568
11569 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11570 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11571 16, &blitRegion, VK_FILTER_LINEAR);
11572 m_errorMonitor->VerifyFound();
11573
11574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11575 "called with 0 in ppMemoryBarriers");
11576 VkImageMemoryBarrier img_barrier;
11577 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11578 img_barrier.pNext = NULL;
11579 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11580 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11581 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11582 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11583 img_barrier.image = image.handle();
11584 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11585 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11586 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11587 img_barrier.subresourceRange.baseArrayLayer = 0;
11588 img_barrier.subresourceRange.baseMipLevel = 0;
11589 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11590 img_barrier.subresourceRange.layerCount = 0;
11591 img_barrier.subresourceRange.levelCount = 1;
11592 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11593 VK_PIPELINE_STAGE_HOST_BIT,
11594 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11595 nullptr, 1, &img_barrier);
11596 m_errorMonitor->VerifyFound();
11597 img_barrier.subresourceRange.layerCount = 1;
11598}
11599
11600TEST_F(VkLayerTest, ImageFormatLimits) {
11601
11602 TEST_DESCRIPTION("Exceed the limits of image format ");
11603
11604 m_errorMonitor->SetDesiredFailureMsg(
11605 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11606 "CreateImage extents exceed allowable limits for format");
11607 VkImageCreateInfo image_create_info = {};
11608 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11609 image_create_info.pNext = NULL;
11610 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11611 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11612 image_create_info.extent.width = 32;
11613 image_create_info.extent.height = 32;
11614 image_create_info.extent.depth = 1;
11615 image_create_info.mipLevels = 1;
11616 image_create_info.arrayLayers = 1;
11617 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11618 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11619 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11620 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11621 image_create_info.flags = 0;
11622
11623 VkImage nullImg;
11624 VkImageFormatProperties imgFmtProps;
11625 vkGetPhysicalDeviceImageFormatProperties(
11626 gpu(), image_create_info.format, image_create_info.imageType,
11627 image_create_info.tiling, image_create_info.usage,
11628 image_create_info.flags, &imgFmtProps);
11629 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11630 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11631 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11632 m_errorMonitor->VerifyFound();
11633 image_create_info.extent.depth = 1;
11634
11635 m_errorMonitor->SetDesiredFailureMsg(
11636 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11637 "exceeds allowable maximum supported by format of");
11638 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11639 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11640 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11641 m_errorMonitor->VerifyFound();
11642 image_create_info.mipLevels = 1;
11643
11644 m_errorMonitor->SetDesiredFailureMsg(
11645 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11646 "exceeds allowable maximum supported by format of");
11647 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11648 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11649 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11650 m_errorMonitor->VerifyFound();
11651 image_create_info.arrayLayers = 1;
11652
11653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11654 "is not supported by format");
11655 int samples = imgFmtProps.sampleCounts >> 1;
11656 image_create_info.samples = (VkSampleCountFlagBits)samples;
11657 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11658 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11659 m_errorMonitor->VerifyFound();
11660 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11661
11662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11663 "pCreateInfo->initialLayout, must be "
11664 "VK_IMAGE_LAYOUT_UNDEFINED or "
11665 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11666 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11667 // Expect INVALID_LAYOUT
11668 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11669 m_errorMonitor->VerifyFound();
11670 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11671}
11672
Karl Schultz6addd812016-02-02 17:17:23 -070011673TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011674 VkResult err;
11675 bool pass;
11676
11677 // Create color images with different format sizes and try to copy between them
11678 m_errorMonitor->SetDesiredFailureMsg(
11679 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11680 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11681
11682 ASSERT_NO_FATAL_FAILURE(InitState());
11683
11684 // Create two images of different types and try to copy between them
11685 VkImage srcImage;
11686 VkImage dstImage;
11687 VkDeviceMemory srcMem;
11688 VkDeviceMemory destMem;
11689 VkMemoryRequirements memReqs;
11690
11691 VkImageCreateInfo image_create_info = {};
11692 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11693 image_create_info.pNext = NULL;
11694 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11695 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11696 image_create_info.extent.width = 32;
11697 image_create_info.extent.height = 32;
11698 image_create_info.extent.depth = 1;
11699 image_create_info.mipLevels = 1;
11700 image_create_info.arrayLayers = 1;
11701 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11702 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11704 image_create_info.flags = 0;
11705
11706 err =
11707 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11708 ASSERT_VK_SUCCESS(err);
11709
11710 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11711 // Introduce failure by creating second image with a different-sized format.
11712 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11713
11714 err =
11715 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11716 ASSERT_VK_SUCCESS(err);
11717
11718 // Allocate memory
11719 VkMemoryAllocateInfo memAlloc = {};
11720 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11721 memAlloc.pNext = NULL;
11722 memAlloc.allocationSize = 0;
11723 memAlloc.memoryTypeIndex = 0;
11724
11725 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11726 memAlloc.allocationSize = memReqs.size;
11727 pass =
11728 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11729 ASSERT_TRUE(pass);
11730 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11731 ASSERT_VK_SUCCESS(err);
11732
11733 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11734 memAlloc.allocationSize = memReqs.size;
11735 pass =
11736 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11737 ASSERT_TRUE(pass);
11738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11739 ASSERT_VK_SUCCESS(err);
11740
11741 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11742 ASSERT_VK_SUCCESS(err);
11743 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11744 ASSERT_VK_SUCCESS(err);
11745
11746 BeginCommandBuffer();
11747 VkImageCopy copyRegion;
11748 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11749 copyRegion.srcSubresource.mipLevel = 0;
11750 copyRegion.srcSubresource.baseArrayLayer = 0;
11751 copyRegion.srcSubresource.layerCount = 0;
11752 copyRegion.srcOffset.x = 0;
11753 copyRegion.srcOffset.y = 0;
11754 copyRegion.srcOffset.z = 0;
11755 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11756 copyRegion.dstSubresource.mipLevel = 0;
11757 copyRegion.dstSubresource.baseArrayLayer = 0;
11758 copyRegion.dstSubresource.layerCount = 0;
11759 copyRegion.dstOffset.x = 0;
11760 copyRegion.dstOffset.y = 0;
11761 copyRegion.dstOffset.z = 0;
11762 copyRegion.extent.width = 1;
11763 copyRegion.extent.height = 1;
11764 copyRegion.extent.depth = 1;
11765 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11766 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11767 EndCommandBuffer();
11768
11769 m_errorMonitor->VerifyFound();
11770
11771 vkDestroyImage(m_device->device(), srcImage, NULL);
11772 vkDestroyImage(m_device->device(), dstImage, NULL);
11773 vkFreeMemory(m_device->device(), srcMem, NULL);
11774 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011775}
11776
Karl Schultz6addd812016-02-02 17:17:23 -070011777TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11778 VkResult err;
11779 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011780
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011781 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011782 m_errorMonitor->SetDesiredFailureMsg(
11783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011784 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011785
Mike Stroyana3082432015-09-25 13:39:21 -060011786 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011787
11788 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011789 VkImage srcImage;
11790 VkImage dstImage;
11791 VkDeviceMemory srcMem;
11792 VkDeviceMemory destMem;
11793 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011794
11795 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011796 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11797 image_create_info.pNext = NULL;
11798 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11799 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11800 image_create_info.extent.width = 32;
11801 image_create_info.extent.height = 32;
11802 image_create_info.extent.depth = 1;
11803 image_create_info.mipLevels = 1;
11804 image_create_info.arrayLayers = 1;
11805 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11806 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11807 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11808 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011809
Karl Schultz6addd812016-02-02 17:17:23 -070011810 err =
11811 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011812 ASSERT_VK_SUCCESS(err);
11813
Karl Schultzbdb75952016-04-19 11:36:49 -060011814 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11815
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011816 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011817 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011818 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11819 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011820
Karl Schultz6addd812016-02-02 17:17:23 -070011821 err =
11822 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011823 ASSERT_VK_SUCCESS(err);
11824
11825 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011826 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011827 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11828 memAlloc.pNext = NULL;
11829 memAlloc.allocationSize = 0;
11830 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011831
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011832 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011833 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011834 pass =
11835 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011836 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011837 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011838 ASSERT_VK_SUCCESS(err);
11839
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011840 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011841 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011842 pass =
11843 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011844 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011845 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011846 ASSERT_VK_SUCCESS(err);
11847
11848 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11849 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011850 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011851 ASSERT_VK_SUCCESS(err);
11852
11853 BeginCommandBuffer();
11854 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011855 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011856 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011857 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011858 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011859 copyRegion.srcOffset.x = 0;
11860 copyRegion.srcOffset.y = 0;
11861 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011862 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011863 copyRegion.dstSubresource.mipLevel = 0;
11864 copyRegion.dstSubresource.baseArrayLayer = 0;
11865 copyRegion.dstSubresource.layerCount = 0;
11866 copyRegion.dstOffset.x = 0;
11867 copyRegion.dstOffset.y = 0;
11868 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011869 copyRegion.extent.width = 1;
11870 copyRegion.extent.height = 1;
11871 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011872 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11873 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011874 EndCommandBuffer();
11875
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011876 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011877
Chia-I Wuf7458c52015-10-26 21:10:41 +080011878 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011879 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011880 vkFreeMemory(m_device->device(), srcMem, NULL);
11881 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011882}
11883
Karl Schultz6addd812016-02-02 17:17:23 -070011884TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11885 VkResult err;
11886 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011887
Karl Schultz6addd812016-02-02 17:17:23 -070011888 m_errorMonitor->SetDesiredFailureMsg(
11889 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011890 "vkCmdResolveImage called with source sample count less than 2.");
11891
Mike Stroyana3082432015-09-25 13:39:21 -060011892 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011893
11894 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011895 VkImage srcImage;
11896 VkImage dstImage;
11897 VkDeviceMemory srcMem;
11898 VkDeviceMemory destMem;
11899 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011900
11901 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11903 image_create_info.pNext = NULL;
11904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11905 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11906 image_create_info.extent.width = 32;
11907 image_create_info.extent.height = 1;
11908 image_create_info.extent.depth = 1;
11909 image_create_info.mipLevels = 1;
11910 image_create_info.arrayLayers = 1;
11911 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11912 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11913 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11914 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011915
Karl Schultz6addd812016-02-02 17:17:23 -070011916 err =
11917 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011918 ASSERT_VK_SUCCESS(err);
11919
Karl Schultz6addd812016-02-02 17:17:23 -070011920 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011921
Karl Schultz6addd812016-02-02 17:17:23 -070011922 err =
11923 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011924 ASSERT_VK_SUCCESS(err);
11925
11926 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011927 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011928 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11929 memAlloc.pNext = NULL;
11930 memAlloc.allocationSize = 0;
11931 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011932
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011933 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011934 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011935 pass =
11936 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011937 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011938 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011939 ASSERT_VK_SUCCESS(err);
11940
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011941 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011942 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011943 pass =
11944 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011945 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011946 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011947 ASSERT_VK_SUCCESS(err);
11948
11949 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11950 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011951 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011952 ASSERT_VK_SUCCESS(err);
11953
11954 BeginCommandBuffer();
11955 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011956 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11957 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011958 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011959 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011960 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011961 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011962 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011963 resolveRegion.srcOffset.x = 0;
11964 resolveRegion.srcOffset.y = 0;
11965 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011966 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011967 resolveRegion.dstSubresource.mipLevel = 0;
11968 resolveRegion.dstSubresource.baseArrayLayer = 0;
11969 resolveRegion.dstSubresource.layerCount = 0;
11970 resolveRegion.dstOffset.x = 0;
11971 resolveRegion.dstOffset.y = 0;
11972 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011973 resolveRegion.extent.width = 1;
11974 resolveRegion.extent.height = 1;
11975 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011976 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11977 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011978 EndCommandBuffer();
11979
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011980 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011981
Chia-I Wuf7458c52015-10-26 21:10:41 +080011982 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011983 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011984 vkFreeMemory(m_device->device(), srcMem, NULL);
11985 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011986}
11987
Karl Schultz6addd812016-02-02 17:17:23 -070011988TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11989 VkResult err;
11990 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011991
Karl Schultz6addd812016-02-02 17:17:23 -070011992 m_errorMonitor->SetDesiredFailureMsg(
11993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011994 "vkCmdResolveImage called with dest sample count greater than 1.");
11995
Mike Stroyana3082432015-09-25 13:39:21 -060011996 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011997
Chris Forbesa7530692016-05-08 12:35:39 +120011998 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011999 VkImage srcImage;
12000 VkImage dstImage;
12001 VkDeviceMemory srcMem;
12002 VkDeviceMemory destMem;
12003 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012004
12005 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012006 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12007 image_create_info.pNext = NULL;
12008 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12009 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12010 image_create_info.extent.width = 32;
12011 image_create_info.extent.height = 1;
12012 image_create_info.extent.depth = 1;
12013 image_create_info.mipLevels = 1;
12014 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012015 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012016 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12017 // Note: Some implementations expect color attachment usage for any
12018 // multisample surface
12019 image_create_info.usage =
12020 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12021 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012022
Karl Schultz6addd812016-02-02 17:17:23 -070012023 err =
12024 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012025 ASSERT_VK_SUCCESS(err);
12026
Karl Schultz6addd812016-02-02 17:17:23 -070012027 // Note: Some implementations expect color attachment usage for any
12028 // multisample surface
12029 image_create_info.usage =
12030 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012031
Karl Schultz6addd812016-02-02 17:17:23 -070012032 err =
12033 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012034 ASSERT_VK_SUCCESS(err);
12035
12036 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012037 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012038 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12039 memAlloc.pNext = NULL;
12040 memAlloc.allocationSize = 0;
12041 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012042
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012043 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012044 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012045 pass =
12046 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012047 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012048 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012049 ASSERT_VK_SUCCESS(err);
12050
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012051 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012052 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012053 pass =
12054 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012055 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012056 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012057 ASSERT_VK_SUCCESS(err);
12058
12059 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12060 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012061 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012062 ASSERT_VK_SUCCESS(err);
12063
12064 BeginCommandBuffer();
12065 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012066 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12067 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012068 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012069 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012070 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012071 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012072 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012073 resolveRegion.srcOffset.x = 0;
12074 resolveRegion.srcOffset.y = 0;
12075 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012076 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012077 resolveRegion.dstSubresource.mipLevel = 0;
12078 resolveRegion.dstSubresource.baseArrayLayer = 0;
12079 resolveRegion.dstSubresource.layerCount = 0;
12080 resolveRegion.dstOffset.x = 0;
12081 resolveRegion.dstOffset.y = 0;
12082 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012083 resolveRegion.extent.width = 1;
12084 resolveRegion.extent.height = 1;
12085 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012086 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12087 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012088 EndCommandBuffer();
12089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012090 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012091
Chia-I Wuf7458c52015-10-26 21:10:41 +080012092 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012093 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012094 vkFreeMemory(m_device->device(), srcMem, NULL);
12095 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012096}
12097
Karl Schultz6addd812016-02-02 17:17:23 -070012098TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12099 VkResult err;
12100 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012101
Karl Schultz6addd812016-02-02 17:17:23 -070012102 m_errorMonitor->SetDesiredFailureMsg(
12103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012104 "vkCmdResolveImage called with unmatched source and dest formats.");
12105
Mike Stroyana3082432015-09-25 13:39:21 -060012106 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012107
12108 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012109 VkImage srcImage;
12110 VkImage dstImage;
12111 VkDeviceMemory srcMem;
12112 VkDeviceMemory destMem;
12113 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012114
12115 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012116 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12117 image_create_info.pNext = NULL;
12118 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12119 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12120 image_create_info.extent.width = 32;
12121 image_create_info.extent.height = 1;
12122 image_create_info.extent.depth = 1;
12123 image_create_info.mipLevels = 1;
12124 image_create_info.arrayLayers = 1;
12125 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12126 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12127 // Note: Some implementations expect color attachment usage for any
12128 // multisample surface
12129 image_create_info.usage =
12130 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12131 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012132
Karl Schultz6addd812016-02-02 17:17:23 -070012133 err =
12134 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012135 ASSERT_VK_SUCCESS(err);
12136
Karl Schultz6addd812016-02-02 17:17:23 -070012137 // Set format to something other than source image
12138 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12139 // Note: Some implementations expect color attachment usage for any
12140 // multisample surface
12141 image_create_info.usage =
12142 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12143 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012144
Karl Schultz6addd812016-02-02 17:17:23 -070012145 err =
12146 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012147 ASSERT_VK_SUCCESS(err);
12148
12149 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012150 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012151 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12152 memAlloc.pNext = NULL;
12153 memAlloc.allocationSize = 0;
12154 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012155
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012156 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012157 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012158 pass =
12159 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012160 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012161 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012162 ASSERT_VK_SUCCESS(err);
12163
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012164 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012165 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012166 pass =
12167 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012168 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012169 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012170 ASSERT_VK_SUCCESS(err);
12171
12172 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12173 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012174 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012175 ASSERT_VK_SUCCESS(err);
12176
12177 BeginCommandBuffer();
12178 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012179 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12180 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012181 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012182 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012183 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012184 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012185 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012186 resolveRegion.srcOffset.x = 0;
12187 resolveRegion.srcOffset.y = 0;
12188 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012189 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012190 resolveRegion.dstSubresource.mipLevel = 0;
12191 resolveRegion.dstSubresource.baseArrayLayer = 0;
12192 resolveRegion.dstSubresource.layerCount = 0;
12193 resolveRegion.dstOffset.x = 0;
12194 resolveRegion.dstOffset.y = 0;
12195 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012196 resolveRegion.extent.width = 1;
12197 resolveRegion.extent.height = 1;
12198 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012199 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12200 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012201 EndCommandBuffer();
12202
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012203 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012204
Chia-I Wuf7458c52015-10-26 21:10:41 +080012205 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012206 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012207 vkFreeMemory(m_device->device(), srcMem, NULL);
12208 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012209}
12210
Karl Schultz6addd812016-02-02 17:17:23 -070012211TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12212 VkResult err;
12213 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012214
Karl Schultz6addd812016-02-02 17:17:23 -070012215 m_errorMonitor->SetDesiredFailureMsg(
12216 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012217 "vkCmdResolveImage called with unmatched source and dest image types.");
12218
Mike Stroyana3082432015-09-25 13:39:21 -060012219 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012220
12221 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012222 VkImage srcImage;
12223 VkImage dstImage;
12224 VkDeviceMemory srcMem;
12225 VkDeviceMemory destMem;
12226 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012227
12228 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012229 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12230 image_create_info.pNext = NULL;
12231 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12232 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12233 image_create_info.extent.width = 32;
12234 image_create_info.extent.height = 1;
12235 image_create_info.extent.depth = 1;
12236 image_create_info.mipLevels = 1;
12237 image_create_info.arrayLayers = 1;
12238 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12239 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12240 // Note: Some implementations expect color attachment usage for any
12241 // multisample surface
12242 image_create_info.usage =
12243 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12244 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012245
Karl Schultz6addd812016-02-02 17:17:23 -070012246 err =
12247 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012248 ASSERT_VK_SUCCESS(err);
12249
Karl Schultz6addd812016-02-02 17:17:23 -070012250 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12251 // Note: Some implementations expect color attachment usage for any
12252 // multisample surface
12253 image_create_info.usage =
12254 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12255 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012256
Karl Schultz6addd812016-02-02 17:17:23 -070012257 err =
12258 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012259 ASSERT_VK_SUCCESS(err);
12260
12261 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012262 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012263 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12264 memAlloc.pNext = NULL;
12265 memAlloc.allocationSize = 0;
12266 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012267
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012268 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012269 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012270 pass =
12271 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012272 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012274 ASSERT_VK_SUCCESS(err);
12275
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012276 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012277 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012278 pass =
12279 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012280 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012281 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012282 ASSERT_VK_SUCCESS(err);
12283
12284 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12285 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012286 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012287 ASSERT_VK_SUCCESS(err);
12288
12289 BeginCommandBuffer();
12290 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012291 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12292 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012293 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012294 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012295 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012296 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012297 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012298 resolveRegion.srcOffset.x = 0;
12299 resolveRegion.srcOffset.y = 0;
12300 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012301 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012302 resolveRegion.dstSubresource.mipLevel = 0;
12303 resolveRegion.dstSubresource.baseArrayLayer = 0;
12304 resolveRegion.dstSubresource.layerCount = 0;
12305 resolveRegion.dstOffset.x = 0;
12306 resolveRegion.dstOffset.y = 0;
12307 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012308 resolveRegion.extent.width = 1;
12309 resolveRegion.extent.height = 1;
12310 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012311 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12312 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012313 EndCommandBuffer();
12314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012315 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012316
Chia-I Wuf7458c52015-10-26 21:10:41 +080012317 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012318 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012319 vkFreeMemory(m_device->device(), srcMem, NULL);
12320 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012321}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012322
Karl Schultz6addd812016-02-02 17:17:23 -070012323TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012324 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012325 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12326 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012327 // The image format check comes 2nd in validation so we trigger it first,
12328 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012329 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012330
Karl Schultz6addd812016-02-02 17:17:23 -070012331 m_errorMonitor->SetDesiredFailureMsg(
12332 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012333 "Combination depth/stencil image formats can have only the ");
12334
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012335 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012336
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012337 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012338 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12339 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012340
12341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12343 ds_pool_ci.pNext = NULL;
12344 ds_pool_ci.maxSets = 1;
12345 ds_pool_ci.poolSizeCount = 1;
12346 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012347
12348 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012349 err =
12350 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012351 ASSERT_VK_SUCCESS(err);
12352
12353 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012354 dsl_binding.binding = 0;
12355 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12356 dsl_binding.descriptorCount = 1;
12357 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12358 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012359
12360 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012361 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12362 ds_layout_ci.pNext = NULL;
12363 ds_layout_ci.bindingCount = 1;
12364 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012365 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012366 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12367 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012368 ASSERT_VK_SUCCESS(err);
12369
12370 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012371 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012373 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012374 alloc_info.descriptorPool = ds_pool;
12375 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12377 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012378 ASSERT_VK_SUCCESS(err);
12379
Karl Schultz6addd812016-02-02 17:17:23 -070012380 VkImage image_bad;
12381 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012382 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012383 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012384 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012385 const int32_t tex_width = 32;
12386 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012387
12388 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012389 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12390 image_create_info.pNext = NULL;
12391 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12392 image_create_info.format = tex_format_bad;
12393 image_create_info.extent.width = tex_width;
12394 image_create_info.extent.height = tex_height;
12395 image_create_info.extent.depth = 1;
12396 image_create_info.mipLevels = 1;
12397 image_create_info.arrayLayers = 1;
12398 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12399 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12400 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12401 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12402 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012403
Karl Schultz6addd812016-02-02 17:17:23 -070012404 err =
12405 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012406 ASSERT_VK_SUCCESS(err);
12407 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012408 image_create_info.usage =
12409 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12410 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12411 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012412 ASSERT_VK_SUCCESS(err);
12413
12414 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012415 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12416 image_view_create_info.image = image_bad;
12417 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12418 image_view_create_info.format = tex_format_bad;
12419 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12420 image_view_create_info.subresourceRange.baseMipLevel = 0;
12421 image_view_create_info.subresourceRange.layerCount = 1;
12422 image_view_create_info.subresourceRange.levelCount = 1;
12423 image_view_create_info.subresourceRange.aspectMask =
12424 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012425
12426 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012427 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12428 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012429
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012430 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012431
Chia-I Wuf7458c52015-10-26 21:10:41 +080012432 vkDestroyImage(m_device->device(), image_bad, NULL);
12433 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012434 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12435 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012436}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012437
12438TEST_F(VkLayerTest, ClearImageErrors) {
12439 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12440 "ClearDepthStencilImage with a color image.");
12441
12442 ASSERT_NO_FATAL_FAILURE(InitState());
12443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12444
12445 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12446 BeginCommandBuffer();
12447 m_commandBuffer->EndRenderPass();
12448
12449 // Color image
12450 VkClearColorValue clear_color;
12451 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12452 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12453 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12454 const int32_t img_width = 32;
12455 const int32_t img_height = 32;
12456 VkImageCreateInfo image_create_info = {};
12457 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12458 image_create_info.pNext = NULL;
12459 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12460 image_create_info.format = color_format;
12461 image_create_info.extent.width = img_width;
12462 image_create_info.extent.height = img_height;
12463 image_create_info.extent.depth = 1;
12464 image_create_info.mipLevels = 1;
12465 image_create_info.arrayLayers = 1;
12466 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12467 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12468 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12469
12470 vk_testing::Image color_image;
12471 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12472 reqs);
12473
12474 const VkImageSubresourceRange color_range =
12475 vk_testing::Image::subresource_range(image_create_info,
12476 VK_IMAGE_ASPECT_COLOR_BIT);
12477
12478 // Depth/Stencil image
12479 VkClearDepthStencilValue clear_value = {0};
12480 reqs = 0; // don't need HOST_VISIBLE DS image
12481 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12482 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12483 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12484 ds_image_create_info.extent.width = 64;
12485 ds_image_create_info.extent.height = 64;
12486 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12487 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12488
12489 vk_testing::Image ds_image;
12490 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12491 reqs);
12492
12493 const VkImageSubresourceRange ds_range =
12494 vk_testing::Image::subresource_range(ds_image_create_info,
12495 VK_IMAGE_ASPECT_DEPTH_BIT);
12496
12497 m_errorMonitor->SetDesiredFailureMsg(
12498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12499 "vkCmdClearColorImage called with depth/stencil image.");
12500
12501 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12502 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12503 &color_range);
12504
12505 m_errorMonitor->VerifyFound();
12506
Tony Barbour26434b92016-06-02 09:43:50 -060012507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12508 "vkCmdClearColorImage called with "
12509 "image created without "
12510 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12511
12512 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12513 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12514 &color_range);
12515
12516 m_errorMonitor->VerifyFound();
12517
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012518 // Call CmdClearDepthStencilImage with color image
12519 m_errorMonitor->SetDesiredFailureMsg(
12520 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12521 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12522
12523 vkCmdClearDepthStencilImage(
12524 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12525 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12526 &ds_range);
12527
12528 m_errorMonitor->VerifyFound();
12529}
Tobin Ehliscde08892015-09-22 10:11:37 -060012530#endif // IMAGE_TESTS
12531
Tony Barbour300a6082015-04-07 13:44:53 -060012532int main(int argc, char **argv) {
12533 int result;
12534
Cody Northrop8e54a402016-03-08 22:25:52 -070012535#ifdef ANDROID
12536 int vulkanSupport = InitVulkan();
12537 if (vulkanSupport == 0)
12538 return 1;
12539#endif
12540
Tony Barbour300a6082015-04-07 13:44:53 -060012541 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012542 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012543
12544 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12545
12546 result = RUN_ALL_TESTS();
12547
Tony Barbour6918cd52015-04-09 12:58:51 -060012548 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012549 return result;
12550}