blob: c00e753282678e7ce0d2ed1d41d4304aa49e4961 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
1424 mmr.memory = mem;
1425 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1426 m_errorMonitor->SetDesiredFailureMsg(
1427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 ") is less than Memory Object's offset (");
1429 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1430 m_errorMonitor->VerifyFound();
1431 // Now flush range that oversteps mapped range
1432 vkUnmapMemory(m_device->device(), mem);
1433 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1434 ASSERT_VK_SUCCESS(err);
1435 mmr.offset = 16;
1436 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1437 m_errorMonitor->SetDesiredFailureMsg(
1438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 ") exceeds the Memory Object's upper-bound (");
1440 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1441 m_errorMonitor->VerifyFound();
1442
1443 pass =
1444 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1445 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1446 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1447 if (!pass) {
1448 vkFreeMemory(m_device->device(), mem, NULL);
1449 vkDestroyBuffer(m_device->device(), buffer, NULL);
1450 return;
1451 }
1452 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1453 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1454
1455 vkDestroyBuffer(m_device->device(), buffer, NULL);
1456 vkFreeMemory(m_device->device(), mem, NULL);
1457}
1458
Ian Elliott1c32c772016-04-28 14:47:13 -06001459TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1460 VkResult err;
1461 bool pass;
1462
Ian Elliott489eec02016-05-05 14:12:44 -06001463// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1464// following declaration (which is temporarily being moved below):
1465// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001466 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1467 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1468 uint32_t swapchain_image_count = 0;
1469// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1470 uint32_t image_index = 0;
1471// VkPresentInfoKHR present_info = {};
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1476#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1477 // Use the functions from the VK_KHR_android_surface extension without
1478 // enabling that extension:
1479
1480 // Create a surface:
1481 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001482 m_errorMonitor->SetDesiredFailureMsg(
1483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1484 "extension was not enabled for this");
1485 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1486 &surface);
1487 pass = (err != VK_SUCCESS);
1488 ASSERT_TRUE(pass);
1489 m_errorMonitor->VerifyFound();
1490#endif // VK_USE_PLATFORM_ANDROID_KHR
1491
1492
1493#if defined(VK_USE_PLATFORM_MIR_KHR)
1494 // Use the functions from the VK_KHR_mir_surface extension without enabling
1495 // that extension:
1496
1497 // Create a surface:
1498 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001499 m_errorMonitor->SetDesiredFailureMsg(
1500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1501 "extension was not enabled for this");
1502 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1503 pass = (err != VK_SUCCESS);
1504 ASSERT_TRUE(pass);
1505 m_errorMonitor->VerifyFound();
1506
1507 // Tell whether an mir_connection supports presentation:
1508 MirConnection *mir_connection = NULL;
1509 m_errorMonitor->SetDesiredFailureMsg(
1510 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1511 "extension was not enabled for this");
1512 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1513 visual_id);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_MIR_KHR
1516
1517
1518#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1519 // Use the functions from the VK_KHR_wayland_surface extension without
1520 // enabling that extension:
1521
1522 // Create a surface:
1523 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 m_errorMonitor->SetDesiredFailureMsg(
1525 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526 "extension was not enabled for this");
1527 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1528 &surface);
1529 pass = (err != VK_SUCCESS);
1530 ASSERT_TRUE(pass);
1531 m_errorMonitor->VerifyFound();
1532
1533 // Tell whether an wayland_display supports presentation:
1534 struct wl_display wayland_display = {};
1535 m_errorMonitor->SetDesiredFailureMsg(
1536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "extension was not enabled for this");
1538 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1539 &wayland_display);
1540 m_errorMonitor->VerifyFound();
1541#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001542#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001543
1544
1545#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001546// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1547// TO NON-LINUX PLATFORMS:
1548VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 // Use the functions from the VK_KHR_win32_surface extension without
1550 // enabling that extension:
1551
1552 // Create a surface:
1553 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 m_errorMonitor->SetDesiredFailureMsg(
1555 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "extension was not enabled for this");
1557 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1558 &surface);
1559 pass = (err != VK_SUCCESS);
1560 ASSERT_TRUE(pass);
1561 m_errorMonitor->VerifyFound();
1562
1563 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001564 m_errorMonitor->SetDesiredFailureMsg(
1565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1566 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
1573
Ian Elliott1c32c772016-04-28 14:47:13 -06001574#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001575// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1576// TO NON-LINUX PLATFORMS:
1577VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1579 // that extension:
1580
1581 // Create a surface:
1582 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 m_errorMonitor->SetDesiredFailureMsg(
1584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1585 "extension was not enabled for this");
1586 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1587 pass = (err != VK_SUCCESS);
1588 ASSERT_TRUE(pass);
1589 m_errorMonitor->VerifyFound();
1590
1591 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 xcb_visualid_t visual_id = 0;
1594 m_errorMonitor->SetDesiredFailureMsg(
1595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1596 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001598 visual_id);
1599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
1610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001611 m_errorMonitor->SetDesiredFailureMsg(
1612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1613 "extension was not enabled for this");
1614 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1615 pass = (err != VK_SUCCESS);
1616 ASSERT_TRUE(pass);
1617 m_errorMonitor->VerifyFound();
1618
1619 // Tell whether an Xlib VisualID supports presentation:
1620 Display *dpy = NULL;
1621 VisualID visual = 0;
1622 m_errorMonitor->SetDesiredFailureMsg(
1623 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1624 "extension was not enabled for this");
1625 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1626 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001627// Set this (for now, until all platforms are supported and tested):
1628#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001629#endif // VK_USE_PLATFORM_XLIB_KHR
1630
1631
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 // Use the functions from the VK_KHR_surface extension without enabling
1633 // that extension:
1634
Ian Elliott489eec02016-05-05 14:12:44 -06001635#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001636 // Destroy a surface:
1637 m_errorMonitor->SetDesiredFailureMsg(
1638 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1639 "extension was not enabled for this");
1640 vkDestroySurfaceKHR(instance(), surface, NULL);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check if surface supports presentation:
1644 VkBool32 supported = false;
1645 m_errorMonitor->SetDesiredFailureMsg(
1646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1647 "extension was not enabled for this");
1648 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1649 pass = (err != VK_SUCCESS);
1650 ASSERT_TRUE(pass);
1651 m_errorMonitor->VerifyFound();
1652
1653 // Check surface capabilities:
1654 VkSurfaceCapabilitiesKHR capabilities = {};
1655 m_errorMonitor->SetDesiredFailureMsg(
1656 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1657 "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1659 &capabilities);
1660 pass = (err != VK_SUCCESS);
1661 ASSERT_TRUE(pass);
1662 m_errorMonitor->VerifyFound();
1663
1664 // Check surface formats:
1665 uint32_t format_count = 0;
1666 VkSurfaceFormatKHR *formats = NULL;
1667 m_errorMonitor->SetDesiredFailureMsg(
1668 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1669 "extension was not enabled for this");
1670 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1671 &format_count, formats);
1672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Check surface present modes:
1677 uint32_t present_mode_count = 0;
1678 VkSurfaceFormatKHR *present_modes = NULL;
1679 m_errorMonitor->SetDesiredFailureMsg(
1680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1681 "extension was not enabled for this");
1682 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1683 &present_mode_count, present_modes);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001687#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688
1689
1690 // Use the functions from the VK_KHR_swapchain extension without enabling
1691 // that extension:
1692
1693 // Create a swapchain:
1694 m_errorMonitor->SetDesiredFailureMsg(
1695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1696 "extension was not enabled for this");
1697 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1698 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001699 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1700 NULL, &swapchain);
1701 pass = (err != VK_SUCCESS);
1702 ASSERT_TRUE(pass);
1703 m_errorMonitor->VerifyFound();
1704
1705 // Get the images from the swapchain:
1706 m_errorMonitor->SetDesiredFailureMsg(
1707 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "extension was not enabled for this");
1709 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1710 &swapchain_image_count, NULL);
1711 pass = (err != VK_SUCCESS);
1712 ASSERT_TRUE(pass);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Try to acquire an image:
1716 m_errorMonitor->SetDesiredFailureMsg(
1717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1718 "extension was not enabled for this");
1719 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1720 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1721 pass = (err != VK_SUCCESS);
1722 ASSERT_TRUE(pass);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001726 //
1727 // NOTE: Currently can't test this because a real swapchain is needed (as
1728 // opposed to the fake one we created) in order for the layer to lookup the
1729 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001730
1731 // Destroy the swapchain:
1732 m_errorMonitor->SetDesiredFailureMsg(
1733 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1734 "extension was not enabled for this");
1735 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1736 m_errorMonitor->VerifyFound();
1737}
1738
Ian Elliott2c1daf52016-05-12 09:41:46 -06001739TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740
Dustin Graves6c6d8982016-05-17 10:09:21 -06001741#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001743
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744 VkResult err;
1745 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001746 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1747 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001748 // uint32_t swapchain_image_count = 0;
1749 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1750 // uint32_t image_index = 0;
1751 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001752
1753 ASSERT_NO_FATAL_FAILURE(InitState());
1754
1755 // Use the create function from one of the VK_KHR_*_surface extension in
1756 // order to create a surface, testing all known errors in the process,
1757 // before successfully creating a surface:
1758 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001761 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1762 pass = (err != VK_SUCCESS);
1763 ASSERT_TRUE(pass);
1764 m_errorMonitor->VerifyFound();
1765
1766 // Next, try to create a surface with the wrong
1767 // VkXcbSurfaceCreateInfoKHR::sType:
1768 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1769 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1771 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001772 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
Ian Elliott2c1daf52016-05-12 09:41:46 -06001777 // Create a native window, and then correctly create a surface:
1778 xcb_connection_t *connection;
1779 xcb_screen_t *screen;
1780 xcb_window_t xcb_window;
1781 xcb_intern_atom_reply_t *atom_wm_delete_window;
1782
1783 const xcb_setup_t *setup;
1784 xcb_screen_iterator_t iter;
1785 int scr;
1786 uint32_t value_mask, value_list[32];
1787 int width = 1;
1788 int height = 1;
1789
1790 connection = xcb_connect(NULL, &scr);
1791 ASSERT_TRUE(connection != NULL);
1792 setup = xcb_get_setup(connection);
1793 iter = xcb_setup_roots_iterator(setup);
1794 while (scr-- > 0)
1795 xcb_screen_next(&iter);
1796 screen = iter.data;
1797
1798 xcb_window = xcb_generate_id(connection);
1799
1800 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1801 value_list[0] = screen->black_pixel;
1802 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1803 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1804
1805 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1806 screen->root, 0, 0, width, height, 0,
1807 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1808 value_mask, value_list);
1809
1810 /* Magic code that will send notification when window is destroyed */
1811 xcb_intern_atom_cookie_t cookie =
1812 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1813 xcb_intern_atom_reply_t *reply =
1814 xcb_intern_atom_reply(connection, cookie, 0);
1815
1816 xcb_intern_atom_cookie_t cookie2 =
1817 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001818 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001819 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1820 (*reply).atom, 4, 32, 1,
1821 &(*atom_wm_delete_window).atom);
1822 free(reply);
1823
1824 xcb_map_window(connection, xcb_window);
1825
1826 // Force the x/y coordinates to 100,100 results are identical in consecutive
1827 // runs
1828 const uint32_t coords[] = {100, 100};
1829 xcb_configure_window(connection, xcb_window,
1830 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1831
Ian Elliott2c1daf52016-05-12 09:41:46 -06001832 // Finally, try to correctly create a surface:
1833 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1834 xcb_create_info.pNext = NULL;
1835 xcb_create_info.flags = 0;
1836 xcb_create_info.connection = connection;
1837 xcb_create_info.window = xcb_window;
1838 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1839 pass = (err == VK_SUCCESS);
1840 ASSERT_TRUE(pass);
1841
Ian Elliott2c1daf52016-05-12 09:41:46 -06001842 // Check if surface supports presentation:
1843
1844 // 1st, do so without having queried the queue families:
1845 VkBool32 supported = false;
1846 // TODO: Get the following error to come out:
1847 m_errorMonitor->SetDesiredFailureMsg(
1848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1849 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1850 "function");
1851 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1852 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 // ASSERT_TRUE(pass);
1854 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855
1856 // Next, query a queue family index that's too large:
1857 m_errorMonitor->SetDesiredFailureMsg(
1858 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1859 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001860 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1861 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 pass = (err != VK_SUCCESS);
1863 ASSERT_TRUE(pass);
1864 m_errorMonitor->VerifyFound();
1865
1866 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001867 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1868 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001869 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1870 pass = (err == VK_SUCCESS);
1871 ASSERT_TRUE(pass);
1872
Ian Elliott2c1daf52016-05-12 09:41:46 -06001873 // Before proceeding, try to create a swapchain without having called
1874 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1875 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1876 swapchain_create_info.pNext = NULL;
1877 swapchain_create_info.flags = 0;
1878 m_errorMonitor->SetDesiredFailureMsg(
1879 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1880 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001881 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1882 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001883 pass = (err != VK_SUCCESS);
1884 ASSERT_TRUE(pass);
1885 m_errorMonitor->VerifyFound();
1886
Ian Elliott2c1daf52016-05-12 09:41:46 -06001887 // Get the surface capabilities:
1888 VkSurfaceCapabilitiesKHR surface_capabilities;
1889
1890 // Do so correctly (only error logged by this entrypoint is if the
1891 // extension isn't enabled):
1892 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1893 &surface_capabilities);
1894 pass = (err == VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896
Ian Elliott2c1daf52016-05-12 09:41:46 -06001897 // Get the surface formats:
1898 uint32_t surface_format_count;
1899
1900 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1902 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001903 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1904 pass = (err == VK_SUCCESS);
1905 ASSERT_TRUE(pass);
1906 m_errorMonitor->VerifyFound();
1907
1908 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1909 // correctly done a 1st try (to get the count):
1910 m_errorMonitor->SetDesiredFailureMsg(
1911 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1912 "but no prior positive value has been seen for");
1913 surface_format_count = 0;
1914 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001915 gpu(), surface, &surface_format_count,
1916 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001917 pass = (err == VK_SUCCESS);
1918 ASSERT_TRUE(pass);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001922 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1923 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001924 pass = (err == VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926
1927 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001928 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1929 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001930
1931 // Next, do a 2nd try with surface_format_count being set too high:
1932 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1934 "that is greater than the value");
1935 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001936 surface_formats);
1937 pass = (err == VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001942 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1943 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001944 pass = (err == VK_SUCCESS);
1945 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001946 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001947 surface_formats);
1948 pass = (err == VK_SUCCESS);
1949 ASSERT_TRUE(pass);
1950
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951 // Get the surface present modes:
1952 uint32_t surface_present_mode_count;
1953
1954 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1956 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001957 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1958 pass = (err == VK_SUCCESS);
1959 ASSERT_TRUE(pass);
1960 m_errorMonitor->VerifyFound();
1961
1962 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1963 // correctly done a 1st try (to get the count):
1964 m_errorMonitor->SetDesiredFailureMsg(
1965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1966 "but no prior positive value has been seen for");
1967 surface_present_mode_count = 0;
1968 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001969 gpu(), surface, &surface_present_mode_count,
1970 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001971 pass = (err == VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
1975 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001976 vkGetPhysicalDeviceSurfacePresentModesKHR(
1977 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001978 pass = (err == VK_SUCCESS);
1979 ASSERT_TRUE(pass);
1980
1981 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001982 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1983 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001984
1985 // Next, do a 2nd try with surface_format_count being set too high:
1986 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1988 "that is greater than the value");
1989 vkGetPhysicalDeviceSurfacePresentModesKHR(
1990 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001991 pass = (err == VK_SUCCESS);
1992 ASSERT_TRUE(pass);
1993 m_errorMonitor->VerifyFound();
1994
1995 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001996 vkGetPhysicalDeviceSurfacePresentModesKHR(
1997 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 pass = (err == VK_SUCCESS);
1999 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002000 vkGetPhysicalDeviceSurfacePresentModesKHR(
2001 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002002 pass = (err == VK_SUCCESS);
2003 ASSERT_TRUE(pass);
2004
Ian Elliott2c1daf52016-05-12 09:41:46 -06002005 // Create a swapchain:
2006
2007 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2009 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2011 pass = (err != VK_SUCCESS);
2012 ASSERT_TRUE(pass);
2013 m_errorMonitor->VerifyFound();
2014
2015 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2016 // sType:
2017 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2019 "called with the wrong value for");
2020 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2021 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002022 pass = (err != VK_SUCCESS);
2023 ASSERT_TRUE(pass);
2024 m_errorMonitor->VerifyFound();
2025
2026 // Next, call with a NULL swapchain pointer:
2027 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2028 swapchain_create_info.pNext = NULL;
2029 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2031 "called with NULL pointer");
2032 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2033 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002034 pass = (err != VK_SUCCESS);
2035 ASSERT_TRUE(pass);
2036 m_errorMonitor->VerifyFound();
2037
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002038 // TODO: Enhance swapchain layer so that
2039 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002040
2041 // Next, call with a queue family index that's too large:
2042 uint32_t queueFamilyIndex[2] = {100000, 0};
2043 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2044 swapchain_create_info.queueFamilyIndexCount = 2;
2045 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2046 m_errorMonitor->SetDesiredFailureMsg(
2047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2048 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002049 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2050 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002051 pass = (err != VK_SUCCESS);
2052 ASSERT_TRUE(pass);
2053 m_errorMonitor->VerifyFound();
2054
2055 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2056 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2057 swapchain_create_info.queueFamilyIndexCount = 1;
2058 m_errorMonitor->SetDesiredFailureMsg(
2059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2060 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2061 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002062 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2063 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002064 pass = (err != VK_SUCCESS);
2065 ASSERT_TRUE(pass);
2066 m_errorMonitor->VerifyFound();
2067
2068 // Next, call with an invalid imageSharingMode:
2069 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2070 swapchain_create_info.queueFamilyIndexCount = 1;
2071 m_errorMonitor->SetDesiredFailureMsg(
2072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2073 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2075 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002076 pass = (err != VK_SUCCESS);
2077 ASSERT_TRUE(pass);
2078 m_errorMonitor->VerifyFound();
2079 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002080 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2081 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002082 swapchain_create_info.queueFamilyIndexCount = 0;
2083 queueFamilyIndex[0] = 0;
2084 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2085
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002086 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002087 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Destroy the swapchain:
2091
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002092 // TODOs:
2093 //
2094 // - Try destroying the device without first destroying the swapchain
2095 //
2096 // - Try destroying the device without first destroying the surface
2097 //
2098 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002099
2100 // Destroy the surface:
2101 vkDestroySurfaceKHR(instance(), surface, NULL);
2102
Ian Elliott2c1daf52016-05-12 09:41:46 -06002103 // Tear down the window:
2104 xcb_destroy_window(connection, xcb_window);
2105 xcb_disconnect(connection);
2106
2107#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002108 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002109#endif // VK_USE_PLATFORM_XCB_KHR
2110}
2111
Karl Schultz6addd812016-02-02 17:17:23 -07002112TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2113 VkResult err;
2114 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002115
Karl Schultz6addd812016-02-02 17:17:23 -07002116 m_errorMonitor->SetDesiredFailureMsg(
2117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002118 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2119
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121
2122 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002123 VkImage image;
2124 VkDeviceMemory mem;
2125 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002126
Karl Schultz6addd812016-02-02 17:17:23 -07002127 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2128 const int32_t tex_width = 32;
2129 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002130
Tony Barboureb254902015-07-15 12:50:33 -06002131 VkImageCreateInfo image_create_info = {};
2132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002133 image_create_info.pNext = NULL;
2134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2135 image_create_info.format = tex_format;
2136 image_create_info.extent.width = tex_width;
2137 image_create_info.extent.height = tex_height;
2138 image_create_info.extent.depth = 1;
2139 image_create_info.mipLevels = 1;
2140 image_create_info.arrayLayers = 1;
2141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2144 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002145
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002146 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002147 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002148 mem_alloc.pNext = NULL;
2149 mem_alloc.allocationSize = 0;
2150 // Introduce failure, do NOT set memProps to
2151 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2152 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002153
Chia-I Wuf7458c52015-10-26 21:10:41 +08002154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002155 ASSERT_VK_SUCCESS(err);
2156
Karl Schultz6addd812016-02-02 17:17:23 -07002157 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002158
Mark Lobodzinski23065352015-05-29 09:32:35 -05002159 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002160
Karl Schultz6addd812016-02-02 17:17:23 -07002161 pass =
2162 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2163 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2164 if (!pass) { // If we can't find any unmappable memory this test doesn't
2165 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002167 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002169
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002171 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002172 ASSERT_VK_SUCCESS(err);
2173
2174 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002175 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002176 ASSERT_VK_SUCCESS(err);
2177
2178 // Map memory as if to initialize the image
2179 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002180 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2181 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002183 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002184
Chia-I Wuf7458c52015-10-26 21:10:41 +08002185 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002186 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002187}
2188
Karl Schultz6addd812016-02-02 17:17:23 -07002189TEST_F(VkLayerTest, RebindMemory) {
2190 VkResult err;
2191 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002192
Karl Schultz6addd812016-02-02 17:17:23 -07002193 m_errorMonitor->SetDesiredFailureMsg(
2194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002195 "which has already been bound to mem object");
2196
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002197 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198
2199 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002200 VkImage image;
2201 VkDeviceMemory mem1;
2202 VkDeviceMemory mem2;
2203 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002204
Karl Schultz6addd812016-02-02 17:17:23 -07002205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2206 const int32_t tex_width = 32;
2207 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002208
Tony Barboureb254902015-07-15 12:50:33 -06002209 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2211 image_create_info.pNext = NULL;
2212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2213 image_create_info.format = tex_format;
2214 image_create_info.extent.width = tex_width;
2215 image_create_info.extent.height = tex_height;
2216 image_create_info.extent.depth = 1;
2217 image_create_info.mipLevels = 1;
2218 image_create_info.arrayLayers = 1;
2219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2222 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002223
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002224 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002225 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2226 mem_alloc.pNext = NULL;
2227 mem_alloc.allocationSize = 0;
2228 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002229
Karl Schultz6addd812016-02-02 17:17:23 -07002230 // Introduce failure, do NOT set memProps to
2231 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002232 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002234 ASSERT_VK_SUCCESS(err);
2235
Karl Schultz6addd812016-02-02 17:17:23 -07002236 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002237
2238 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002239 pass =
2240 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002241 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002242
2243 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002245 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002247 ASSERT_VK_SUCCESS(err);
2248
2249 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002250 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002251 ASSERT_VK_SUCCESS(err);
2252
Karl Schultz6addd812016-02-02 17:17:23 -07002253 // Introduce validation failure, try to bind a different memory object to
2254 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002255 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002258
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 vkDestroyImage(m_device->device(), image, NULL);
2260 vkFreeMemory(m_device->device(), mem1, NULL);
2261 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002262}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002263
Karl Schultz6addd812016-02-02 17:17:23 -07002264TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002265 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002266
Karl Schultz6addd812016-02-02 17:17:23 -07002267 m_errorMonitor->SetDesiredFailureMsg(
2268 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2269 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002270
2271 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002272 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2273 fenceInfo.pNext = NULL;
2274 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002275
Tony Barbour300a6082015-04-07 13:44:53 -06002276 ASSERT_NO_FATAL_FAILURE(InitState());
2277 ASSERT_NO_FATAL_FAILURE(InitViewport());
2278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2279
Tony Barbourfe3351b2015-07-28 10:17:20 -06002280 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2282 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002283 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002284
2285 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002286
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002287 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002288 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2289 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002290 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002291 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002292 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002293 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002295 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002296 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002297
2298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002299 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002301 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002302}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002303// This is a positive test. We used to expect error in this case but spec now
2304// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002305TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002306 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002307 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002308 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002309 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2310 fenceInfo.pNext = NULL;
2311
Tony Barbour0b4d9562015-04-09 10:48:04 -06002312 ASSERT_NO_FATAL_FAILURE(InitState());
2313 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002314 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002315 VkResult result = vkResetFences(m_device->device(), 1, fences);
2316 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002317
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002318 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002319}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002320
Chris Forbes18127d12016-06-08 16:52:28 +12002321TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2322{
2323 m_errorMonitor->ExpectSuccess();
2324
2325 ASSERT_NO_FATAL_FAILURE(InitState());
2326 VkResult err;
2327
2328 // Record (empty!) command buffer that can be submitted multiple times
2329 // simultaneously.
2330 VkCommandBufferBeginInfo cbbi = {
2331 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2332 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2333 };
2334 m_commandBuffer->BeginCommandBuffer(&cbbi);
2335 m_commandBuffer->EndCommandBuffer();
2336
2337 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2338 VkFence fence;
2339 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2343 VkSemaphore s1, s2;
2344 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2345 ASSERT_VK_SUCCESS(err);
2346 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2347 ASSERT_VK_SUCCESS(err);
2348
2349 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2350 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2351 1, &m_commandBuffer->handle(), 1, &s1 };
2352 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2353 ASSERT_VK_SUCCESS(err);
2354
2355 // Submit CB again, signaling s2.
2356 si.pSignalSemaphores = &s2;
2357 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2358 ASSERT_VK_SUCCESS(err);
2359
2360 // Wait for fence.
2361 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2362 ASSERT_VK_SUCCESS(err);
2363
2364 // CB is still in flight from second submission, but semaphore s1 is no
2365 // longer in flight. delete it.
2366 vkDestroySemaphore(m_device->device(), s1, nullptr);
2367
2368 m_errorMonitor->VerifyNotFound();
2369
2370 // Force device idle and clean up remaining objects
2371 vkDeviceWaitIdle(m_device->device());
2372 vkDestroySemaphore(m_device->device(), s2, nullptr);
2373 vkDestroyFence(m_device->device(), fence, nullptr);
2374}
2375
Tobin Ehlis41376e12015-07-03 08:45:14 -06002376TEST_F(VkLayerTest, InvalidUsageBits)
2377{
Tony Barbourf92621a2016-05-02 14:28:12 -06002378 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002379 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002380 "Initialize buffer with wrong usage then perform copy expecting errors "
2381 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002383 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002384
2385 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002386 VkImageObj image(m_device);
2387 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002388 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002389 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2390 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002391
Tony Barbourf92621a2016-05-02 14:28:12 -06002392 VkImageView dsv;
2393 VkImageViewCreateInfo dsvci = {};
2394 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2395 dsvci.image = image.handle();
2396 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2397 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2398 dsvci.subresourceRange.layerCount = 1;
2399 dsvci.subresourceRange.baseMipLevel = 0;
2400 dsvci.subresourceRange.levelCount = 1;
2401 dsvci.subresourceRange.aspectMask =
2402 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002403
Tony Barbourf92621a2016-05-02 14:28:12 -06002404 // Create a view with depth / stencil aspect for image with different usage
2405 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002408
2409 // Initialize buffer with TRANSFER_DST usage
2410 vk_testing::Buffer buffer;
2411 VkMemoryPropertyFlags reqs = 0;
2412 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2413 VkBufferImageCopy region = {};
2414 region.bufferRowLength = 128;
2415 region.bufferImageHeight = 128;
2416 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2417 region.imageSubresource.layerCount = 1;
2418 region.imageExtent.height = 16;
2419 region.imageExtent.width = 16;
2420 region.imageExtent.depth = 1;
2421
2422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2423 "Invalid usage flag for buffer ");
2424 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2425 // TRANSFER_DST
2426 BeginCommandBuffer();
2427 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2428 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2429 1, &region);
2430 m_errorMonitor->VerifyFound();
2431
2432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2433 "Invalid usage flag for image ");
2434 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2435 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2436 1, &region);
2437 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002438}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002439#endif // MEM_TRACKER_TESTS
2440
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002441#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002442
2443TEST_F(VkLayerTest, LeakAnObject) {
2444 VkResult err;
2445
2446 TEST_DESCRIPTION(
2447 "Create a fence and destroy its device without first destroying the fence.");
2448
2449 // Note that we have to create a new device since destroying the
2450 // framework's device causes Teardown() to fail and just calling Teardown
2451 // will destroy the errorMonitor.
2452
2453 m_errorMonitor->SetDesiredFailureMsg(
2454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2455 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2456
2457 ASSERT_NO_FATAL_FAILURE(InitState());
2458
2459 const std::vector<VkQueueFamilyProperties> queue_props =
2460 m_device->queue_props;
2461 std::vector<VkDeviceQueueCreateInfo> queue_info;
2462 queue_info.reserve(queue_props.size());
2463 std::vector<std::vector<float>> queue_priorities;
2464 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2465 VkDeviceQueueCreateInfo qi = {};
2466 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2467 qi.pNext = NULL;
2468 qi.queueFamilyIndex = i;
2469 qi.queueCount = queue_props[i].queueCount;
2470 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2471 qi.pQueuePriorities = queue_priorities[i].data();
2472 queue_info.push_back(qi);
2473 }
2474
2475 std::vector<const char *> device_layer_names;
2476 std::vector<const char *> device_extension_names;
2477 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2478 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2479 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2480 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2481 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2482 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2483 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2484
2485 // The sacrificial device object
2486 VkDevice testDevice;
2487 VkDeviceCreateInfo device_create_info = {};
2488 auto features = m_device->phy().features();
2489 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2490 device_create_info.pNext = NULL;
2491 device_create_info.queueCreateInfoCount = queue_info.size();
2492 device_create_info.pQueueCreateInfos = queue_info.data();
2493 device_create_info.enabledLayerCount = device_layer_names.size();
2494 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2495 device_create_info.pEnabledFeatures = &features;
2496 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2497 ASSERT_VK_SUCCESS(err);
2498
2499 VkFence fence;
2500 VkFenceCreateInfo fence_create_info = {};
2501 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2502 fence_create_info.pNext = NULL;
2503 fence_create_info.flags = 0;
2504 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 // Induce failure by not calling vkDestroyFence
2508 vkDestroyDevice(testDevice, NULL);
2509 m_errorMonitor->VerifyFound();
2510}
2511
2512TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2513
2514 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2515 "attempt to delete them from another.");
2516
2517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2518 "FreeCommandBuffers is attempting to free Command Buffer");
2519
2520 VkCommandPool command_pool_one;
2521 VkCommandPool command_pool_two;
2522
2523 VkCommandPoolCreateInfo pool_create_info{};
2524 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2525 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2526 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2527
2528 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2529 &command_pool_one);
2530
2531 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2532 &command_pool_two);
2533
2534 VkCommandBuffer command_buffer[9];
2535 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2536 command_buffer_allocate_info.sType =
2537 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2538 command_buffer_allocate_info.commandPool = command_pool_one;
2539 command_buffer_allocate_info.commandBufferCount = 9;
2540 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2541 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2542 command_buffer);
2543
2544 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2545 &command_buffer[3]);
2546
2547 m_errorMonitor->VerifyFound();
2548
2549 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2550 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2551}
2552
2553TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2554 VkResult err;
2555
2556 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2557 "attempt to delete them from another.");
2558
2559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2560 "FreeDescriptorSets is attempting to free descriptorSet");
2561
2562 ASSERT_NO_FATAL_FAILURE(InitState());
2563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2564
2565 VkDescriptorPoolSize ds_type_count = {};
2566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2567 ds_type_count.descriptorCount = 1;
2568
2569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2571 ds_pool_ci.pNext = NULL;
2572 ds_pool_ci.flags = 0;
2573 ds_pool_ci.maxSets = 1;
2574 ds_pool_ci.poolSizeCount = 1;
2575 ds_pool_ci.pPoolSizes = &ds_type_count;
2576
2577 VkDescriptorPool ds_pool_one;
2578 err =
2579 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2580 ASSERT_VK_SUCCESS(err);
2581
2582 // Create a second descriptor pool
2583 VkDescriptorPool ds_pool_two;
2584 err =
2585 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2586 ASSERT_VK_SUCCESS(err);
2587
2588 VkDescriptorSetLayoutBinding dsl_binding = {};
2589 dsl_binding.binding = 0;
2590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2591 dsl_binding.descriptorCount = 1;
2592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2593 dsl_binding.pImmutableSamplers = NULL;
2594
2595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2597 ds_layout_ci.pNext = NULL;
2598 ds_layout_ci.bindingCount = 1;
2599 ds_layout_ci.pBindings = &dsl_binding;
2600
2601 VkDescriptorSetLayout ds_layout;
2602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2603 &ds_layout);
2604 ASSERT_VK_SUCCESS(err);
2605
2606 VkDescriptorSet descriptorSet;
2607 VkDescriptorSetAllocateInfo alloc_info = {};
2608 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2609 alloc_info.descriptorSetCount = 1;
2610 alloc_info.descriptorPool = ds_pool_one;
2611 alloc_info.pSetLayouts = &ds_layout;
2612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2613 &descriptorSet);
2614 ASSERT_VK_SUCCESS(err);
2615
2616 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2617
2618 m_errorMonitor->VerifyFound();
2619
2620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2621 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2622 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2623}
2624
2625TEST_F(VkLayerTest, CreateUnknownObject) {
2626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2627 "Invalid VkImage Object ");
2628
2629 TEST_DESCRIPTION(
2630 "Pass an invalid image object handle into a Vulkan API call.");
2631
2632 ASSERT_NO_FATAL_FAILURE(InitState());
2633
2634 // Pass bogus handle into GetImageMemoryRequirements
2635 VkMemoryRequirements mem_reqs;
2636 uint64_t fakeImageHandle = 0xCADECADE;
2637 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2638
2639 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2640
2641 m_errorMonitor->VerifyFound();
2642}
2643
Karl Schultz6addd812016-02-02 17:17:23 -07002644TEST_F(VkLayerTest, PipelineNotBound) {
2645 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002646
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002647 TEST_DESCRIPTION(
2648 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2649
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002651 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002655
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2658 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002659
2660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2662 ds_pool_ci.pNext = NULL;
2663 ds_pool_ci.maxSets = 1;
2664 ds_pool_ci.poolSizeCount = 1;
2665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002666
2667 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002668 err =
2669 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002670 ASSERT_VK_SUCCESS(err);
2671
2672 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002673 dsl_binding.binding = 0;
2674 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2675 dsl_binding.descriptorCount = 1;
2676 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2677 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002678
2679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2681 ds_layout_ci.pNext = NULL;
2682 ds_layout_ci.bindingCount = 1;
2683 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002684
2685 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2687 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002688 ASSERT_VK_SUCCESS(err);
2689
2690 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002691 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002693 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002694 alloc_info.descriptorPool = ds_pool;
2695 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002696 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2697 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002701 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2702 pipeline_layout_ci.pNext = NULL;
2703 pipeline_layout_ci.setLayoutCount = 1;
2704 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002705
2706 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2708 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002709 ASSERT_VK_SUCCESS(err);
2710
Mark Youngad779052016-01-06 14:26:04 -07002711 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712
2713 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2715 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002717 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002718
Chia-I Wuf7458c52015-10-26 21:10:41 +08002719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002722}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002723#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002724TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2725 VkResult err;
2726
2727 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2728 "during bind[Buffer|Image]Memory time");
2729
2730 m_errorMonitor->SetDesiredFailureMsg(
2731 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2732 "for this object type are not compatible with the memory");
2733
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // Create an image, allocate memory, set a bad typeIndex and then try to
2737 // bind it
2738 VkImage image;
2739 VkDeviceMemory mem;
2740 VkMemoryRequirements mem_reqs;
2741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
2744
2745 VkImageCreateInfo image_create_info = {};
2746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
2759
2760 VkMemoryAllocateInfo mem_alloc = {};
2761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
2765
2766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2767 ASSERT_VK_SUCCESS(err);
2768
2769 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2770 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002771 // TODO : This is not an ideal way to cause the error and triggers a segF
2772 // on at least one android driver when attempting to Allocate the memory.
2773 // That segF may or may not be a driver bug, but really what we want to do
2774 // here is find a device-supported memory type that is also not supported
2775 // for the particular image we're binding the memory too. If no such
2776 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002777 // Introduce Failure, select likely invalid TypeIndex
2778 mem_alloc.memoryTypeIndex = 31;
2779
2780 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2781 ASSERT_VK_SUCCESS(err);
2782
2783 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2784 (void)err;
2785
2786 m_errorMonitor->VerifyFound();
2787
2788 vkDestroyImage(m_device->device(), image, NULL);
2789 vkFreeMemory(m_device->device(), mem, NULL);
2790}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002791#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002792TEST_F(VkLayerTest, BindInvalidMemory) {
2793 VkResult err;
2794 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002795
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002797 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002798
Tobin Ehlisec598302015-09-15 15:02:17 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002800
2801 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002802 VkImage image;
2803 VkDeviceMemory mem;
2804 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002805
Karl Schultz6addd812016-02-02 17:17:23 -07002806 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2807 const int32_t tex_width = 32;
2808 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002809
2810 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002811 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2812 image_create_info.pNext = NULL;
2813 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2814 image_create_info.format = tex_format;
2815 image_create_info.extent.width = tex_width;
2816 image_create_info.extent.height = tex_height;
2817 image_create_info.extent.depth = 1;
2818 image_create_info.mipLevels = 1;
2819 image_create_info.arrayLayers = 1;
2820 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2821 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2822 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2823 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002824
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002825 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002826 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2827 mem_alloc.pNext = NULL;
2828 mem_alloc.allocationSize = 0;
2829 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002830
Chia-I Wuf7458c52015-10-26 21:10:41 +08002831 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002832 ASSERT_VK_SUCCESS(err);
2833
Karl Schultz6addd812016-02-02 17:17:23 -07002834 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002835
2836 mem_alloc.allocationSize = mem_reqs.size;
2837
Karl Schultz6addd812016-02-02 17:17:23 -07002838 pass =
2839 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002840 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002841
2842 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002843 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002844 ASSERT_VK_SUCCESS(err);
2845
2846 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002847 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002848
2849 // Try to bind free memory that has been freed
2850 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2851 // This may very well return an error.
2852 (void)err;
2853
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002854 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002855
Chia-I Wuf7458c52015-10-26 21:10:41 +08002856 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002857}
2858
Karl Schultz6addd812016-02-02 17:17:23 -07002859TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2860 VkResult err;
2861 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002862
Karl Schultz6addd812016-02-02 17:17:23 -07002863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2864 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002865
Tobin Ehlisec598302015-09-15 15:02:17 -06002866 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002867
Karl Schultz6addd812016-02-02 17:17:23 -07002868 // Create an image object, allocate memory, destroy the object and then try
2869 // to bind it
2870 VkImage image;
2871 VkDeviceMemory mem;
2872 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002873
Karl Schultz6addd812016-02-02 17:17:23 -07002874 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2875 const int32_t tex_width = 32;
2876 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002877
2878 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002879 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2880 image_create_info.pNext = NULL;
2881 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2882 image_create_info.format = tex_format;
2883 image_create_info.extent.width = tex_width;
2884 image_create_info.extent.height = tex_height;
2885 image_create_info.extent.depth = 1;
2886 image_create_info.mipLevels = 1;
2887 image_create_info.arrayLayers = 1;
2888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2889 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2890 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2891 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002892
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002893 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002894 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2895 mem_alloc.pNext = NULL;
2896 mem_alloc.allocationSize = 0;
2897 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002898
Chia-I Wuf7458c52015-10-26 21:10:41 +08002899 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002900 ASSERT_VK_SUCCESS(err);
2901
Karl Schultz6addd812016-02-02 17:17:23 -07002902 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002903
2904 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002905 pass =
2906 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002907 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002908
2909 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002910 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002911 ASSERT_VK_SUCCESS(err);
2912
2913 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002914 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002915 ASSERT_VK_SUCCESS(err);
2916
2917 // Now Try to bind memory to this destroyed object
2918 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2919 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002920 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002922 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002923
Chia-I Wuf7458c52015-10-26 21:10:41 +08002924 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002925}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002926
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002927#endif // OBJ_TRACKER_TESTS
2928
Tobin Ehlis0788f522015-05-26 16:11:58 -06002929#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002930
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002931// This is a positive test. No errors are expected.
2932TEST_F(VkLayerTest, StencilLoadOp) {
2933 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2934 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2935 VkResult result = VK_SUCCESS;
2936 VkImageFormatProperties formatProps;
2937 vkGetPhysicalDeviceImageFormatProperties(
2938 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2939 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2940 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2941 0, &formatProps);
2942 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2943 return;
2944 }
2945
2946 ASSERT_NO_FATAL_FAILURE(InitState());
2947 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2948 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2949 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2950 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2951 VkAttachmentDescription att = {};
2952 VkAttachmentReference ref = {};
2953 att.format = depth_stencil_fmt;
2954 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2955 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2956 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2957 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2958 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2959 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2960
2961 VkClearValue clear;
2962 clear.depthStencil.depth = 1.0;
2963 clear.depthStencil.stencil = 0;
2964 ref.attachment = 0;
2965 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2966
2967 VkSubpassDescription subpass = {};
2968 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
2969 subpass.flags = 0;
2970 subpass.inputAttachmentCount = 0;
2971 subpass.pInputAttachments = NULL;
2972 subpass.colorAttachmentCount = 0;
2973 subpass.pColorAttachments = NULL;
2974 subpass.pResolveAttachments = NULL;
2975 subpass.pDepthStencilAttachment = &ref;
2976 subpass.preserveAttachmentCount = 0;
2977 subpass.pPreserveAttachments = NULL;
2978
2979 VkRenderPass rp;
2980 VkRenderPassCreateInfo rp_info = {};
2981 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2982 rp_info.attachmentCount = 1;
2983 rp_info.pAttachments = &att;
2984 rp_info.subpassCount = 1;
2985 rp_info.pSubpasses = &subpass;
2986 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
2987 ASSERT_VK_SUCCESS(result);
2988
2989 VkImageView *depthView = m_depthStencil->BindInfo();
2990 VkFramebufferCreateInfo fb_info = {};
2991 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
2992 fb_info.pNext = NULL;
2993 fb_info.renderPass = rp;
2994 fb_info.attachmentCount = 1;
2995 fb_info.pAttachments = depthView;
2996 fb_info.width = 100;
2997 fb_info.height = 100;
2998 fb_info.layers = 1;
2999 VkFramebuffer fb;
3000 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3001 ASSERT_VK_SUCCESS(result);
3002
3003
3004 VkRenderPassBeginInfo rpbinfo = {};
3005 rpbinfo.clearValueCount = 1;
3006 rpbinfo.pClearValues = &clear;
3007 rpbinfo.pNext = NULL;
3008 rpbinfo.renderPass = rp;
3009 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3010 rpbinfo.renderArea.extent.width = 100;
3011 rpbinfo.renderArea.extent.height = 100;
3012 rpbinfo.renderArea.offset.x = 0;
3013 rpbinfo.renderArea.offset.y = 0;
3014 rpbinfo.framebuffer = fb;
3015
3016 VkFence fence = {};
3017 VkFenceCreateInfo fence_ci = {};
3018 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3019 fence_ci.pNext = nullptr;
3020 fence_ci.flags = 0;
3021 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3022 ASSERT_VK_SUCCESS(result);
3023
3024
3025 m_commandBuffer->BeginCommandBuffer();
3026 m_commandBuffer->BeginRenderPass(rpbinfo);
3027 m_commandBuffer->EndRenderPass();
3028 m_commandBuffer->EndCommandBuffer();
3029 m_commandBuffer->QueueCommandBuffer(fence);
3030
3031 VkImageObj destImage(m_device);
3032 destImage.init(100, 100, depth_stencil_fmt,
3033 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3034 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3035 VK_IMAGE_TILING_OPTIMAL, 0);
3036 VkImageMemoryBarrier barrier = {};
3037 VkImageSubresourceRange range;
3038 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3039 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3040 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3041 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3042 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3043 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3044 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3045 barrier.image = m_depthStencil->handle();
3046 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3047 range.baseMipLevel = 0;
3048 range.levelCount = 1;
3049 range.baseArrayLayer = 0;
3050 range.layerCount = 1;
3051 barrier.subresourceRange = range;
3052 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3053 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3054 cmdbuf.BeginCommandBuffer();
3055 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3056 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3057 nullptr, 1, &barrier);
3058 barrier.srcAccessMask = 0;
3059 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3060 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3061 barrier.image = destImage.handle();
3062 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3063 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3064 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3065 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3066 nullptr, 1, &barrier);
3067 VkImageCopy cregion;
3068 cregion.srcSubresource.aspectMask =
3069 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3070 cregion.srcSubresource.mipLevel = 0;
3071 cregion.srcSubresource.baseArrayLayer = 0;
3072 cregion.srcSubresource.layerCount = 1;
3073 cregion.srcOffset.x = 0;
3074 cregion.srcOffset.y = 0;
3075 cregion.srcOffset.z = 0;
3076 cregion.dstSubresource.aspectMask =
3077 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3078 cregion.dstSubresource.mipLevel = 0;
3079 cregion.dstSubresource.baseArrayLayer = 0;
3080 cregion.dstSubresource.layerCount = 1;
3081 cregion.dstOffset.x = 0;
3082 cregion.dstOffset.y = 0;
3083 cregion.dstOffset.z = 0;
3084 cregion.extent.width = 100;
3085 cregion.extent.height = 100;
3086 cregion.extent.depth = 1;
3087 cmdbuf.CopyImage(m_depthStencil->handle(),
3088 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3089 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3090 cmdbuf.EndCommandBuffer();
3091
3092 VkSubmitInfo submit_info;
3093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3094 submit_info.pNext = NULL;
3095 submit_info.waitSemaphoreCount = 0;
3096 submit_info.pWaitSemaphores = NULL;
3097 submit_info.pWaitDstStageMask = NULL;
3098 submit_info.commandBufferCount = 1;
3099 submit_info.pCommandBuffers = &cmdbuf.handle();
3100 submit_info.signalSemaphoreCount = 0;
3101 submit_info.pSignalSemaphores = NULL;
3102
3103 m_errorMonitor->ExpectSuccess();
3104 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3105 m_errorMonitor->VerifyNotFound();
3106
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003107 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003108 vkDestroyFence(m_device->device(), fence, nullptr);
3109 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3110 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3111}
3112
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003113TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3114 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3115 "attachment reference of VK_ATTACHMENT_UNUSED");
3116
3117 ASSERT_NO_FATAL_FAILURE(InitState());
3118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3119
3120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3121 "must not be VK_ATTACHMENT_UNUSED");
3122
3123 VkAttachmentReference color_attach = {};
3124 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3125 color_attach.attachment = 0;
3126 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3127 VkSubpassDescription subpass = {};
3128 subpass.colorAttachmentCount = 1;
3129 subpass.pColorAttachments = &color_attach;
3130 subpass.preserveAttachmentCount = 1;
3131 subpass.pPreserveAttachments = &preserve_attachment;
3132
3133 VkRenderPassCreateInfo rpci = {};
3134 rpci.subpassCount = 1;
3135 rpci.pSubpasses = &subpass;
3136 rpci.attachmentCount = 1;
3137 VkAttachmentDescription attach_desc = {};
3138 attach_desc.format = VK_FORMAT_UNDEFINED;
3139 rpci.pAttachments = &attach_desc;
3140 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3141 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003142 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003143
3144 m_errorMonitor->VerifyFound();
3145
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003146 if (result == VK_SUCCESS) {
3147 vkDestroyRenderPass(m_device->device(), rp, NULL);
3148 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003149}
3150
3151TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3152 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3153 "in the depthStencil attachment point");
3154
3155 ASSERT_NO_FATAL_FAILURE(InitState());
3156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3157
3158 m_errorMonitor->SetDesiredFailureMsg(
3159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3160 "conflicts with the image's IMAGE_USAGE flags");
3161
3162 // Create a renderPass with a depth-stencil attachment created with
3163 // IMAGE_USAGE_COLOR_ATTACHMENT
3164 VkAttachmentReference attach = {};
3165 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3166 VkSubpassDescription subpass = {};
3167 // Add our color attachment to pDepthStencilAttachment
3168 subpass.pDepthStencilAttachment = &attach;
3169 VkRenderPassCreateInfo rpci = {};
3170 rpci.subpassCount = 1;
3171 rpci.pSubpasses = &subpass;
3172 rpci.attachmentCount = 1;
3173 VkAttachmentDescription attach_desc = {};
3174 attach_desc.format = VK_FORMAT_UNDEFINED;
3175 rpci.pAttachments = &attach_desc;
3176 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3177 VkRenderPass rp;
3178 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3179 ASSERT_VK_SUCCESS(err);
3180
3181 VkImageView imageView =
3182 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3183 VkFramebufferCreateInfo fb_info = {};
3184 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3185 fb_info.pNext = NULL;
3186 fb_info.renderPass = rp;
3187 fb_info.attachmentCount = 1;
3188 fb_info.pAttachments = &imageView;
3189 fb_info.width = 100;
3190 fb_info.height = 100;
3191 fb_info.layers = 1;
3192
3193 VkFramebuffer fb;
3194 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3195
3196 m_errorMonitor->VerifyFound();
3197
3198 if (err == VK_SUCCESS) {
3199 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3200 }
3201 vkDestroyRenderPass(m_device->device(), rp, NULL);
3202}
3203
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003204// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003205TEST_F(VkLayerTest, WaitEventThenSet) {
3206 TEST_DESCRIPTION(
3207 "Wait on a event then set it after the wait has been submitted.");
3208
Michael Lentine860b0fe2016-05-20 10:14:00 -05003209 m_errorMonitor->ExpectSuccess();
3210
3211 VkEvent event;
3212 VkEventCreateInfo event_create_info{};
3213 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3214 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3215
3216 VkCommandPool command_pool;
3217 VkCommandPoolCreateInfo pool_create_info{};
3218 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3219 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3220 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3221 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3222 &command_pool);
3223
3224 VkCommandBuffer command_buffer;
3225 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3226 command_buffer_allocate_info.sType =
3227 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3228 command_buffer_allocate_info.commandPool = command_pool;
3229 command_buffer_allocate_info.commandBufferCount = 1;
3230 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3231 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3232 &command_buffer);
3233
3234 VkQueue queue = VK_NULL_HANDLE;
3235 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003236 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003237
3238 {
3239 VkCommandBufferBeginInfo begin_info{};
3240 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3241 vkBeginCommandBuffer(command_buffer, &begin_info);
3242
3243 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3244 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3245 nullptr, 0, nullptr);
3246 vkCmdResetEvent(command_buffer, event,
3247 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3248 vkEndCommandBuffer(command_buffer);
3249 }
3250 {
3251 VkSubmitInfo submit_info{};
3252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3253 submit_info.commandBufferCount = 1;
3254 submit_info.pCommandBuffers = &command_buffer;
3255 submit_info.signalSemaphoreCount = 0;
3256 submit_info.pSignalSemaphores = nullptr;
3257 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3258 }
3259 { vkSetEvent(m_device->device(), event); }
3260
3261 vkQueueWaitIdle(queue);
3262
3263 vkDestroyEvent(m_device->device(), event, nullptr);
3264 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3265 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3266
3267 m_errorMonitor->VerifyNotFound();
3268}
Michael Lentine5627e692016-05-20 17:45:02 -05003269// This is a positive test. No errors should be generated.
3270TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3271 TEST_DESCRIPTION(
3272 "Issue a query and copy from it on a second command buffer.");
3273
3274 if ((m_device->queue_props.empty()) ||
3275 (m_device->queue_props[0].queueCount < 2))
3276 return;
3277
3278 m_errorMonitor->ExpectSuccess();
3279
3280 VkQueryPool query_pool;
3281 VkQueryPoolCreateInfo query_pool_create_info{};
3282 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3283 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3284 query_pool_create_info.queryCount = 1;
3285 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3286 &query_pool);
3287
3288 VkCommandPool command_pool;
3289 VkCommandPoolCreateInfo pool_create_info{};
3290 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3291 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3292 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3293 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3294 &command_pool);
3295
3296 VkCommandBuffer command_buffer[2];
3297 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3298 command_buffer_allocate_info.sType =
3299 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3300 command_buffer_allocate_info.commandPool = command_pool;
3301 command_buffer_allocate_info.commandBufferCount = 2;
3302 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3303 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3304 command_buffer);
3305
3306 VkQueue queue = VK_NULL_HANDLE;
3307 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3308 1, &queue);
3309
3310 uint32_t qfi = 0;
3311 VkBufferCreateInfo buff_create_info = {};
3312 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3313 buff_create_info.size = 1024;
3314 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3315 buff_create_info.queueFamilyIndexCount = 1;
3316 buff_create_info.pQueueFamilyIndices = &qfi;
3317
3318 VkResult err;
3319 VkBuffer buffer;
3320 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3321 ASSERT_VK_SUCCESS(err);
3322 VkMemoryAllocateInfo mem_alloc = {};
3323 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3324 mem_alloc.pNext = NULL;
3325 mem_alloc.allocationSize = 1024;
3326 mem_alloc.memoryTypeIndex = 0;
3327
3328 VkMemoryRequirements memReqs;
3329 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3330 bool pass =
3331 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3332 if (!pass) {
3333 vkDestroyBuffer(m_device->device(), buffer, NULL);
3334 return;
3335 }
3336
3337 VkDeviceMemory mem;
3338 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3339 ASSERT_VK_SUCCESS(err);
3340 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3341 ASSERT_VK_SUCCESS(err);
3342
3343 {
3344 VkCommandBufferBeginInfo begin_info{};
3345 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3346 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3347
3348 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3349 vkCmdWriteTimestamp(command_buffer[0],
3350 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3351
3352 vkEndCommandBuffer(command_buffer[0]);
3353
3354 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3355
3356 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3357 0, 0, 0);
3358
3359 vkEndCommandBuffer(command_buffer[1]);
3360 }
3361 {
3362 VkSubmitInfo submit_info{};
3363 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3364 submit_info.commandBufferCount = 2;
3365 submit_info.pCommandBuffers = command_buffer;
3366 submit_info.signalSemaphoreCount = 0;
3367 submit_info.pSignalSemaphores = nullptr;
3368 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3369 }
3370
3371 vkQueueWaitIdle(queue);
3372
3373 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3374 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3375 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003376 vkDestroyBuffer(m_device->device(), buffer, NULL);
3377 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003378
3379 m_errorMonitor->VerifyNotFound();
3380}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003381
3382TEST_F(VkLayerTest, ResetEventThenSet) {
3383 TEST_DESCRIPTION(
3384 "Reset an event then set it after the reset has been submitted.");
3385
Michael Lentine860b0fe2016-05-20 10:14:00 -05003386 m_errorMonitor->ExpectSuccess();
3387
3388 VkEvent event;
3389 VkEventCreateInfo event_create_info{};
3390 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3391 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3392
3393 VkCommandPool command_pool;
3394 VkCommandPoolCreateInfo pool_create_info{};
3395 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3396 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3397 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3398 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3399 &command_pool);
3400
3401 VkCommandBuffer command_buffer;
3402 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3403 command_buffer_allocate_info.sType =
3404 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3405 command_buffer_allocate_info.commandPool = command_pool;
3406 command_buffer_allocate_info.commandBufferCount = 1;
3407 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3408 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3409 &command_buffer);
3410
3411 VkQueue queue = VK_NULL_HANDLE;
3412 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003413 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003414
3415 {
3416 VkCommandBufferBeginInfo begin_info{};
3417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3418 vkBeginCommandBuffer(command_buffer, &begin_info);
3419
3420 vkCmdResetEvent(command_buffer, event,
3421 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3422 vkCmdWaitEvents(command_buffer, 1, &event,
3423 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3424 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3425 nullptr, 0, nullptr);
3426 vkEndCommandBuffer(command_buffer);
3427 }
3428 {
3429 VkSubmitInfo submit_info{};
3430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3431 submit_info.commandBufferCount = 1;
3432 submit_info.pCommandBuffers = &command_buffer;
3433 submit_info.signalSemaphoreCount = 0;
3434 submit_info.pSignalSemaphores = nullptr;
3435 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3436 }
3437 {
3438 m_errorMonitor->SetDesiredFailureMsg(
3439 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3440 "0x1 that is already in use by a "
3441 "command buffer.");
3442 vkSetEvent(m_device->device(), event);
3443 m_errorMonitor->VerifyFound();
3444 }
3445
3446 vkQueueWaitIdle(queue);
3447
3448 vkDestroyEvent(m_device->device(), event, nullptr);
3449 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3450 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3451}
3452
3453// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003454TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3455 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3456 "run through a Submit & WaitForFences cycle 3 times. This "
3457 "previously revealed a bug so running this positive test "
3458 "to prevent a regression.");
3459 m_errorMonitor->ExpectSuccess();
3460
3461 ASSERT_NO_FATAL_FAILURE(InitState());
3462 VkQueue queue = VK_NULL_HANDLE;
3463 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3464 0, &queue);
3465
3466 static const uint32_t NUM_OBJECTS = 2;
3467 static const uint32_t NUM_FRAMES = 3;
3468 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3469 VkFence fences[NUM_OBJECTS] = {};
3470
3471 VkCommandPool cmd_pool;
3472 VkCommandPoolCreateInfo cmd_pool_ci = {};
3473 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3474 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3475 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3476 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3477 nullptr, &cmd_pool);
3478 ASSERT_VK_SUCCESS(err);
3479
3480 VkCommandBufferAllocateInfo cmd_buf_info = {};
3481 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3482 cmd_buf_info.commandPool = cmd_pool;
3483 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3484 cmd_buf_info.commandBufferCount = 1;
3485
3486 VkFenceCreateInfo fence_ci = {};
3487 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3488 fence_ci.pNext = nullptr;
3489 fence_ci.flags = 0;
3490
3491 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3492 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3493 &cmd_buffers[i]);
3494 ASSERT_VK_SUCCESS(err);
3495 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3496 ASSERT_VK_SUCCESS(err);
3497 }
3498
3499 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003500 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3501 // Create empty cmd buffer
3502 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3503 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003504
Tobin Ehlisf9025162016-05-26 06:55:21 -06003505 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3506 ASSERT_VK_SUCCESS(err);
3507 err = vkEndCommandBuffer(cmd_buffers[obj]);
3508 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003509
Tobin Ehlisf9025162016-05-26 06:55:21 -06003510 VkSubmitInfo submit_info = {};
3511 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3512 submit_info.commandBufferCount = 1;
3513 submit_info.pCommandBuffers = &cmd_buffers[obj];
3514 // Submit cmd buffer and wait for fence
3515 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3516 ASSERT_VK_SUCCESS(err);
3517 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3518 UINT64_MAX);
3519 ASSERT_VK_SUCCESS(err);
3520 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3521 ASSERT_VK_SUCCESS(err);
3522 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003523 }
3524 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003525 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3526 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3527 vkDestroyFence(m_device->device(), fences[i], nullptr);
3528 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003529}
3530// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003531TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3532
3533 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3534 "submitted on separate queues followed by a QueueWaitIdle.");
3535
Dustin Graves48458142016-04-29 16:11:55 -06003536 if ((m_device->queue_props.empty()) ||
3537 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003538 return;
3539
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003540 m_errorMonitor->ExpectSuccess();
3541
3542 VkSemaphore semaphore;
3543 VkSemaphoreCreateInfo semaphore_create_info{};
3544 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3545 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3546 &semaphore);
3547
3548 VkCommandPool command_pool;
3549 VkCommandPoolCreateInfo pool_create_info{};
3550 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3551 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3552 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3553 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3554 &command_pool);
3555
3556 VkCommandBuffer command_buffer[2];
3557 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3558 command_buffer_allocate_info.sType =
3559 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3560 command_buffer_allocate_info.commandPool = command_pool;
3561 command_buffer_allocate_info.commandBufferCount = 2;
3562 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3563 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3564 command_buffer);
3565
3566 VkQueue queue = VK_NULL_HANDLE;
3567 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3568 1, &queue);
3569
3570 {
3571 VkCommandBufferBeginInfo begin_info{};
3572 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3573 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3574
3575 vkCmdPipelineBarrier(command_buffer[0],
3576 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3577 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3578 0, nullptr, 0, nullptr);
3579
3580 VkViewport viewport{};
3581 viewport.maxDepth = 1.0f;
3582 viewport.minDepth = 0.0f;
3583 viewport.width = 512;
3584 viewport.height = 512;
3585 viewport.x = 0;
3586 viewport.y = 0;
3587 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3588 vkEndCommandBuffer(command_buffer[0]);
3589 }
3590 {
3591 VkCommandBufferBeginInfo begin_info{};
3592 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3593 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3594
3595 VkViewport viewport{};
3596 viewport.maxDepth = 1.0f;
3597 viewport.minDepth = 0.0f;
3598 viewport.width = 512;
3599 viewport.height = 512;
3600 viewport.x = 0;
3601 viewport.y = 0;
3602 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3603 vkEndCommandBuffer(command_buffer[1]);
3604 }
3605 {
3606 VkSubmitInfo submit_info{};
3607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3608 submit_info.commandBufferCount = 1;
3609 submit_info.pCommandBuffers = &command_buffer[0];
3610 submit_info.signalSemaphoreCount = 1;
3611 submit_info.pSignalSemaphores = &semaphore;
3612 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3613 }
3614 {
3615 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3616 VkSubmitInfo submit_info{};
3617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.commandBufferCount = 1;
3619 submit_info.pCommandBuffers = &command_buffer[1];
3620 submit_info.waitSemaphoreCount = 1;
3621 submit_info.pWaitSemaphores = &semaphore;
3622 submit_info.pWaitDstStageMask = flags;
3623 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3624 }
3625
3626 vkQueueWaitIdle(m_device->m_queue);
3627
3628 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3629 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3630 &command_buffer[0]);
3631 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3632
3633 m_errorMonitor->VerifyNotFound();
3634}
3635
3636// This is a positive test. No errors should be generated.
3637TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3638
3639 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3640 "submitted on separate queues, the second having a fence"
3641 "followed by a QueueWaitIdle.");
3642
Dustin Graves48458142016-04-29 16:11:55 -06003643 if ((m_device->queue_props.empty()) ||
3644 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003645 return;
3646
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003647 m_errorMonitor->ExpectSuccess();
3648
3649 VkFence fence;
3650 VkFenceCreateInfo fence_create_info{};
3651 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3652 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3653
3654 VkSemaphore semaphore;
3655 VkSemaphoreCreateInfo semaphore_create_info{};
3656 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3657 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3658 &semaphore);
3659
3660 VkCommandPool command_pool;
3661 VkCommandPoolCreateInfo pool_create_info{};
3662 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3663 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3664 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3665 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3666 &command_pool);
3667
3668 VkCommandBuffer command_buffer[2];
3669 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3670 command_buffer_allocate_info.sType =
3671 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3672 command_buffer_allocate_info.commandPool = command_pool;
3673 command_buffer_allocate_info.commandBufferCount = 2;
3674 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3675 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3676 command_buffer);
3677
3678 VkQueue queue = VK_NULL_HANDLE;
3679 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3680 1, &queue);
3681
3682 {
3683 VkCommandBufferBeginInfo begin_info{};
3684 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3685 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3686
3687 vkCmdPipelineBarrier(command_buffer[0],
3688 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3689 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3690 0, nullptr, 0, nullptr);
3691
3692 VkViewport viewport{};
3693 viewport.maxDepth = 1.0f;
3694 viewport.minDepth = 0.0f;
3695 viewport.width = 512;
3696 viewport.height = 512;
3697 viewport.x = 0;
3698 viewport.y = 0;
3699 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3700 vkEndCommandBuffer(command_buffer[0]);
3701 }
3702 {
3703 VkCommandBufferBeginInfo begin_info{};
3704 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3705 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3706
3707 VkViewport viewport{};
3708 viewport.maxDepth = 1.0f;
3709 viewport.minDepth = 0.0f;
3710 viewport.width = 512;
3711 viewport.height = 512;
3712 viewport.x = 0;
3713 viewport.y = 0;
3714 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3715 vkEndCommandBuffer(command_buffer[1]);
3716 }
3717 {
3718 VkSubmitInfo submit_info{};
3719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3720 submit_info.commandBufferCount = 1;
3721 submit_info.pCommandBuffers = &command_buffer[0];
3722 submit_info.signalSemaphoreCount = 1;
3723 submit_info.pSignalSemaphores = &semaphore;
3724 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3725 }
3726 {
3727 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3728 VkSubmitInfo submit_info{};
3729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3730 submit_info.commandBufferCount = 1;
3731 submit_info.pCommandBuffers = &command_buffer[1];
3732 submit_info.waitSemaphoreCount = 1;
3733 submit_info.pWaitSemaphores = &semaphore;
3734 submit_info.pWaitDstStageMask = flags;
3735 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3736 }
3737
3738 vkQueueWaitIdle(m_device->m_queue);
3739
3740 vkDestroyFence(m_device->device(), fence, nullptr);
3741 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3742 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3743 &command_buffer[0]);
3744 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3745
3746 m_errorMonitor->VerifyNotFound();
3747}
3748
3749// This is a positive test. No errors should be generated.
3750TEST_F(VkLayerTest,
3751 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3752
3753 TEST_DESCRIPTION(
3754 "Two command buffers, each in a separate QueueSubmit call "
3755 "submitted on separate queues, the second having a fence"
3756 "followed by two consecutive WaitForFences calls on the same fence.");
3757
Dustin Graves48458142016-04-29 16:11:55 -06003758 if ((m_device->queue_props.empty()) ||
3759 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003760 return;
3761
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003762 m_errorMonitor->ExpectSuccess();
3763
3764 VkFence fence;
3765 VkFenceCreateInfo fence_create_info{};
3766 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3767 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3768
3769 VkSemaphore semaphore;
3770 VkSemaphoreCreateInfo semaphore_create_info{};
3771 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3772 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3773 &semaphore);
3774
3775 VkCommandPool command_pool;
3776 VkCommandPoolCreateInfo pool_create_info{};
3777 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3778 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3779 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3780 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3781 &command_pool);
3782
3783 VkCommandBuffer command_buffer[2];
3784 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3785 command_buffer_allocate_info.sType =
3786 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3787 command_buffer_allocate_info.commandPool = command_pool;
3788 command_buffer_allocate_info.commandBufferCount = 2;
3789 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3790 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3791 command_buffer);
3792
3793 VkQueue queue = VK_NULL_HANDLE;
3794 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3795 1, &queue);
3796
3797 {
3798 VkCommandBufferBeginInfo begin_info{};
3799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3800 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3801
3802 vkCmdPipelineBarrier(command_buffer[0],
3803 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3804 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3805 0, nullptr, 0, nullptr);
3806
3807 VkViewport viewport{};
3808 viewport.maxDepth = 1.0f;
3809 viewport.minDepth = 0.0f;
3810 viewport.width = 512;
3811 viewport.height = 512;
3812 viewport.x = 0;
3813 viewport.y = 0;
3814 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3815 vkEndCommandBuffer(command_buffer[0]);
3816 }
3817 {
3818 VkCommandBufferBeginInfo begin_info{};
3819 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3821
3822 VkViewport viewport{};
3823 viewport.maxDepth = 1.0f;
3824 viewport.minDepth = 0.0f;
3825 viewport.width = 512;
3826 viewport.height = 512;
3827 viewport.x = 0;
3828 viewport.y = 0;
3829 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3830 vkEndCommandBuffer(command_buffer[1]);
3831 }
3832 {
3833 VkSubmitInfo submit_info{};
3834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3835 submit_info.commandBufferCount = 1;
3836 submit_info.pCommandBuffers = &command_buffer[0];
3837 submit_info.signalSemaphoreCount = 1;
3838 submit_info.pSignalSemaphores = &semaphore;
3839 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3840 }
3841 {
3842 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3843 VkSubmitInfo submit_info{};
3844 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3845 submit_info.commandBufferCount = 1;
3846 submit_info.pCommandBuffers = &command_buffer[1];
3847 submit_info.waitSemaphoreCount = 1;
3848 submit_info.pWaitSemaphores = &semaphore;
3849 submit_info.pWaitDstStageMask = flags;
3850 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3851 }
3852
3853 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3854 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3855
3856 vkDestroyFence(m_device->device(), fence, nullptr);
3857 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3858 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3859 &command_buffer[0]);
3860 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3861
3862 m_errorMonitor->VerifyNotFound();
3863}
3864
3865// This is a positive test. No errors should be generated.
3866TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3867
3868 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3869 "submitted on separate queues, the second having a fence, "
3870 "followed by a WaitForFences call.");
3871
Dustin Graves48458142016-04-29 16:11:55 -06003872 if ((m_device->queue_props.empty()) ||
3873 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003874 return;
3875
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003876 m_errorMonitor->ExpectSuccess();
3877
3878 VkFence fence;
3879 VkFenceCreateInfo fence_create_info{};
3880 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3881 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3882
3883 VkSemaphore semaphore;
3884 VkSemaphoreCreateInfo semaphore_create_info{};
3885 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3886 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3887 &semaphore);
3888
3889 VkCommandPool command_pool;
3890 VkCommandPoolCreateInfo pool_create_info{};
3891 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3892 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3893 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3894 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3895 &command_pool);
3896
3897 VkCommandBuffer command_buffer[2];
3898 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3899 command_buffer_allocate_info.sType =
3900 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3901 command_buffer_allocate_info.commandPool = command_pool;
3902 command_buffer_allocate_info.commandBufferCount = 2;
3903 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3904 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3905 command_buffer);
3906
3907 VkQueue queue = VK_NULL_HANDLE;
3908 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3909 1, &queue);
3910
3911
3912 {
3913 VkCommandBufferBeginInfo begin_info{};
3914 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3915 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3916
3917 vkCmdPipelineBarrier(command_buffer[0],
3918 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3919 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3920 0, nullptr, 0, nullptr);
3921
3922 VkViewport viewport{};
3923 viewport.maxDepth = 1.0f;
3924 viewport.minDepth = 0.0f;
3925 viewport.width = 512;
3926 viewport.height = 512;
3927 viewport.x = 0;
3928 viewport.y = 0;
3929 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3930 vkEndCommandBuffer(command_buffer[0]);
3931 }
3932 {
3933 VkCommandBufferBeginInfo begin_info{};
3934 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3935 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3936
3937 VkViewport viewport{};
3938 viewport.maxDepth = 1.0f;
3939 viewport.minDepth = 0.0f;
3940 viewport.width = 512;
3941 viewport.height = 512;
3942 viewport.x = 0;
3943 viewport.y = 0;
3944 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3945 vkEndCommandBuffer(command_buffer[1]);
3946 }
3947 {
3948 VkSubmitInfo submit_info{};
3949 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3950 submit_info.commandBufferCount = 1;
3951 submit_info.pCommandBuffers = &command_buffer[0];
3952 submit_info.signalSemaphoreCount = 1;
3953 submit_info.pSignalSemaphores = &semaphore;
3954 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3955 }
3956 {
3957 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3958 VkSubmitInfo submit_info{};
3959 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3960 submit_info.commandBufferCount = 1;
3961 submit_info.pCommandBuffers = &command_buffer[1];
3962 submit_info.waitSemaphoreCount = 1;
3963 submit_info.pWaitSemaphores = &semaphore;
3964 submit_info.pWaitDstStageMask = flags;
3965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3966 }
3967
3968 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3969
3970 vkDestroyFence(m_device->device(), fence, nullptr);
3971 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3972 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3973 &command_buffer[0]);
3974 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3975
3976 m_errorMonitor->VerifyNotFound();
3977}
3978
3979// This is a positive test. No errors should be generated.
3980TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3981
3982 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3983 "on the same queue, sharing a signal/wait semaphore, the "
3984 "second having a fence, "
3985 "followed by a WaitForFences call.");
3986
3987 m_errorMonitor->ExpectSuccess();
3988
3989 VkFence fence;
3990 VkFenceCreateInfo fence_create_info{};
3991 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3992 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3993
3994 VkSemaphore semaphore;
3995 VkSemaphoreCreateInfo semaphore_create_info{};
3996 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3997 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3998 &semaphore);
3999
4000 VkCommandPool command_pool;
4001 VkCommandPoolCreateInfo pool_create_info{};
4002 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4003 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4004 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4005 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4006 &command_pool);
4007
4008 VkCommandBuffer command_buffer[2];
4009 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4010 command_buffer_allocate_info.sType =
4011 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4012 command_buffer_allocate_info.commandPool = command_pool;
4013 command_buffer_allocate_info.commandBufferCount = 2;
4014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4015 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4016 command_buffer);
4017
4018 {
4019 VkCommandBufferBeginInfo begin_info{};
4020 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4021 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4022
4023 vkCmdPipelineBarrier(command_buffer[0],
4024 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4025 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4026 0, nullptr, 0, nullptr);
4027
4028 VkViewport viewport{};
4029 viewport.maxDepth = 1.0f;
4030 viewport.minDepth = 0.0f;
4031 viewport.width = 512;
4032 viewport.height = 512;
4033 viewport.x = 0;
4034 viewport.y = 0;
4035 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4036 vkEndCommandBuffer(command_buffer[0]);
4037 }
4038 {
4039 VkCommandBufferBeginInfo begin_info{};
4040 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4041 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4042
4043 VkViewport viewport{};
4044 viewport.maxDepth = 1.0f;
4045 viewport.minDepth = 0.0f;
4046 viewport.width = 512;
4047 viewport.height = 512;
4048 viewport.x = 0;
4049 viewport.y = 0;
4050 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4051 vkEndCommandBuffer(command_buffer[1]);
4052 }
4053 {
4054 VkSubmitInfo submit_info{};
4055 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4056 submit_info.commandBufferCount = 1;
4057 submit_info.pCommandBuffers = &command_buffer[0];
4058 submit_info.signalSemaphoreCount = 1;
4059 submit_info.pSignalSemaphores = &semaphore;
4060 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4061 }
4062 {
4063 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4064 VkSubmitInfo submit_info{};
4065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4066 submit_info.commandBufferCount = 1;
4067 submit_info.pCommandBuffers = &command_buffer[1];
4068 submit_info.waitSemaphoreCount = 1;
4069 submit_info.pWaitSemaphores = &semaphore;
4070 submit_info.pWaitDstStageMask = flags;
4071 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4072 }
4073
4074 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4075
4076 vkDestroyFence(m_device->device(), fence, nullptr);
4077 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4078 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4079 &command_buffer[0]);
4080 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4081
4082 m_errorMonitor->VerifyNotFound();
4083}
4084
4085// This is a positive test. No errors should be generated.
4086TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4087
4088 TEST_DESCRIPTION(
4089 "Two command buffers, each in a separate QueueSubmit call "
4090 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4091 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4092
4093 m_errorMonitor->ExpectSuccess();
4094
4095 VkFence fence;
4096 VkFenceCreateInfo fence_create_info{};
4097 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4098 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4099
4100 VkCommandPool command_pool;
4101 VkCommandPoolCreateInfo pool_create_info{};
4102 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4103 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4104 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4105 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4106 &command_pool);
4107
4108 VkCommandBuffer command_buffer[2];
4109 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4110 command_buffer_allocate_info.sType =
4111 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4112 command_buffer_allocate_info.commandPool = command_pool;
4113 command_buffer_allocate_info.commandBufferCount = 2;
4114 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4115 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4116 command_buffer);
4117
4118 {
4119 VkCommandBufferBeginInfo begin_info{};
4120 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4121 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4122
4123 vkCmdPipelineBarrier(command_buffer[0],
4124 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4125 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4126 0, nullptr, 0, nullptr);
4127
4128 VkViewport viewport{};
4129 viewport.maxDepth = 1.0f;
4130 viewport.minDepth = 0.0f;
4131 viewport.width = 512;
4132 viewport.height = 512;
4133 viewport.x = 0;
4134 viewport.y = 0;
4135 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4136 vkEndCommandBuffer(command_buffer[0]);
4137 }
4138 {
4139 VkCommandBufferBeginInfo begin_info{};
4140 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4141 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4142
4143 VkViewport viewport{};
4144 viewport.maxDepth = 1.0f;
4145 viewport.minDepth = 0.0f;
4146 viewport.width = 512;
4147 viewport.height = 512;
4148 viewport.x = 0;
4149 viewport.y = 0;
4150 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4151 vkEndCommandBuffer(command_buffer[1]);
4152 }
4153 {
4154 VkSubmitInfo submit_info{};
4155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4156 submit_info.commandBufferCount = 1;
4157 submit_info.pCommandBuffers = &command_buffer[0];
4158 submit_info.signalSemaphoreCount = 0;
4159 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4161 }
4162 {
4163 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4164 VkSubmitInfo submit_info{};
4165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4166 submit_info.commandBufferCount = 1;
4167 submit_info.pCommandBuffers = &command_buffer[1];
4168 submit_info.waitSemaphoreCount = 0;
4169 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4170 submit_info.pWaitDstStageMask = flags;
4171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4172 }
4173
4174 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4175
4176 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4177
4178 vkDestroyFence(m_device->device(), fence, nullptr);
4179 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4180 &command_buffer[0]);
4181 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4182
4183 m_errorMonitor->VerifyNotFound();
4184}
4185
4186// This is a positive test. No errors should be generated.
4187TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4188
4189 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4190 "on the same queue, the second having a fence, followed "
4191 "by a WaitForFences call.");
4192
4193 m_errorMonitor->ExpectSuccess();
4194
4195 VkFence fence;
4196 VkFenceCreateInfo fence_create_info{};
4197 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4198 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4199
4200 VkCommandPool command_pool;
4201 VkCommandPoolCreateInfo pool_create_info{};
4202 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4203 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4204 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4205 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4206 &command_pool);
4207
4208 VkCommandBuffer command_buffer[2];
4209 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4210 command_buffer_allocate_info.sType =
4211 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4212 command_buffer_allocate_info.commandPool = command_pool;
4213 command_buffer_allocate_info.commandBufferCount = 2;
4214 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4215 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4216 command_buffer);
4217
4218 {
4219 VkCommandBufferBeginInfo begin_info{};
4220 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4221 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4222
4223 vkCmdPipelineBarrier(command_buffer[0],
4224 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4225 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4226 0, nullptr, 0, nullptr);
4227
4228 VkViewport viewport{};
4229 viewport.maxDepth = 1.0f;
4230 viewport.minDepth = 0.0f;
4231 viewport.width = 512;
4232 viewport.height = 512;
4233 viewport.x = 0;
4234 viewport.y = 0;
4235 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4236 vkEndCommandBuffer(command_buffer[0]);
4237 }
4238 {
4239 VkCommandBufferBeginInfo begin_info{};
4240 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4241 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4242
4243 VkViewport viewport{};
4244 viewport.maxDepth = 1.0f;
4245 viewport.minDepth = 0.0f;
4246 viewport.width = 512;
4247 viewport.height = 512;
4248 viewport.x = 0;
4249 viewport.y = 0;
4250 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4251 vkEndCommandBuffer(command_buffer[1]);
4252 }
4253 {
4254 VkSubmitInfo submit_info{};
4255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4256 submit_info.commandBufferCount = 1;
4257 submit_info.pCommandBuffers = &command_buffer[0];
4258 submit_info.signalSemaphoreCount = 0;
4259 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4261 }
4262 {
4263 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4264 VkSubmitInfo submit_info{};
4265 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4266 submit_info.commandBufferCount = 1;
4267 submit_info.pCommandBuffers = &command_buffer[1];
4268 submit_info.waitSemaphoreCount = 0;
4269 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4270 submit_info.pWaitDstStageMask = flags;
4271 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4272 }
4273
4274 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4275
4276 vkDestroyFence(m_device->device(), fence, nullptr);
4277 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4278 &command_buffer[0]);
4279 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4280
4281 m_errorMonitor->VerifyNotFound();
4282}
4283
4284// This is a positive test. No errors should be generated.
4285TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4286
4287 TEST_DESCRIPTION(
4288 "Two command buffers each in a separate SubmitInfo sent in a single "
4289 "QueueSubmit call followed by a WaitForFences call.");
4290
4291 m_errorMonitor->ExpectSuccess();
4292
4293 VkFence fence;
4294 VkFenceCreateInfo fence_create_info{};
4295 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4296 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4297
4298 VkSemaphore semaphore;
4299 VkSemaphoreCreateInfo semaphore_create_info{};
4300 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4301 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4302 &semaphore);
4303
4304 VkCommandPool command_pool;
4305 VkCommandPoolCreateInfo pool_create_info{};
4306 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4307 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4308 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4309 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4310 &command_pool);
4311
4312 VkCommandBuffer command_buffer[2];
4313 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4314 command_buffer_allocate_info.sType =
4315 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4316 command_buffer_allocate_info.commandPool = command_pool;
4317 command_buffer_allocate_info.commandBufferCount = 2;
4318 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4319 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4320 command_buffer);
4321
4322 {
4323 VkCommandBufferBeginInfo begin_info{};
4324 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4325 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4326
4327 vkCmdPipelineBarrier(command_buffer[0],
4328 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4329 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4330 0, nullptr, 0, nullptr);
4331
4332 VkViewport viewport{};
4333 viewport.maxDepth = 1.0f;
4334 viewport.minDepth = 0.0f;
4335 viewport.width = 512;
4336 viewport.height = 512;
4337 viewport.x = 0;
4338 viewport.y = 0;
4339 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4340 vkEndCommandBuffer(command_buffer[0]);
4341 }
4342 {
4343 VkCommandBufferBeginInfo begin_info{};
4344 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4345 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4346
4347 VkViewport viewport{};
4348 viewport.maxDepth = 1.0f;
4349 viewport.minDepth = 0.0f;
4350 viewport.width = 512;
4351 viewport.height = 512;
4352 viewport.x = 0;
4353 viewport.y = 0;
4354 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4355 vkEndCommandBuffer(command_buffer[1]);
4356 }
4357 {
4358 VkSubmitInfo submit_info[2];
4359 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4360
4361 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4362 submit_info[0].pNext = NULL;
4363 submit_info[0].commandBufferCount = 1;
4364 submit_info[0].pCommandBuffers = &command_buffer[0];
4365 submit_info[0].signalSemaphoreCount = 1;
4366 submit_info[0].pSignalSemaphores = &semaphore;
4367 submit_info[0].waitSemaphoreCount = 0;
4368 submit_info[0].pWaitSemaphores = NULL;
4369 submit_info[0].pWaitDstStageMask = 0;
4370
4371 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4372 submit_info[1].pNext = NULL;
4373 submit_info[1].commandBufferCount = 1;
4374 submit_info[1].pCommandBuffers = &command_buffer[1];
4375 submit_info[1].waitSemaphoreCount = 1;
4376 submit_info[1].pWaitSemaphores = &semaphore;
4377 submit_info[1].pWaitDstStageMask = flags;
4378 submit_info[1].signalSemaphoreCount = 0;
4379 submit_info[1].pSignalSemaphores = NULL;
4380 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4381 }
4382
4383 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4384
4385 vkDestroyFence(m_device->device(), fence, nullptr);
4386 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4387 &command_buffer[0]);
4388 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004389 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004390
4391 m_errorMonitor->VerifyNotFound();
4392}
4393
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004394TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004395 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004396 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4397 "state is required but not correctly bound.");
4398
4399 // Dynamic depth bias
4400 m_errorMonitor->SetDesiredFailureMsg(
4401 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4402 "Dynamic depth bias state not set for this command buffer");
4403 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4404 BsoFailDepthBias);
4405 m_errorMonitor->VerifyFound();
4406}
4407
4408TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4409 TEST_DESCRIPTION(
4410 "Run a simple draw calls to validate failure when Line Width dynamic "
4411 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004412
4413 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004414 m_errorMonitor->SetDesiredFailureMsg(
4415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004416 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004417 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4418 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004419 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004420}
4421
4422TEST_F(VkLayerTest, DynamicViewportNotBound) {
4423 TEST_DESCRIPTION(
4424 "Run a simple draw calls to validate failure when Viewport dynamic "
4425 "state is required but not correctly bound.");
4426
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004427 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004428 m_errorMonitor->SetDesiredFailureMsg(
4429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004430 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004431 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4432 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004433 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004434}
4435
4436TEST_F(VkLayerTest, DynamicScissorNotBound) {
4437 TEST_DESCRIPTION(
4438 "Run a simple draw calls to validate failure when Scissor dynamic "
4439 "state is required but not correctly bound.");
4440
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004441 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004442 m_errorMonitor->SetDesiredFailureMsg(
4443 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004444 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004445 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4446 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004447 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004448}
4449
Tobin Ehlis21c88352016-05-26 06:15:45 -06004450TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004451 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004452 "Run a simple draw calls to validate failure when Blend Constants "
4453 "dynamic state is required but not correctly bound.");
4454 // Dynamic blend constant state
4455 m_errorMonitor->SetDesiredFailureMsg(
4456 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4457 "Dynamic blend constants state not set for this command buffer");
4458 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4459 BsoFailBlend);
4460 m_errorMonitor->VerifyFound();
4461}
4462
4463TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4464 TEST_DESCRIPTION(
4465 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004466 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004467 if (!m_device->phy().features().depthBounds) {
4468 printf("Device does not support depthBounds test; skipped.\n");
4469 return;
4470 }
4471 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004472 m_errorMonitor->SetDesiredFailureMsg(
4473 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004474 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004475 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4476 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004477 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004478}
4479
4480TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4481 TEST_DESCRIPTION(
4482 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4483 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004484 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004485 m_errorMonitor->SetDesiredFailureMsg(
4486 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004487 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4489 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004490 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004491}
4492
4493TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4494 TEST_DESCRIPTION(
4495 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4496 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004497 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004498 m_errorMonitor->SetDesiredFailureMsg(
4499 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004500 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004501 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4502 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004503 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004504}
4505
4506TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4507 TEST_DESCRIPTION(
4508 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4509 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004510 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004511 m_errorMonitor->SetDesiredFailureMsg(
4512 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004513 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004514 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4515 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004516 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004517}
4518
Karl Schultz6addd812016-02-02 17:17:23 -07004519TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004520 m_errorMonitor->SetDesiredFailureMsg(
4521 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4522 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4523 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004524
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004525 ASSERT_NO_FATAL_FAILURE(InitState());
4526 ASSERT_NO_FATAL_FAILURE(InitViewport());
4527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4528
Karl Schultz6addd812016-02-02 17:17:23 -07004529 // We luck out b/c by default the framework creates CB w/ the
4530 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004531 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004532 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4533 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004534 EndCommandBuffer();
4535
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004536 // Bypass framework since it does the waits automatically
4537 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004538 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004539 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4540 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004541 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004542 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004543 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004544 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004545 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004546 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004547 submit_info.pSignalSemaphores = NULL;
4548
Chris Forbes40028e22016-06-13 09:59:34 +12004549 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004551
Karl Schultz6addd812016-02-02 17:17:23 -07004552 // Cause validation error by re-submitting cmd buffer that should only be
4553 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004554 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004555
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004556 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004557}
4558
Karl Schultz6addd812016-02-02 17:17:23 -07004559TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004560 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004561 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004562
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004564 "Unable to allocate 1 descriptors of "
4565 "type "
4566 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004567
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004568 ASSERT_NO_FATAL_FAILURE(InitState());
4569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004570
Karl Schultz6addd812016-02-02 17:17:23 -07004571 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4572 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004573 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004574 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4575 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004576
4577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4579 ds_pool_ci.pNext = NULL;
4580 ds_pool_ci.flags = 0;
4581 ds_pool_ci.maxSets = 1;
4582 ds_pool_ci.poolSizeCount = 1;
4583 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004584
4585 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004586 err =
4587 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004588 ASSERT_VK_SUCCESS(err);
4589
4590 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004591 dsl_binding.binding = 0;
4592 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4593 dsl_binding.descriptorCount = 1;
4594 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4595 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004596
4597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4599 ds_layout_ci.pNext = NULL;
4600 ds_layout_ci.bindingCount = 1;
4601 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004602
4603 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004604 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4605 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004606 ASSERT_VK_SUCCESS(err);
4607
4608 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004609 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004611 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004612 alloc_info.descriptorPool = ds_pool;
4613 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4615 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004616
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004617 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004618
Chia-I Wuf7458c52015-10-26 21:10:41 +08004619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4620 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004621}
4622
Karl Schultz6addd812016-02-02 17:17:23 -07004623TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4624 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004625
Karl Schultz6addd812016-02-02 17:17:23 -07004626 m_errorMonitor->SetDesiredFailureMsg(
4627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4628 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4629 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004630
Tobin Ehlise735c692015-10-08 13:13:50 -06004631 ASSERT_NO_FATAL_FAILURE(InitState());
4632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004633
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004634 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004635 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4636 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004637
4638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4640 ds_pool_ci.pNext = NULL;
4641 ds_pool_ci.maxSets = 1;
4642 ds_pool_ci.poolSizeCount = 1;
4643 ds_pool_ci.flags = 0;
4644 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4645 // app can only call vkResetDescriptorPool on this pool.;
4646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004647
4648 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004649 err =
4650 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004651 ASSERT_VK_SUCCESS(err);
4652
4653 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004654 dsl_binding.binding = 0;
4655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4656 dsl_binding.descriptorCount = 1;
4657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004659
4660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4662 ds_layout_ci.pNext = NULL;
4663 ds_layout_ci.bindingCount = 1;
4664 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004665
4666 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4668 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004669 ASSERT_VK_SUCCESS(err);
4670
4671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004675 alloc_info.descriptorPool = ds_pool;
4676 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4678 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004679 ASSERT_VK_SUCCESS(err);
4680
4681 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004682 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004683
Chia-I Wuf7458c52015-10-26 21:10:41 +08004684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004686}
4687
Karl Schultz6addd812016-02-02 17:17:23 -07004688TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004689 // Attempt to clear Descriptor Pool with bad object.
4690 // ObjectTracker should catch this.
4691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4692 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004693 uint64_t fake_pool_handle = 0xbaad6001;
4694 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4695 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004696 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004697}
4698
Karl Schultz6addd812016-02-02 17:17:23 -07004699TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004700 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4701 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004702 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004703 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004704
4705 uint64_t fake_set_handle = 0xbaad6001;
4706 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004707 VkResult err;
4708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4709 "Invalid VkDescriptorSet Object 0xbaad6001");
4710
4711 ASSERT_NO_FATAL_FAILURE(InitState());
4712
4713 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4714 layout_bindings[0].binding = 0;
4715 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4716 layout_bindings[0].descriptorCount = 1;
4717 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4718 layout_bindings[0].pImmutableSamplers = NULL;
4719
4720 VkDescriptorSetLayout descriptor_set_layout;
4721 VkDescriptorSetLayoutCreateInfo dslci = {};
4722 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4723 dslci.pNext = NULL;
4724 dslci.bindingCount = 1;
4725 dslci.pBindings = layout_bindings;
4726 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004727 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004728
4729 VkPipelineLayout pipeline_layout;
4730 VkPipelineLayoutCreateInfo plci = {};
4731 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4732 plci.pNext = NULL;
4733 plci.setLayoutCount = 1;
4734 plci.pSetLayouts = &descriptor_set_layout;
4735 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004736 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004737
4738 BeginCommandBuffer();
4739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004740 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004741 m_errorMonitor->VerifyFound();
4742 EndCommandBuffer();
4743 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4744 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004745}
4746
Karl Schultz6addd812016-02-02 17:17:23 -07004747TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004748 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4749 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004750 uint64_t fake_layout_handle = 0xbaad6001;
4751 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4753 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4754
4755 VkPipelineLayout pipeline_layout;
4756 VkPipelineLayoutCreateInfo plci = {};
4757 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4758 plci.pNext = NULL;
4759 plci.setLayoutCount = 1;
4760 plci.pSetLayouts = &bad_layout;
4761 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4762
4763 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004764}
4765
Mark Muellerd4914412016-06-13 17:52:06 -06004766TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4767 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4768 "1) A uniform buffer update must have a valid buffer index."
4769 "2) When using an array of descriptors in a single WriteDescriptor,"
4770 " the descriptor types and stageflags must all be the same."
4771 "3) Immutable Sampler state must match across descriptors");
4772
4773 const char *invalid_BufferInfo_ErrorMessage =
4774 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4775 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4776 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4777 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004778 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004779 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004780 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004781
Mark Muellerd4914412016-06-13 17:52:06 -06004782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4783
4784 ASSERT_NO_FATAL_FAILURE(InitState());
4785 VkDescriptorPoolSize ds_type_count[4] = {};
4786 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4787 ds_type_count[0].descriptorCount = 1;
4788 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4789 ds_type_count[1].descriptorCount = 1;
4790 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4791 ds_type_count[2].descriptorCount = 1;
4792 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4793 ds_type_count[3].descriptorCount = 1;
4794
4795 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4796 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4797 ds_pool_ci.maxSets = 1;
4798 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4799 ds_pool_ci.pPoolSizes = ds_type_count;
4800
4801 VkDescriptorPool ds_pool;
4802 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4803 ASSERT_VK_SUCCESS(err);
4804
Mark Muellerb9896722016-06-16 09:54:29 -06004805 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004806 layout_binding[0].binding = 0;
4807 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4808 layout_binding[0].descriptorCount = 1;
4809 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4810 layout_binding[0].pImmutableSamplers = NULL;
4811
4812 layout_binding[1].binding = 1;
4813 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4814 layout_binding[1].descriptorCount = 1;
4815 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4816 layout_binding[1].pImmutableSamplers = NULL;
4817
4818 VkSamplerCreateInfo sampler_ci = {};
4819 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4820 sampler_ci.pNext = NULL;
4821 sampler_ci.magFilter = VK_FILTER_NEAREST;
4822 sampler_ci.minFilter = VK_FILTER_NEAREST;
4823 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4824 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4825 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4826 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4827 sampler_ci.mipLodBias = 1.0;
4828 sampler_ci.anisotropyEnable = VK_FALSE;
4829 sampler_ci.maxAnisotropy = 1;
4830 sampler_ci.compareEnable = VK_FALSE;
4831 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4832 sampler_ci.minLod = 1.0;
4833 sampler_ci.maxLod = 1.0;
4834 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4835 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4836 VkSampler sampler;
4837
4838 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4839 ASSERT_VK_SUCCESS(err);
4840
4841 layout_binding[2].binding = 2;
4842 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4843 layout_binding[2].descriptorCount = 1;
4844 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4845 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4846
Mark Muellerd4914412016-06-13 17:52:06 -06004847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4849 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4850 ds_layout_ci.pBindings = layout_binding;
4851 VkDescriptorSetLayout ds_layout;
4852 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4853 ASSERT_VK_SUCCESS(err);
4854
4855 VkDescriptorSetAllocateInfo alloc_info = {};
4856 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4857 alloc_info.descriptorSetCount = 1;
4858 alloc_info.descriptorPool = ds_pool;
4859 alloc_info.pSetLayouts = &ds_layout;
4860 VkDescriptorSet descriptorSet;
4861 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4862 ASSERT_VK_SUCCESS(err);
4863
4864 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4865 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4866 pipeline_layout_ci.pNext = NULL;
4867 pipeline_layout_ci.setLayoutCount = 1;
4868 pipeline_layout_ci.pSetLayouts = &ds_layout;
4869
4870 VkPipelineLayout pipeline_layout;
4871 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4872 ASSERT_VK_SUCCESS(err);
4873
Mark Mueller5c838ce2016-06-16 09:54:29 -06004874 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4876 descriptor_write.dstSet = descriptorSet;
4877 descriptor_write.dstBinding = 0;
4878 descriptor_write.descriptorCount = 1;
4879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4880
Mark Mueller5c838ce2016-06-16 09:54:29 -06004881 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4883 m_errorMonitor->VerifyFound();
4884
4885 // Create a buffer to update the descriptor with
4886 uint32_t qfi = 0;
4887 VkBufferCreateInfo buffCI = {};
4888 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4889 buffCI.size = 1024;
4890 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4891 buffCI.queueFamilyIndexCount = 1;
4892 buffCI.pQueueFamilyIndices = &qfi;
4893
4894 VkBuffer dyub;
4895 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4896 ASSERT_VK_SUCCESS(err);
4897 VkDescriptorBufferInfo buffInfo = {};
4898 buffInfo.buffer = dyub;
4899 buffInfo.offset = 0;
4900 buffInfo.range = 1024;
4901
4902 descriptor_write.pBufferInfo = &buffInfo;
4903 descriptor_write.descriptorCount = 2;
4904
Mark Mueller5c838ce2016-06-16 09:54:29 -06004905 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4907 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4908 m_errorMonitor->VerifyFound();
4909
Mark Mueller5c838ce2016-06-16 09:54:29 -06004910 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4911 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004912 descriptor_write.dstBinding = 1;
4913 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004914
4915
4916 // Make pImageInfo index non-null to avoid complaints of it missing
4917 VkDescriptorImageInfo imageInfo = {};
4918 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4919 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4922 m_errorMonitor->VerifyFound();
4923
Mark Muellerd4914412016-06-13 17:52:06 -06004924 vkDestroyBuffer(m_device->device(), dyub, NULL);
4925 vkDestroySampler(m_device->device(), sampler, NULL);
4926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4929}
4930
Karl Schultz6addd812016-02-02 17:17:23 -07004931TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004932 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4933 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004934 // Create a valid cmd buffer
4935 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004936 uint64_t fake_pipeline_handle = 0xbaad6001;
4937 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4939 "Invalid VkPipeline Object 0xbaad6001");
4940 ASSERT_NO_FATAL_FAILURE(InitState());
4941 BeginCommandBuffer();
4942 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4943 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4944 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004945 // Now issue a draw call with no pipeline bound
4946 m_errorMonitor->SetDesiredFailureMsg(
4947 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4948 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004949
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004950 BeginCommandBuffer();
4951 Draw(1, 0, 0, 0);
4952 m_errorMonitor->VerifyFound();
4953 // Finally same check once more but with Dispatch/Compute
4954 m_errorMonitor->SetDesiredFailureMsg(
4955 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4956 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004957 BeginCommandBuffer();
4958 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4959 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004960}
4961
Karl Schultz6addd812016-02-02 17:17:23 -07004962TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4963 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4964 // CommandBuffer
4965 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004966
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004968 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004969
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004970 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004971 ASSERT_NO_FATAL_FAILURE(InitViewport());
4972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004973 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4975 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004976
4977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4979 ds_pool_ci.pNext = NULL;
4980 ds_pool_ci.maxSets = 1;
4981 ds_pool_ci.poolSizeCount = 1;
4982 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004983
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004984 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004985 err =
4986 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004987 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004988
Tony Barboureb254902015-07-15 12:50:33 -06004989 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004990 dsl_binding.binding = 0;
4991 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4992 dsl_binding.descriptorCount = 1;
4993 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4994 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004995
Tony Barboureb254902015-07-15 12:50:33 -06004996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4998 ds_layout_ci.pNext = NULL;
4999 ds_layout_ci.bindingCount = 1;
5000 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005001 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5003 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005004 ASSERT_VK_SUCCESS(err);
5005
5006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005010 alloc_info.descriptorPool = ds_pool;
5011 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5013 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005014 ASSERT_VK_SUCCESS(err);
5015
Tony Barboureb254902015-07-15 12:50:33 -06005016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5018 pipeline_layout_ci.pNext = NULL;
5019 pipeline_layout_ci.setLayoutCount = 1;
5020 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005021
5022 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5024 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005025 ASSERT_VK_SUCCESS(err);
5026
Karl Schultz6addd812016-02-02 17:17:23 -07005027 VkShaderObj vs(m_device, bindStateVertShaderText,
5028 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005029 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005030 // on more devices
5031 VkShaderObj fs(m_device, bindStateFragShaderText,
5032 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005033
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005034 VkPipelineObj pipe(m_device);
5035 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005036 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005037 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005039
5040 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005041 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5042 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5043 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5044 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5045 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005046
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005047 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005048
Chia-I Wuf7458c52015-10-26 21:10:41 +08005049 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5050 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5051 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005052}
5053
Karl Schultz6addd812016-02-02 17:17:23 -07005054TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005055 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005056 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005057
Karl Schultz6addd812016-02-02 17:17:23 -07005058 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005059 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5060 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005061
5062 ASSERT_NO_FATAL_FAILURE(InitState());
5063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5065 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005066
5067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5069 ds_pool_ci.pNext = NULL;
5070 ds_pool_ci.maxSets = 1;
5071 ds_pool_ci.poolSizeCount = 1;
5072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005073
5074 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err =
5076 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005080 dsl_binding.binding = 0;
5081 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5082 dsl_binding.descriptorCount = 1;
5083 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5084 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005085
5086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005087 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5088 ds_layout_ci.pNext = NULL;
5089 ds_layout_ci.bindingCount = 1;
5090 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005091 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005092 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5093 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005094 ASSERT_VK_SUCCESS(err);
5095
5096 VkDescriptorSet descriptorSet;
5097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005099 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005100 alloc_info.descriptorPool = ds_pool;
5101 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5103 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005104 ASSERT_VK_SUCCESS(err);
5105
Karl Schultz6addd812016-02-02 17:17:23 -07005106 VkBufferView view =
5107 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005108 VkWriteDescriptorSet descriptor_write;
5109 memset(&descriptor_write, 0, sizeof(descriptor_write));
5110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5111 descriptor_write.dstSet = descriptorSet;
5112 descriptor_write.dstBinding = 0;
5113 descriptor_write.descriptorCount = 1;
5114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5115 descriptor_write.pTexelBufferView = &view;
5116
5117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005119 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005120
5121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5123}
5124
Karl Schultz6addd812016-02-02 17:17:23 -07005125TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5126 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5127 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005128 // 1. No dynamicOffset supplied
5129 // 2. Too many dynamicOffsets supplied
5130 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005131 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005133 " requires 1 dynamicOffsets, but only "
5134 "0 dynamicOffsets are left in "
5135 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005136
5137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitViewport());
5139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5140
5141 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005142 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5143 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005144
5145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5147 ds_pool_ci.pNext = NULL;
5148 ds_pool_ci.maxSets = 1;
5149 ds_pool_ci.poolSizeCount = 1;
5150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005151
5152 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005153 err =
5154 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005155 ASSERT_VK_SUCCESS(err);
5156
5157 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005158 dsl_binding.binding = 0;
5159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5160 dsl_binding.descriptorCount = 1;
5161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5162 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005163
5164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5166 ds_layout_ci.pNext = NULL;
5167 ds_layout_ci.bindingCount = 1;
5168 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005169 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5171 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005172 ASSERT_VK_SUCCESS(err);
5173
5174 VkDescriptorSet descriptorSet;
5175 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005176 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005177 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005178 alloc_info.descriptorPool = ds_pool;
5179 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005180 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5181 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005182 ASSERT_VK_SUCCESS(err);
5183
5184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5186 pipeline_layout_ci.pNext = NULL;
5187 pipeline_layout_ci.setLayoutCount = 1;
5188 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005189
5190 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5192 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005193 ASSERT_VK_SUCCESS(err);
5194
5195 // Create a buffer to update the descriptor with
5196 uint32_t qfi = 0;
5197 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005198 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5199 buffCI.size = 1024;
5200 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5201 buffCI.queueFamilyIndexCount = 1;
5202 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005203
5204 VkBuffer dyub;
5205 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5206 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005207 // Allocate memory and bind to buffer so we can make it to the appropriate
5208 // error
5209 VkMemoryAllocateInfo mem_alloc = {};
5210 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5211 mem_alloc.pNext = NULL;
5212 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005213 mem_alloc.memoryTypeIndex = 0;
5214
5215 VkMemoryRequirements memReqs;
5216 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5217 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5218 0);
5219 if (!pass) {
5220 vkDestroyBuffer(m_device->device(), dyub, NULL);
5221 return;
5222 }
5223
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005224 VkDeviceMemory mem;
5225 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5226 ASSERT_VK_SUCCESS(err);
5227 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5228 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005229 // Correctly update descriptor to avoid "NOT_UPDATED" error
5230 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005231 buffInfo.buffer = dyub;
5232 buffInfo.offset = 0;
5233 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005234
5235 VkWriteDescriptorSet descriptor_write;
5236 memset(&descriptor_write, 0, sizeof(descriptor_write));
5237 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5238 descriptor_write.dstSet = descriptorSet;
5239 descriptor_write.dstBinding = 0;
5240 descriptor_write.descriptorCount = 1;
5241 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5242 descriptor_write.pBufferInfo = &buffInfo;
5243
5244 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5245
5246 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5248 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5249 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005250 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005251 uint32_t pDynOff[2] = {512, 756};
5252 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005253 m_errorMonitor->SetDesiredFailureMsg(
5254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005255 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5257 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5258 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005259 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005260 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5262 " dynamic offset 512 combined with "
5263 "offset 0 and range 1024 that "
5264 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005265 // Create PSO to be used for draw-time errors below
5266 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005267 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005268 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005269 "out gl_PerVertex { \n"
5270 " vec4 gl_Position;\n"
5271 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005272 "void main(){\n"
5273 " gl_Position = vec4(1);\n"
5274 "}\n";
5275 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005276 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005277 "\n"
5278 "layout(location=0) out vec4 x;\n"
5279 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5280 "void main(){\n"
5281 " x = vec4(bar.y);\n"
5282 "}\n";
5283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5285 VkPipelineObj pipe(m_device);
5286 pipe.AddShader(&vs);
5287 pipe.AddShader(&fs);
5288 pipe.AddColorAttachment();
5289 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5290
Karl Schultz6addd812016-02-02 17:17:23 -07005291 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5292 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5293 // This update should succeed, but offset size of 512 will overstep buffer
5294 // /w range 1024 & size 1024
5295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5296 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5297 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005298 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005299 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005300
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005301 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005302 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005303
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005305 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005306 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5307}
5308
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005309TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005310 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005311 ASSERT_NO_FATAL_FAILURE(InitState());
5312 ASSERT_NO_FATAL_FAILURE(InitViewport());
5313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5314
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005315 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005316 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005317 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5318 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5319 pipeline_layout_ci.pushConstantRangeCount = 1;
5320 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5321
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005322 //
5323 // Check for invalid push constant ranges in pipeline layouts.
5324 //
5325 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005326 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005327 char const *msg;
5328 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005329
Karl Schultzc81037d2016-05-12 08:11:23 -06005330 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5331 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5332 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5333 "vkCreatePipelineLayout() call has push constants index 0 with "
5334 "size 0."},
5335 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5336 "vkCreatePipelineLayout() call has push constants index 0 with "
5337 "size 1."},
5338 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5339 "vkCreatePipelineLayout() call has push constants index 0 with "
5340 "size 1."},
5341 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5342 "vkCreatePipelineLayout() call has push constants index 0 with "
5343 "size 0."},
5344 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5345 "vkCreatePipelineLayout() call has push constants index 0 with "
5346 "offset 1. Offset must"},
5347 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5348 "vkCreatePipelineLayout() call has push constants index 0 "
5349 "with offset "},
5350 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5351 "vkCreatePipelineLayout() call has push constants "
5352 "index 0 with offset "},
5353 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5354 "vkCreatePipelineLayout() call has push constants index 0 "
5355 "with offset "},
5356 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5357 "vkCreatePipelineLayout() call has push "
5358 "constants index 0 with offset "},
5359 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5360 "vkCreatePipelineLayout() call has push "
5361 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005362 }};
5363
5364 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005365 for (const auto &iter : range_tests) {
5366 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5368 iter.msg);
5369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5370 NULL, &pipeline_layout);
5371 m_errorMonitor->VerifyFound();
5372 if (VK_SUCCESS == err) {
5373 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5374 }
5375 }
5376
5377 // Check for invalid stage flag
5378 pc_range.offset = 0;
5379 pc_range.size = 16;
5380 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005381 m_errorMonitor->SetDesiredFailureMsg(
5382 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005383 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005384 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5385 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005386 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005387 if (VK_SUCCESS == err) {
5388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5389 }
5390
5391 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005392 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005393 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005394 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005395 char const *msg;
5396 };
5397
Karl Schultzc81037d2016-05-12 08:11:23 -06005398 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005399 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5400 {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 "vkCreatePipelineLayout() call has push constants with overlapping "
5405 "ranges: 0:[0, 4), 1:[0, 4)"},
5406 {
5407 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5408 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5409 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5410 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5411 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5412 "vkCreatePipelineLayout() call has push constants with "
5413 "overlapping "
5414 "ranges: 3:[12, 20), 4:[16, 20)",
5415 },
5416 {
5417 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5418 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5419 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5420 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5421 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5422 "vkCreatePipelineLayout() call has push constants with "
5423 "overlapping "
5424 "ranges: 0:[16, 20), 1:[12, 20)",
5425 },
5426 {
5427 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5428 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5429 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5430 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5431 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5432 "vkCreatePipelineLayout() call has push constants with "
5433 "overlapping "
5434 "ranges: 0:[16, 20), 3:[12, 20)",
5435 },
5436 {
5437 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5438 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5439 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5440 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5441 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5442 "vkCreatePipelineLayout() call has push constants with "
5443 "overlapping "
5444 "ranges: 0:[16, 20), 2:[4, 100)",
5445 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005446
Karl Schultzc81037d2016-05-12 08:11:23 -06005447 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005448 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005449 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005451 iter.msg);
5452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5453 NULL, &pipeline_layout);
5454 m_errorMonitor->VerifyFound();
5455 if (VK_SUCCESS == err) {
5456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5457 }
5458 }
5459
5460 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005461 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5462 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5463 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5464 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5465 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5466 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5467 ""},
5468 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5469 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5470 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5471 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5472 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5473 ""}}};
5474 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005475 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5476 m_errorMonitor->ExpectSuccess();
5477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5478 NULL, &pipeline_layout);
5479 m_errorMonitor->VerifyNotFound();
5480 if (VK_SUCCESS == err) {
5481 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5482 }
5483 }
5484
5485 //
5486 // CmdPushConstants tests
5487 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005488 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005489
5490 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005491 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5492 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5493 "vkCmdPushConstants() call has push constants with size 0. Size "
5494 "must be greater than zero and a multiple of 4."},
5495 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5496 "vkCmdPushConstants() call has push constants with size 1. Size "
5497 "must be greater than zero and a multiple of 4."},
5498 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5499 "vkCmdPushConstants() call has push constants with size 1. Size "
5500 "must be greater than zero and a multiple of 4."},
5501 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5502 "vkCmdPushConstants() call has push constants with offset 1. "
5503 "Offset must be a multiple of 4."},
5504 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5505 "vkCmdPushConstants() call has push constants with offset 1. "
5506 "Offset must be a multiple of 4."},
5507 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5508 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5509 "0x1 not within flag-matching ranges in pipeline layout"},
5510 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5511 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5512 "0x1 not within flag-matching ranges in pipeline layout"},
5513 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5514 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5515 "0x1 not within flag-matching ranges in pipeline layout"},
5516 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5517 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5518 "0x1 not within flag-matching ranges in pipeline layout"},
5519 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5520 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5521 "any of the ranges in pipeline layout"},
5522 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5523 0, 16},
5524 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5525 "any of the ranges in pipeline layout"},
5526 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005527 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005528 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005529 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005530 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005531 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005532 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005533 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005534 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005535 "vkCmdPushConstants() call has push constants with offset "},
5536 }};
5537
5538 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005539 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005540 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005541 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005542 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005543 pipeline_layout_ci.pushConstantRangeCount =
5544 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005545 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5547 &pipeline_layout);
5548 ASSERT_VK_SUCCESS(err);
5549 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005550 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5552 iter.msg);
5553 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005554 iter.range.stageFlags, iter.range.offset,
5555 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005556 m_errorMonitor->VerifyFound();
5557 }
5558
5559 // Check for invalid stage flag
5560 m_errorMonitor->SetDesiredFailureMsg(
5561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5562 "vkCmdPushConstants() call has no stageFlags set.");
5563 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005564 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005565 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005566 EndCommandBuffer();
5567 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5568 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005569
Karl Schultzc81037d2016-05-12 08:11:23 -06005570 // overlapping range tests with cmd
5571 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5572 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5573 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5574 "0x1 not within flag-matching ranges in pipeline layout"},
5575 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5576 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5577 "0x1 not within flag-matching ranges in pipeline layout"},
5578 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5579 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5580 "0x1 not within flag-matching ranges in pipeline layout"},
5581 }};
5582 const VkPushConstantRange pc_range3[] = {
5583 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5584 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5585 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5586 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5587 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5588 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5589 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5590 };
5591 pipeline_layout_ci.pushConstantRangeCount =
5592 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5593 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5595 &pipeline_layout);
5596 ASSERT_VK_SUCCESS(err);
5597 BeginCommandBuffer();
5598 for (const auto &iter : cmd_overlap_tests) {
5599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5600 iter.msg);
5601 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5602 iter.range.stageFlags, iter.range.offset,
5603 iter.range.size, dummy_values);
5604 m_errorMonitor->VerifyFound();
5605 }
5606 EndCommandBuffer();
5607 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5609
5610 // positive overlapping range tests with cmd
5611 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5612 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5613 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5614 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5615 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5616 }};
5617 const VkPushConstantRange pc_range4[] = {
5618 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5619 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5620 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5621 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5622 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5623 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5624 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5625 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5626 };
5627 pipeline_layout_ci.pushConstantRangeCount =
5628 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5629 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5630 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5631 &pipeline_layout);
5632 ASSERT_VK_SUCCESS(err);
5633 BeginCommandBuffer();
5634 for (const auto &iter : cmd_overlap_tests_pos) {
5635 m_errorMonitor->ExpectSuccess();
5636 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5637 iter.range.stageFlags, iter.range.offset,
5638 iter.range.size, dummy_values);
5639 m_errorMonitor->VerifyNotFound();
5640 }
5641 EndCommandBuffer();
5642 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5644}
5645
Karl Schultz6addd812016-02-02 17:17:23 -07005646TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005647 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005648 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005649
5650 ASSERT_NO_FATAL_FAILURE(InitState());
5651 ASSERT_NO_FATAL_FAILURE(InitViewport());
5652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5653
5654 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5655 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005656 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5657 ds_type_count[0].descriptorCount = 10;
5658 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5659 ds_type_count[1].descriptorCount = 2;
5660 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5661 ds_type_count[2].descriptorCount = 2;
5662 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5663 ds_type_count[3].descriptorCount = 5;
5664 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5665 // type
5666 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5667 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5668 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005669
5670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5672 ds_pool_ci.pNext = NULL;
5673 ds_pool_ci.maxSets = 5;
5674 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5675 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005676
5677 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005678 err =
5679 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005680 ASSERT_VK_SUCCESS(err);
5681
5682 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5683 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005684 dsl_binding[0].binding = 0;
5685 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5686 dsl_binding[0].descriptorCount = 5;
5687 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5688 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005689
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005690 // Create layout identical to set0 layout but w/ different stageFlags
5691 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005692 dsl_fs_stage_only.binding = 0;
5693 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5694 dsl_fs_stage_only.descriptorCount = 5;
5695 dsl_fs_stage_only.stageFlags =
5696 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5697 // bind time
5698 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5701 ds_layout_ci.pNext = NULL;
5702 ds_layout_ci.bindingCount = 1;
5703 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005704 static const uint32_t NUM_LAYOUTS = 4;
5705 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005706 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005707 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5708 // layout for error case
5709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5710 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005711 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005712 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5714 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005715 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005716 dsl_binding[0].binding = 0;
5717 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005718 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005719 dsl_binding[1].binding = 1;
5720 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5721 dsl_binding[1].descriptorCount = 2;
5722 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5723 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005724 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005725 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005726 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5727 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005728 ASSERT_VK_SUCCESS(err);
5729 dsl_binding[0].binding = 0;
5730 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005731 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005732 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5734 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005735 ASSERT_VK_SUCCESS(err);
5736 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005737 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5739 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005740 ASSERT_VK_SUCCESS(err);
5741
5742 static const uint32_t NUM_SETS = 4;
5743 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5744 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005745 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005746 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005747 alloc_info.descriptorPool = ds_pool;
5748 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005749 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5750 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005751 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005752 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005753 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005754 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005755 err =
5756 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005758
5759 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005760 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5761 pipeline_layout_ci.pNext = NULL;
5762 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5763 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005764
5765 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5767 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005769 // Create pipelineLayout with only one setLayout
5770 pipeline_layout_ci.setLayoutCount = 1;
5771 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5773 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005774 ASSERT_VK_SUCCESS(err);
5775 // Create pipelineLayout with 2 descriptor setLayout at index 0
5776 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5777 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005778 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5779 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005780 ASSERT_VK_SUCCESS(err);
5781 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5782 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5783 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5785 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005786 ASSERT_VK_SUCCESS(err);
5787 // Create pipelineLayout with UB type, but stageFlags for FS only
5788 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5789 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005790 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5791 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005792 ASSERT_VK_SUCCESS(err);
5793 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5794 VkDescriptorSetLayout pl_bad_s0[2] = {};
5795 pl_bad_s0[0] = ds_layout_fs_only;
5796 pl_bad_s0[1] = ds_layout[1];
5797 pipeline_layout_ci.setLayoutCount = 2;
5798 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5799 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005800 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5801 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005802 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005803
5804 // Create a buffer to update the descriptor with
5805 uint32_t qfi = 0;
5806 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005807 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5808 buffCI.size = 1024;
5809 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5810 buffCI.queueFamilyIndexCount = 1;
5811 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005812
5813 VkBuffer dyub;
5814 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5815 ASSERT_VK_SUCCESS(err);
5816 // Correctly update descriptor to avoid "NOT_UPDATED" error
5817 static const uint32_t NUM_BUFFS = 5;
5818 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005819 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005820 buffInfo[i].buffer = dyub;
5821 buffInfo[i].offset = 0;
5822 buffInfo[i].range = 1024;
5823 }
Karl Schultz6addd812016-02-02 17:17:23 -07005824 VkImage image;
5825 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5826 const int32_t tex_width = 32;
5827 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005828 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005829 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5830 image_create_info.pNext = NULL;
5831 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5832 image_create_info.format = tex_format;
5833 image_create_info.extent.width = tex_width;
5834 image_create_info.extent.height = tex_height;
5835 image_create_info.extent.depth = 1;
5836 image_create_info.mipLevels = 1;
5837 image_create_info.arrayLayers = 1;
5838 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5839 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5840 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5841 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5843 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005844
Karl Schultz6addd812016-02-02 17:17:23 -07005845 VkMemoryRequirements memReqs;
5846 VkDeviceMemory imageMem;
5847 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005848 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5850 memAlloc.pNext = NULL;
5851 memAlloc.allocationSize = 0;
5852 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005853 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5854 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005855 pass =
5856 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005857 ASSERT_TRUE(pass);
5858 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5859 ASSERT_VK_SUCCESS(err);
5860 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5861 ASSERT_VK_SUCCESS(err);
5862
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005863 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005864 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5865 image_view_create_info.image = image;
5866 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5867 image_view_create_info.format = tex_format;
5868 image_view_create_info.subresourceRange.layerCount = 1;
5869 image_view_create_info.subresourceRange.baseMipLevel = 0;
5870 image_view_create_info.subresourceRange.levelCount = 1;
5871 image_view_create_info.subresourceRange.aspectMask =
5872 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005873
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005874 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005875 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5876 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005877 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005878 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005879 imageInfo[0].imageView = view;
5880 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5881 imageInfo[1].imageView = view;
5882 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005883 imageInfo[2].imageView = view;
5884 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5885 imageInfo[3].imageView = view;
5886 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005887
5888 static const uint32_t NUM_SET_UPDATES = 3;
5889 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5890 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5891 descriptor_write[0].dstSet = descriptorSet[0];
5892 descriptor_write[0].dstBinding = 0;
5893 descriptor_write[0].descriptorCount = 5;
5894 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5895 descriptor_write[0].pBufferInfo = buffInfo;
5896 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5897 descriptor_write[1].dstSet = descriptorSet[1];
5898 descriptor_write[1].dstBinding = 0;
5899 descriptor_write[1].descriptorCount = 2;
5900 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5901 descriptor_write[1].pImageInfo = imageInfo;
5902 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5903 descriptor_write[2].dstSet = descriptorSet[1];
5904 descriptor_write[2].dstBinding = 1;
5905 descriptor_write[2].descriptorCount = 2;
5906 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005907 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005908
5909 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005910
Tobin Ehlis88452832015-12-03 09:40:56 -07005911 // Create PSO to be used for draw-time errors below
5912 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005913 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005914 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005915 "out gl_PerVertex {\n"
5916 " vec4 gl_Position;\n"
5917 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005918 "void main(){\n"
5919 " gl_Position = vec4(1);\n"
5920 "}\n";
5921 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005922 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005923 "\n"
5924 "layout(location=0) out vec4 x;\n"
5925 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5926 "void main(){\n"
5927 " x = vec4(bar.y);\n"
5928 "}\n";
5929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005931 VkPipelineObj pipe(m_device);
5932 pipe.AddShader(&vs);
5933 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005934 pipe.AddColorAttachment();
5935 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005936
5937 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005938
Karl Schultz6addd812016-02-02 17:17:23 -07005939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5940 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5941 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5942 // of PSO
5943 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5944 // cmd_pipeline.c
5945 // due to the fact that cmd_alloc_dset_data() has not been called in
5946 // cmd_bind_graphics_pipeline()
5947 // TODO : Want to cause various binding incompatibility issues here to test
5948 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005949 // First cause various verify_layout_compatibility() fails
5950 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005951 // verify_set_layout_compatibility fail cases:
5952 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5954 " due to: invalid VkPipelineLayout ");
5955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5956 VK_PIPELINE_BIND_POINT_GRAPHICS,
5957 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5958 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005959 m_errorMonitor->VerifyFound();
5960
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005961 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5963 " attempting to bind set to index 1");
5964 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5965 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5966 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005967 m_errorMonitor->VerifyFound();
5968
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005969 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005970 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5971 // descriptors
5972 m_errorMonitor->SetDesiredFailureMsg(
5973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005974 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005975 vkCmdBindDescriptorSets(
5976 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5977 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005978 m_errorMonitor->VerifyFound();
5979
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005980 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5981 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005982 m_errorMonitor->SetDesiredFailureMsg(
5983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005984 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005985 vkCmdBindDescriptorSets(
5986 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5987 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005988 m_errorMonitor->VerifyFound();
5989
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005990 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5991 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005992 m_errorMonitor->SetDesiredFailureMsg(
5993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005994 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005995 vkCmdBindDescriptorSets(
5996 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5997 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005998 m_errorMonitor->VerifyFound();
5999
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006000 // Cause INFO messages due to disturbing previously bound Sets
6001 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006002 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6003 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6004 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006005 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006006 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006007 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006008 " previously bound as set #0 was disturbed ");
6009 vkCmdBindDescriptorSets(
6010 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6011 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006012 m_errorMonitor->VerifyFound();
6013
Karl Schultz6addd812016-02-02 17:17:23 -07006014 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6015 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6016 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006017 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006019 " newly bound as set #0 so set #1 and "
6020 "any subsequent sets were disturbed ");
6021 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6022 VK_PIPELINE_BIND_POINT_GRAPHICS,
6023 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006024 m_errorMonitor->VerifyFound();
6025
Tobin Ehlis88452832015-12-03 09:40:56 -07006026 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006027 // 1. Error due to not binding required set (we actually use same code as
6028 // above to disturb set0)
6029 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6030 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6031 2, &descriptorSet[0], 0, NULL);
6032 vkCmdBindDescriptorSets(
6033 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6034 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6035 m_errorMonitor->SetDesiredFailureMsg(
6036 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6037 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006038 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006039 m_errorMonitor->VerifyFound();
6040
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006041 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006042 // 2. Error due to bound set not being compatible with PSO's
6043 // VkPipelineLayout (diff stageFlags in this case)
6044 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6045 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6046 2, &descriptorSet[0], 0, NULL);
6047 m_errorMonitor->SetDesiredFailureMsg(
6048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6049 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006050 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006051 m_errorMonitor->VerifyFound();
6052
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006053 // Remaining clean-up
6054 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006055 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6057 }
6058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006059 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6060 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006061 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006062 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6063 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006064 vkFreeMemory(m_device->device(), imageMem, NULL);
6065 vkDestroyImage(m_device->device(), image, NULL);
6066 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006067}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006068
Karl Schultz6addd812016-02-02 17:17:23 -07006069TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006070
Karl Schultz6addd812016-02-02 17:17:23 -07006071 m_errorMonitor->SetDesiredFailureMsg(
6072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006073 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006074
6075 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006076 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006077 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006078 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006079
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006080 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006081}
6082
Karl Schultz6addd812016-02-02 17:17:23 -07006083TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6084 VkResult err;
6085 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006086
Karl Schultz6addd812016-02-02 17:17:23 -07006087 m_errorMonitor->SetDesiredFailureMsg(
6088 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006089 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006090
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006091 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006092
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006093 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006094 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006095 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006096 cmd.commandPool = m_commandPool;
6097 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006098 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006099
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006100 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006101 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006102
6103 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006104 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006105 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006106 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006107 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006108 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6109 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006110 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006111
6112 // The error should be caught by validation of the BeginCommandBuffer call
6113 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6114
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006115 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006116 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006117}
6118
Karl Schultz6addd812016-02-02 17:17:23 -07006119TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006120 // Cause error due to Begin while recording CB
6121 // Then cause 2 errors for attempting to reset CB w/o having
6122 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6123 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006125 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006126
6127 ASSERT_NO_FATAL_FAILURE(InitState());
6128
6129 // Calls AllocateCommandBuffers
6130 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6131
Karl Schultz6addd812016-02-02 17:17:23 -07006132 // Force the failure by setting the Renderpass and Framebuffer fields with
6133 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006134 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006135 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006136 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6137 cmd_buf_info.pNext = NULL;
6138 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006139 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006140
6141 // Begin CB to transition to recording state
6142 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6143 // Can't re-begin. This should trigger error
6144 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006145 m_errorMonitor->VerifyFound();
6146
Karl Schultz6addd812016-02-02 17:17:23 -07006147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006149 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6150 // Reset attempt will trigger error due to incorrect CommandPool state
6151 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006152 m_errorMonitor->VerifyFound();
6153
Karl Schultz6addd812016-02-02 17:17:23 -07006154 m_errorMonitor->SetDesiredFailureMsg(
6155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6156 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006157 // Transition CB to RECORDED state
6158 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6159 // Now attempting to Begin will implicitly reset, which triggers error
6160 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006161 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006162}
6163
Karl Schultz6addd812016-02-02 17:17:23 -07006164TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006165 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006166 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006167
Karl Schultz6addd812016-02-02 17:17:23 -07006168 m_errorMonitor->SetDesiredFailureMsg(
6169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006170 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6171
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006172 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006174
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6177 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006178
6179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6181 ds_pool_ci.pNext = NULL;
6182 ds_pool_ci.maxSets = 1;
6183 ds_pool_ci.poolSizeCount = 1;
6184 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006185
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006186 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006187 err =
6188 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006189 ASSERT_VK_SUCCESS(err);
6190
Tony Barboureb254902015-07-15 12:50:33 -06006191 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006192 dsl_binding.binding = 0;
6193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6194 dsl_binding.descriptorCount = 1;
6195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6196 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006197
Tony Barboureb254902015-07-15 12:50:33 -06006198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6200 ds_layout_ci.pNext = NULL;
6201 ds_layout_ci.bindingCount = 1;
6202 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006203
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006204 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6206 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006207 ASSERT_VK_SUCCESS(err);
6208
6209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006212 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006213 alloc_info.descriptorPool = ds_pool;
6214 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6216 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006217 ASSERT_VK_SUCCESS(err);
6218
Tony Barboureb254902015-07-15 12:50:33 -06006219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6221 pipeline_layout_ci.setLayoutCount = 1;
6222 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006223
6224 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6226 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006227 ASSERT_VK_SUCCESS(err);
6228
Tobin Ehlise68360f2015-10-01 11:15:13 -06006229 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006230 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006231
6232 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006233 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6234 vp_state_ci.scissorCount = 1;
6235 vp_state_ci.pScissors = &sc;
6236 vp_state_ci.viewportCount = 1;
6237 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006238
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006239 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6240 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6241 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6242 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6243 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6244 rs_state_ci.depthClampEnable = VK_FALSE;
6245 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6246 rs_state_ci.depthBiasEnable = VK_FALSE;
6247
Tony Barboureb254902015-07-15 12:50:33 -06006248 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6250 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006251 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006252 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6253 gp_ci.layout = pipeline_layout;
6254 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006255
6256 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006257 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6258 pc_ci.initialDataSize = 0;
6259 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006260
6261 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006262 VkPipelineCache pipelineCache;
6263
Karl Schultz6addd812016-02-02 17:17:23 -07006264 err =
6265 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006266 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006267 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6268 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006269
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006270 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006271
Chia-I Wuf7458c52015-10-26 21:10:41 +08006272 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6273 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6274 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6275 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006276}
Tobin Ehlis912df022015-09-17 08:46:18 -06006277/*// TODO : This test should be good, but needs Tess support in compiler to run
6278TEST_F(VkLayerTest, InvalidPatchControlPoints)
6279{
6280 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006281 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006282
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006284 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6285primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006286
Tobin Ehlis912df022015-09-17 08:46:18 -06006287 ASSERT_NO_FATAL_FAILURE(InitState());
6288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006289
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006290 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006291 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006292 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006293
6294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6296 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006297 ds_pool_ci.poolSizeCount = 1;
6298 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006299
6300 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006301 err = vkCreateDescriptorPool(m_device->device(),
6302VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006303 ASSERT_VK_SUCCESS(err);
6304
6305 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006306 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006307 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006308 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006309 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6310 dsl_binding.pImmutableSamplers = NULL;
6311
6312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006313 ds_layout_ci.sType =
6314VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006315 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006316 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006317 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006318
6319 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6321&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006322 ASSERT_VK_SUCCESS(err);
6323
6324 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006325 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6326VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006327 ASSERT_VK_SUCCESS(err);
6328
6329 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 pipeline_layout_ci.sType =
6331VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006332 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006333 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006334 pipeline_layout_ci.pSetLayouts = &ds_layout;
6335
6336 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6338&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006339 ASSERT_VK_SUCCESS(err);
6340
6341 VkPipelineShaderStageCreateInfo shaderStages[3];
6342 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6343
Karl Schultz6addd812016-02-02 17:17:23 -07006344 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6345this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006346 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006347 VkShaderObj
6348tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6349this);
6350 VkShaderObj
6351te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6352this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006353
Karl Schultz6addd812016-02-02 17:17:23 -07006354 shaderStages[0].sType =
6355VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006356 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006357 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006358 shaderStages[1].sType =
6359VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006360 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006361 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006362 shaderStages[2].sType =
6363VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006364 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006365 shaderStages[2].shader = te.handle();
6366
6367 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006368 iaCI.sType =
6369VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006370 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006371
6372 VkPipelineTessellationStateCreateInfo tsCI = {};
6373 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6374 tsCI.patchControlPoints = 0; // This will cause an error
6375
6376 VkGraphicsPipelineCreateInfo gp_ci = {};
6377 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6378 gp_ci.pNext = NULL;
6379 gp_ci.stageCount = 3;
6380 gp_ci.pStages = shaderStages;
6381 gp_ci.pVertexInputState = NULL;
6382 gp_ci.pInputAssemblyState = &iaCI;
6383 gp_ci.pTessellationState = &tsCI;
6384 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006385 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006386 gp_ci.pMultisampleState = NULL;
6387 gp_ci.pDepthStencilState = NULL;
6388 gp_ci.pColorBlendState = NULL;
6389 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6390 gp_ci.layout = pipeline_layout;
6391 gp_ci.renderPass = renderPass();
6392
6393 VkPipelineCacheCreateInfo pc_ci = {};
6394 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6395 pc_ci.pNext = NULL;
6396 pc_ci.initialSize = 0;
6397 pc_ci.initialData = 0;
6398 pc_ci.maxSize = 0;
6399
6400 VkPipeline pipeline;
6401 VkPipelineCache pipelineCache;
6402
Karl Schultz6addd812016-02-02 17:17:23 -07006403 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6404&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006405 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006406 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6407&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006409 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006410
Chia-I Wuf7458c52015-10-26 21:10:41 +08006411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006415}
6416*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006417// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006418TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006419 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006420
Karl Schultz6addd812016-02-02 17:17:23 -07006421 m_errorMonitor->SetDesiredFailureMsg(
6422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006423 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6424
Tobin Ehlise68360f2015-10-01 11:15:13 -06006425 ASSERT_NO_FATAL_FAILURE(InitState());
6426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006427
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006428 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6430 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006431
6432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6434 ds_pool_ci.maxSets = 1;
6435 ds_pool_ci.poolSizeCount = 1;
6436 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006437
6438 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006439 err =
6440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006441 ASSERT_VK_SUCCESS(err);
6442
6443 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006444 dsl_binding.binding = 0;
6445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6446 dsl_binding.descriptorCount = 1;
6447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006448
6449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6451 ds_layout_ci.bindingCount = 1;
6452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006453
6454 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6456 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006457 ASSERT_VK_SUCCESS(err);
6458
6459 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006462 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006463 alloc_info.descriptorPool = ds_pool;
6464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6466 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006467 ASSERT_VK_SUCCESS(err);
6468
6469 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006470 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6471 pipeline_layout_ci.setLayoutCount = 1;
6472 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006473
6474 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6476 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006477 ASSERT_VK_SUCCESS(err);
6478
6479 VkViewport vp = {}; // Just need dummy vp to point to
6480
6481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6483 vp_state_ci.scissorCount = 0;
6484 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6485 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006486
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006487 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6488 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6489 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6490 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6491 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6492 rs_state_ci.depthClampEnable = VK_FALSE;
6493 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6494 rs_state_ci.depthBiasEnable = VK_FALSE;
6495
Cody Northropeb3a6c12015-10-05 14:44:45 -06006496 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006497 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006498
Karl Schultz6addd812016-02-02 17:17:23 -07006499 VkShaderObj vs(m_device, bindStateVertShaderText,
6500 VK_SHADER_STAGE_VERTEX_BIT, this);
6501 VkShaderObj fs(m_device, bindStateFragShaderText,
6502 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006503 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006504 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006505 shaderStages[0] = vs.GetStageCreateInfo();
6506 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006507
6508 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6510 gp_ci.stageCount = 2;
6511 gp_ci.pStages = shaderStages;
6512 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006513 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006514 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6515 gp_ci.layout = pipeline_layout;
6516 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006517
6518 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006519 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006520
6521 VkPipeline pipeline;
6522 VkPipelineCache pipelineCache;
6523
Karl Schultz6addd812016-02-02 17:17:23 -07006524 err =
6525 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006526 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006527 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6528 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006530 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006531
Chia-I Wuf7458c52015-10-26 21:10:41 +08006532 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6533 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6535 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006536}
Karl Schultz6addd812016-02-02 17:17:23 -07006537// Don't set viewport state in PSO. This is an error b/c we always need this
6538// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006539// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006540TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006541 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006542 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006543
Karl Schultz6addd812016-02-02 17:17:23 -07006544 m_errorMonitor->SetDesiredFailureMsg(
6545 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006546 "Gfx Pipeline pViewportState is null. Even if ");
6547
Tobin Ehlise68360f2015-10-01 11:15:13 -06006548 ASSERT_NO_FATAL_FAILURE(InitState());
6549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006550
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006551 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006552 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6553 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006554
6555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6557 ds_pool_ci.maxSets = 1;
6558 ds_pool_ci.poolSizeCount = 1;
6559 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006560
6561 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006562 err =
6563 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006564 ASSERT_VK_SUCCESS(err);
6565
6566 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006567 dsl_binding.binding = 0;
6568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6569 dsl_binding.descriptorCount = 1;
6570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006571
6572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6574 ds_layout_ci.bindingCount = 1;
6575 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006576
6577 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006578 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6579 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006580 ASSERT_VK_SUCCESS(err);
6581
6582 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006583 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006585 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006586 alloc_info.descriptorPool = ds_pool;
6587 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6589 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006590 ASSERT_VK_SUCCESS(err);
6591
6592 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006593 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6594 pipeline_layout_ci.setLayoutCount = 1;
6595 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006596
6597 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006598 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6599 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006600 ASSERT_VK_SUCCESS(err);
6601
6602 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6603 // Set scissor as dynamic to avoid second error
6604 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6606 dyn_state_ci.dynamicStateCount = 1;
6607 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006608
Cody Northropeb3a6c12015-10-05 14:44:45 -06006609 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006610 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006611
Karl Schultz6addd812016-02-02 17:17:23 -07006612 VkShaderObj vs(m_device, bindStateVertShaderText,
6613 VK_SHADER_STAGE_VERTEX_BIT, this);
6614 VkShaderObj fs(m_device, bindStateFragShaderText,
6615 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006616 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006617 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006618 shaderStages[0] = vs.GetStageCreateInfo();
6619 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006620
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006621
6622 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6623 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6624 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6625 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6626 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6627 rs_state_ci.depthClampEnable = VK_FALSE;
6628 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6629 rs_state_ci.depthBiasEnable = VK_FALSE;
6630
Tobin Ehlise68360f2015-10-01 11:15:13 -06006631 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006632 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6633 gp_ci.stageCount = 2;
6634 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006635 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006636 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6637 // should cause validation error
6638 gp_ci.pDynamicState = &dyn_state_ci;
6639 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6640 gp_ci.layout = pipeline_layout;
6641 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006642
6643 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006644 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006645
6646 VkPipeline pipeline;
6647 VkPipelineCache pipelineCache;
6648
Karl Schultz6addd812016-02-02 17:17:23 -07006649 err =
6650 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006651 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6653 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006655 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006656
Chia-I Wuf7458c52015-10-26 21:10:41 +08006657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6660 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006661}
6662// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006663// Then run second test where dynamic scissor count doesn't match PSO scissor
6664// count
6665TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6666 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006667
Karl Schultz6addd812016-02-02 17:17:23 -07006668 m_errorMonitor->SetDesiredFailureMsg(
6669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006670 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6671
Tobin Ehlise68360f2015-10-01 11:15:13 -06006672 ASSERT_NO_FATAL_FAILURE(InitState());
6673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006674
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006675 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006676 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6677 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006678
6679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6681 ds_pool_ci.maxSets = 1;
6682 ds_pool_ci.poolSizeCount = 1;
6683 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006684
6685 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006686 err =
6687 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006688 ASSERT_VK_SUCCESS(err);
6689
6690 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006691 dsl_binding.binding = 0;
6692 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6693 dsl_binding.descriptorCount = 1;
6694 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006695
6696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6698 ds_layout_ci.bindingCount = 1;
6699 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006700
6701 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6703 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006704 ASSERT_VK_SUCCESS(err);
6705
6706 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006707 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006709 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006710 alloc_info.descriptorPool = ds_pool;
6711 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006712 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6713 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006714 ASSERT_VK_SUCCESS(err);
6715
6716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6718 pipeline_layout_ci.setLayoutCount = 1;
6719 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006720
6721 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006722 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6723 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006724 ASSERT_VK_SUCCESS(err);
6725
6726 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006727 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6728 vp_state_ci.viewportCount = 1;
6729 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6730 vp_state_ci.scissorCount = 1;
6731 vp_state_ci.pScissors =
6732 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006733
6734 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6735 // Set scissor as dynamic to avoid that error
6736 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006737 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6738 dyn_state_ci.dynamicStateCount = 1;
6739 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006740
Cody Northropeb3a6c12015-10-05 14:44:45 -06006741 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006742 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006743
Karl Schultz6addd812016-02-02 17:17:23 -07006744 VkShaderObj vs(m_device, bindStateVertShaderText,
6745 VK_SHADER_STAGE_VERTEX_BIT, this);
6746 VkShaderObj fs(m_device, bindStateFragShaderText,
6747 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006748 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006750 shaderStages[0] = vs.GetStageCreateInfo();
6751 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006752
Cody Northropf6622dc2015-10-06 10:33:21 -06006753 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6754 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6755 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006756 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006757 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006758 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006759 vi_ci.pVertexAttributeDescriptions = nullptr;
6760
6761 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6762 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6763 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6764
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006765 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006766 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006767 rs_ci.pNext = nullptr;
6768
Mark Youngc89c6312016-03-31 16:03:20 -06006769 VkPipelineColorBlendAttachmentState att = {};
6770 att.blendEnable = VK_FALSE;
6771 att.colorWriteMask = 0xf;
6772
Cody Northropf6622dc2015-10-06 10:33:21 -06006773 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6774 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6775 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006776 cb_ci.attachmentCount = 1;
6777 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006778
Tobin Ehlise68360f2015-10-01 11:15:13 -06006779 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006780 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6781 gp_ci.stageCount = 2;
6782 gp_ci.pStages = shaderStages;
6783 gp_ci.pVertexInputState = &vi_ci;
6784 gp_ci.pInputAssemblyState = &ia_ci;
6785 gp_ci.pViewportState = &vp_state_ci;
6786 gp_ci.pRasterizationState = &rs_ci;
6787 gp_ci.pColorBlendState = &cb_ci;
6788 gp_ci.pDynamicState = &dyn_state_ci;
6789 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6790 gp_ci.layout = pipeline_layout;
6791 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006792
6793 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006794 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006795
6796 VkPipeline pipeline;
6797 VkPipelineCache pipelineCache;
6798
Karl Schultz6addd812016-02-02 17:17:23 -07006799 err =
6800 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006801 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6803 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006805 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006806
Tobin Ehlisd332f282015-10-02 11:00:56 -06006807 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006808 // First need to successfully create the PSO from above by setting
6809 // pViewports
6810 m_errorMonitor->SetDesiredFailureMsg(
6811 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6812 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6813 "scissorCount is 1. These counts must match.");
6814
6815 VkViewport vp = {}; // Just need dummy vp to point to
6816 vp_state_ci.pViewports = &vp;
6817 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6818 &gp_ci, NULL, &pipeline);
6819 ASSERT_VK_SUCCESS(err);
6820 BeginCommandBuffer();
6821 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6822 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6823 VkRect2D scissors[2] = {}; // don't care about data
6824 // Count of 2 doesn't match PSO count of 1
6825 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6826 Draw(1, 0, 0, 0);
6827
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006828 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006829
6830 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006834 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006835}
6836// Create PSO w/o non-zero scissorCount but no scissor data
6837// Then run second test where dynamic viewportCount doesn't match PSO
6838// viewportCount
6839TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6840 VkResult err;
6841
6842 m_errorMonitor->SetDesiredFailureMsg(
6843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6844 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6845
6846 ASSERT_NO_FATAL_FAILURE(InitState());
6847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6848
6849 VkDescriptorPoolSize ds_type_count = {};
6850 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6851 ds_type_count.descriptorCount = 1;
6852
6853 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6854 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6855 ds_pool_ci.maxSets = 1;
6856 ds_pool_ci.poolSizeCount = 1;
6857 ds_pool_ci.pPoolSizes = &ds_type_count;
6858
6859 VkDescriptorPool ds_pool;
6860 err =
6861 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6862 ASSERT_VK_SUCCESS(err);
6863
6864 VkDescriptorSetLayoutBinding dsl_binding = {};
6865 dsl_binding.binding = 0;
6866 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6867 dsl_binding.descriptorCount = 1;
6868 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6869
6870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6872 ds_layout_ci.bindingCount = 1;
6873 ds_layout_ci.pBindings = &dsl_binding;
6874
6875 VkDescriptorSetLayout ds_layout;
6876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6877 &ds_layout);
6878 ASSERT_VK_SUCCESS(err);
6879
6880 VkDescriptorSet descriptorSet;
6881 VkDescriptorSetAllocateInfo alloc_info = {};
6882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6883 alloc_info.descriptorSetCount = 1;
6884 alloc_info.descriptorPool = ds_pool;
6885 alloc_info.pSetLayouts = &ds_layout;
6886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6887 &descriptorSet);
6888 ASSERT_VK_SUCCESS(err);
6889
6890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6892 pipeline_layout_ci.setLayoutCount = 1;
6893 pipeline_layout_ci.pSetLayouts = &ds_layout;
6894
6895 VkPipelineLayout pipeline_layout;
6896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6897 &pipeline_layout);
6898 ASSERT_VK_SUCCESS(err);
6899
6900 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6901 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6902 vp_state_ci.scissorCount = 1;
6903 vp_state_ci.pScissors =
6904 NULL; // Null scissor w/ count of 1 should cause error
6905 vp_state_ci.viewportCount = 1;
6906 vp_state_ci.pViewports =
6907 NULL; // vp is dynamic (below) so this won't cause error
6908
6909 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6910 // Set scissor as dynamic to avoid that error
6911 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6912 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6913 dyn_state_ci.dynamicStateCount = 1;
6914 dyn_state_ci.pDynamicStates = &vp_state;
6915
6916 VkPipelineShaderStageCreateInfo shaderStages[2];
6917 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6918
6919 VkShaderObj vs(m_device, bindStateVertShaderText,
6920 VK_SHADER_STAGE_VERTEX_BIT, this);
6921 VkShaderObj fs(m_device, bindStateFragShaderText,
6922 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006923 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006924 // but add it to be able to run on more devices
6925 shaderStages[0] = vs.GetStageCreateInfo();
6926 shaderStages[1] = fs.GetStageCreateInfo();
6927
6928 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6929 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6930 vi_ci.pNext = nullptr;
6931 vi_ci.vertexBindingDescriptionCount = 0;
6932 vi_ci.pVertexBindingDescriptions = nullptr;
6933 vi_ci.vertexAttributeDescriptionCount = 0;
6934 vi_ci.pVertexAttributeDescriptions = nullptr;
6935
6936 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6937 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6938 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6939
6940 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6941 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6942 rs_ci.pNext = nullptr;
6943
Mark Youngc89c6312016-03-31 16:03:20 -06006944 VkPipelineColorBlendAttachmentState att = {};
6945 att.blendEnable = VK_FALSE;
6946 att.colorWriteMask = 0xf;
6947
Karl Schultz6addd812016-02-02 17:17:23 -07006948 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6949 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6950 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006951 cb_ci.attachmentCount = 1;
6952 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006953
6954 VkGraphicsPipelineCreateInfo gp_ci = {};
6955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6956 gp_ci.stageCount = 2;
6957 gp_ci.pStages = shaderStages;
6958 gp_ci.pVertexInputState = &vi_ci;
6959 gp_ci.pInputAssemblyState = &ia_ci;
6960 gp_ci.pViewportState = &vp_state_ci;
6961 gp_ci.pRasterizationState = &rs_ci;
6962 gp_ci.pColorBlendState = &cb_ci;
6963 gp_ci.pDynamicState = &dyn_state_ci;
6964 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6965 gp_ci.layout = pipeline_layout;
6966 gp_ci.renderPass = renderPass();
6967
6968 VkPipelineCacheCreateInfo pc_ci = {};
6969 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6970
6971 VkPipeline pipeline;
6972 VkPipelineCache pipelineCache;
6973
6974 err =
6975 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6976 ASSERT_VK_SUCCESS(err);
6977 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6978 &gp_ci, NULL, &pipeline);
6979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006980 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006981
6982 // Now hit second fail case where we set scissor w/ different count than PSO
6983 // First need to successfully create the PSO from above by setting
6984 // pViewports
6985 m_errorMonitor->SetDesiredFailureMsg(
6986 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6987 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6988 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006989
Tobin Ehlisd332f282015-10-02 11:00:56 -06006990 VkRect2D sc = {}; // Just need dummy vp to point to
6991 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006992 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6993 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006994 ASSERT_VK_SUCCESS(err);
6995 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006996 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6997 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006998 VkViewport viewports[2] = {}; // don't care about data
6999 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007000 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007001 Draw(1, 0, 0, 0);
7002
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007003 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007004
Chia-I Wuf7458c52015-10-26 21:10:41 +08007005 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7008 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007009 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007010}
7011
Mark Young7394fdd2016-03-31 14:56:43 -06007012TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7013 VkResult err;
7014
7015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007016 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007017
7018 ASSERT_NO_FATAL_FAILURE(InitState());
7019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7020
7021 VkDescriptorPoolSize ds_type_count = {};
7022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7023 ds_type_count.descriptorCount = 1;
7024
7025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7027 ds_pool_ci.maxSets = 1;
7028 ds_pool_ci.poolSizeCount = 1;
7029 ds_pool_ci.pPoolSizes = &ds_type_count;
7030
7031 VkDescriptorPool ds_pool;
7032 err =
7033 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7034 ASSERT_VK_SUCCESS(err);
7035
7036 VkDescriptorSetLayoutBinding dsl_binding = {};
7037 dsl_binding.binding = 0;
7038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7039 dsl_binding.descriptorCount = 1;
7040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7041
7042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7044 ds_layout_ci.bindingCount = 1;
7045 ds_layout_ci.pBindings = &dsl_binding;
7046
7047 VkDescriptorSetLayout ds_layout;
7048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7049 &ds_layout);
7050 ASSERT_VK_SUCCESS(err);
7051
7052 VkDescriptorSet descriptorSet;
7053 VkDescriptorSetAllocateInfo alloc_info = {};
7054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7055 alloc_info.descriptorSetCount = 1;
7056 alloc_info.descriptorPool = ds_pool;
7057 alloc_info.pSetLayouts = &ds_layout;
7058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7059 &descriptorSet);
7060 ASSERT_VK_SUCCESS(err);
7061
7062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7064 pipeline_layout_ci.setLayoutCount = 1;
7065 pipeline_layout_ci.pSetLayouts = &ds_layout;
7066
7067 VkPipelineLayout pipeline_layout;
7068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7069 &pipeline_layout);
7070 ASSERT_VK_SUCCESS(err);
7071
7072 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7073 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7074 vp_state_ci.scissorCount = 1;
7075 vp_state_ci.pScissors = NULL;
7076 vp_state_ci.viewportCount = 1;
7077 vp_state_ci.pViewports = NULL;
7078
7079 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7080 VK_DYNAMIC_STATE_SCISSOR,
7081 VK_DYNAMIC_STATE_LINE_WIDTH};
7082 // Set scissor as dynamic to avoid that error
7083 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7084 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7085 dyn_state_ci.dynamicStateCount = 2;
7086 dyn_state_ci.pDynamicStates = dynamic_states;
7087
7088 VkPipelineShaderStageCreateInfo shaderStages[2];
7089 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7090
7091 VkShaderObj vs(m_device, bindStateVertShaderText,
7092 VK_SHADER_STAGE_VERTEX_BIT, this);
7093 VkShaderObj fs(m_device, bindStateFragShaderText,
7094 VK_SHADER_STAGE_FRAGMENT_BIT,
7095 this); // TODO - We shouldn't need a fragment shader
7096 // but add it to be able to run on more devices
7097 shaderStages[0] = vs.GetStageCreateInfo();
7098 shaderStages[1] = fs.GetStageCreateInfo();
7099
7100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7102 vi_ci.pNext = nullptr;
7103 vi_ci.vertexBindingDescriptionCount = 0;
7104 vi_ci.pVertexBindingDescriptions = nullptr;
7105 vi_ci.vertexAttributeDescriptionCount = 0;
7106 vi_ci.pVertexAttributeDescriptions = nullptr;
7107
7108 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7109 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7110 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7111
7112 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7113 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7114 rs_ci.pNext = nullptr;
7115
Mark Young47107952016-05-02 15:59:55 -06007116 // Check too low (line width of -1.0f).
7117 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007118
7119 VkPipelineColorBlendAttachmentState att = {};
7120 att.blendEnable = VK_FALSE;
7121 att.colorWriteMask = 0xf;
7122
7123 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7124 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7125 cb_ci.pNext = nullptr;
7126 cb_ci.attachmentCount = 1;
7127 cb_ci.pAttachments = &att;
7128
7129 VkGraphicsPipelineCreateInfo gp_ci = {};
7130 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7131 gp_ci.stageCount = 2;
7132 gp_ci.pStages = shaderStages;
7133 gp_ci.pVertexInputState = &vi_ci;
7134 gp_ci.pInputAssemblyState = &ia_ci;
7135 gp_ci.pViewportState = &vp_state_ci;
7136 gp_ci.pRasterizationState = &rs_ci;
7137 gp_ci.pColorBlendState = &cb_ci;
7138 gp_ci.pDynamicState = &dyn_state_ci;
7139 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7140 gp_ci.layout = pipeline_layout;
7141 gp_ci.renderPass = renderPass();
7142
7143 VkPipelineCacheCreateInfo pc_ci = {};
7144 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7145
7146 VkPipeline pipeline;
7147 VkPipelineCache pipelineCache;
7148
7149 err =
7150 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7151 ASSERT_VK_SUCCESS(err);
7152 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7153 &gp_ci, NULL, &pipeline);
7154
7155 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007156 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007157
7158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7159 "Attempt to set lineWidth to 65536");
7160
7161 // Check too high (line width of 65536.0f).
7162 rs_ci.lineWidth = 65536.0f;
7163
7164 err =
7165 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7166 ASSERT_VK_SUCCESS(err);
7167 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7168 &gp_ci, NULL, &pipeline);
7169
7170 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007171 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007172
7173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007174 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007175
7176 dyn_state_ci.dynamicStateCount = 3;
7177
7178 rs_ci.lineWidth = 1.0f;
7179
7180 err =
7181 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7182 ASSERT_VK_SUCCESS(err);
7183 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7184 &gp_ci, NULL, &pipeline);
7185 BeginCommandBuffer();
7186 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7187 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7188
7189 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007190 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007191 m_errorMonitor->VerifyFound();
7192
7193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7194 "Attempt to set lineWidth to 65536");
7195
7196 // Check too high with dynamic setting.
7197 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7198 m_errorMonitor->VerifyFound();
7199 EndCommandBuffer();
7200
7201 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7204 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007205 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007206}
7207
Karl Schultz6addd812016-02-02 17:17:23 -07007208TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007209 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007210 m_errorMonitor->SetDesiredFailureMsg(
7211 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007212 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007213
7214 ASSERT_NO_FATAL_FAILURE(InitState());
7215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007216
Tony Barbourfe3351b2015-07-28 10:17:20 -06007217 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007218 // Don't care about RenderPass handle b/c error should be flagged before
7219 // that
7220 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7221 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007222
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007223 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007224}
7225
Karl Schultz6addd812016-02-02 17:17:23 -07007226TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007227 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007228 m_errorMonitor->SetDesiredFailureMsg(
7229 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007230 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007231
7232 ASSERT_NO_FATAL_FAILURE(InitState());
7233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007234
Tony Barbourfe3351b2015-07-28 10:17:20 -06007235 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007236 // Just create a dummy Renderpass that's non-NULL so we can get to the
7237 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007238 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007239 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7240 rp_begin.pNext = NULL;
7241 rp_begin.renderPass = renderPass();
7242 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007243
Karl Schultz6addd812016-02-02 17:17:23 -07007244 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7245 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007246
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007247 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007248}
7249
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007250TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7251 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7252 "the number of renderPass attachments that use loadOp"
7253 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7254
7255 ASSERT_NO_FATAL_FAILURE(InitState());
7256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7257
7258 // Create a renderPass with a single attachment that uses loadOp CLEAR
7259 VkAttachmentReference attach = {};
7260 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7261 VkSubpassDescription subpass = {};
7262 subpass.inputAttachmentCount = 1;
7263 subpass.pInputAttachments = &attach;
7264 VkRenderPassCreateInfo rpci = {};
7265 rpci.subpassCount = 1;
7266 rpci.pSubpasses = &subpass;
7267 rpci.attachmentCount = 1;
7268 VkAttachmentDescription attach_desc = {};
7269 attach_desc.format = VK_FORMAT_UNDEFINED;
7270 // Set loadOp to CLEAR
7271 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7272 rpci.pAttachments = &attach_desc;
7273 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7274 VkRenderPass rp;
7275 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7276
7277 VkCommandBufferInheritanceInfo hinfo = {};
7278 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7279 hinfo.renderPass = VK_NULL_HANDLE;
7280 hinfo.subpass = 0;
7281 hinfo.framebuffer = VK_NULL_HANDLE;
7282 hinfo.occlusionQueryEnable = VK_FALSE;
7283 hinfo.queryFlags = 0;
7284 hinfo.pipelineStatistics = 0;
7285 VkCommandBufferBeginInfo info = {};
7286 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7287 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7288 info.pInheritanceInfo = &hinfo;
7289
7290 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7291 VkRenderPassBeginInfo rp_begin = {};
7292 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7293 rp_begin.pNext = NULL;
7294 rp_begin.renderPass = renderPass();
7295 rp_begin.framebuffer = framebuffer();
7296 rp_begin.clearValueCount = 0; // Should be 1
7297
7298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7299 " has a clearValueCount of 0 but the "
7300 "actual number of attachments in "
7301 "renderPass ");
7302
7303 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7304 VK_SUBPASS_CONTENTS_INLINE);
7305
7306 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007307
7308 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007309}
7310
Cody Northrop3bb4d962016-05-09 16:15:57 -06007311TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7312
7313 TEST_DESCRIPTION("End a command buffer with an active render pass");
7314
7315 m_errorMonitor->SetDesiredFailureMsg(
7316 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7317 "It is invalid to issue this call inside an active render pass");
7318
7319 ASSERT_NO_FATAL_FAILURE(InitState());
7320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7321
7322 // The framework's BeginCommandBuffer calls CreateRenderPass
7323 BeginCommandBuffer();
7324
7325 // Call directly into vkEndCommandBuffer instead of the
7326 // the framework's EndCommandBuffer, which inserts a
7327 // vkEndRenderPass
7328 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7329
7330 m_errorMonitor->VerifyFound();
7331
7332 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7333 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7334}
7335
Karl Schultz6addd812016-02-02 17:17:23 -07007336TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007337 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007338 m_errorMonitor->SetDesiredFailureMsg(
7339 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007341
7342 ASSERT_NO_FATAL_FAILURE(InitState());
7343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007344
7345 // Renderpass is started here
7346 BeginCommandBuffer();
7347
7348 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007349 vk_testing::Buffer dstBuffer;
7350 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007352 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007354 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007355}
7356
Karl Schultz6addd812016-02-02 17:17:23 -07007357TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007358 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007359 m_errorMonitor->SetDesiredFailureMsg(
7360 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007361 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007362
7363 ASSERT_NO_FATAL_FAILURE(InitState());
7364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007365
7366 // Renderpass is started here
7367 BeginCommandBuffer();
7368
7369 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007370 vk_testing::Buffer dstBuffer;
7371 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007372
Karl Schultz6addd812016-02-02 17:17:23 -07007373 VkDeviceSize dstOffset = 0;
7374 VkDeviceSize dataSize = 1024;
7375 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007376
Karl Schultz6addd812016-02-02 17:17:23 -07007377 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7378 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007380 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007381}
7382
Karl Schultz6addd812016-02-02 17:17:23 -07007383TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007384 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007385 m_errorMonitor->SetDesiredFailureMsg(
7386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007387 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007388
7389 ASSERT_NO_FATAL_FAILURE(InitState());
7390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007391
7392 // Renderpass is started here
7393 BeginCommandBuffer();
7394
Michael Lentine0a369f62016-02-03 16:51:46 -06007395 VkClearColorValue clear_color;
7396 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7398 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7399 const int32_t tex_width = 32;
7400 const int32_t tex_height = 32;
7401 VkImageCreateInfo image_create_info = {};
7402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7403 image_create_info.pNext = NULL;
7404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7405 image_create_info.format = tex_format;
7406 image_create_info.extent.width = tex_width;
7407 image_create_info.extent.height = tex_height;
7408 image_create_info.extent.depth = 1;
7409 image_create_info.mipLevels = 1;
7410 image_create_info.arrayLayers = 1;
7411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007414
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007415 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007416 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7417 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007418
Karl Schultz6addd812016-02-02 17:17:23 -07007419 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7420 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007421
Karl Schultz6addd812016-02-02 17:17:23 -07007422 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7423 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007424
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007425 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007426}
7427
Karl Schultz6addd812016-02-02 17:17:23 -07007428TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007429 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007430 m_errorMonitor->SetDesiredFailureMsg(
7431 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007432 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007433
7434 ASSERT_NO_FATAL_FAILURE(InitState());
7435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007436
7437 // Renderpass is started here
7438 BeginCommandBuffer();
7439
7440 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007441 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007442 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7443 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7444 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7445 image_create_info.extent.width = 64;
7446 image_create_info.extent.height = 64;
7447 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7448 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007449
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007450 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007451 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7452 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007453
Karl Schultz6addd812016-02-02 17:17:23 -07007454 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7455 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007456
Karl Schultz6addd812016-02-02 17:17:23 -07007457 vkCmdClearDepthStencilImage(
7458 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7459 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7460 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007461
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007462 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007463}
7464
Karl Schultz6addd812016-02-02 17:17:23 -07007465TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007466 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007467 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007468
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007470 "vkCmdClearAttachments: This call "
7471 "must be issued inside an active "
7472 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007473
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007474 ASSERT_NO_FATAL_FAILURE(InitState());
7475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007476
7477 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007478 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007479 ASSERT_VK_SUCCESS(err);
7480
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007481 VkClearAttachment color_attachment;
7482 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7483 color_attachment.clearValue.color.float32[0] = 0;
7484 color_attachment.clearValue.color.float32[1] = 0;
7485 color_attachment.clearValue.color.float32[2] = 0;
7486 color_attachment.clearValue.color.float32[3] = 0;
7487 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007488 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7489 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7490 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007491
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007492 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007493}
7494
Karl Schultz9e66a292016-04-21 15:57:51 -06007495TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7496 // Try to add a buffer memory barrier with no buffer.
7497 m_errorMonitor->SetDesiredFailureMsg(
7498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7499 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7500
7501 ASSERT_NO_FATAL_FAILURE(InitState());
7502 BeginCommandBuffer();
7503
7504 VkBufferMemoryBarrier buf_barrier = {};
7505 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7506 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7507 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7508 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7509 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7510 buf_barrier.buffer = VK_NULL_HANDLE;
7511 buf_barrier.offset = 0;
7512 buf_barrier.size = VK_WHOLE_SIZE;
7513 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7514 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7515 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7516
7517 m_errorMonitor->VerifyFound();
7518}
7519
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007520TEST_F(VkLayerTest, InvalidBarriers) {
7521 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7522
7523 m_errorMonitor->SetDesiredFailureMsg(
7524 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7525
7526 ASSERT_NO_FATAL_FAILURE(InitState());
7527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7528
7529 VkMemoryBarrier mem_barrier = {};
7530 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7531 mem_barrier.pNext = NULL;
7532 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7533 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7534 BeginCommandBuffer();
7535 // BeginCommandBuffer() starts a render pass
7536 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7537 VK_PIPELINE_STAGE_HOST_BIT,
7538 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7539 &mem_barrier, 0, nullptr, 0, nullptr);
7540 m_errorMonitor->VerifyFound();
7541
7542 m_errorMonitor->SetDesiredFailureMsg(
7543 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7544 "Image Layout cannot be transitioned to UNDEFINED");
7545 VkImageObj image(m_device);
7546 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7547 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7548 ASSERT_TRUE(image.initialized());
7549 VkImageMemoryBarrier img_barrier = {};
7550 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7551 img_barrier.pNext = NULL;
7552 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7553 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7554 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7555 // New layout can't be UNDEFINED
7556 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7557 img_barrier.image = image.handle();
7558 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7559 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7560 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7561 img_barrier.subresourceRange.baseArrayLayer = 0;
7562 img_barrier.subresourceRange.baseMipLevel = 0;
7563 img_barrier.subresourceRange.layerCount = 1;
7564 img_barrier.subresourceRange.levelCount = 1;
7565 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7566 VK_PIPELINE_STAGE_HOST_BIT,
7567 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7568 nullptr, 1, &img_barrier);
7569 m_errorMonitor->VerifyFound();
7570 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7571
7572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7573 "Subresource must have the sum of the "
7574 "baseArrayLayer");
7575 // baseArrayLayer + layerCount must be <= image's arrayLayers
7576 img_barrier.subresourceRange.baseArrayLayer = 1;
7577 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7578 VK_PIPELINE_STAGE_HOST_BIT,
7579 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7580 nullptr, 1, &img_barrier);
7581 m_errorMonitor->VerifyFound();
7582 img_barrier.subresourceRange.baseArrayLayer = 0;
7583
7584 m_errorMonitor->SetDesiredFailureMsg(
7585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7586 "Subresource must have the sum of the baseMipLevel");
7587 // baseMipLevel + levelCount must be <= image's mipLevels
7588 img_barrier.subresourceRange.baseMipLevel = 1;
7589 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7590 VK_PIPELINE_STAGE_HOST_BIT,
7591 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7592 nullptr, 1, &img_barrier);
7593 m_errorMonitor->VerifyFound();
7594 img_barrier.subresourceRange.baseMipLevel = 0;
7595
7596 m_errorMonitor->SetDesiredFailureMsg(
7597 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7598 "Buffer Barriers cannot be used during a render pass");
7599 vk_testing::Buffer buffer;
7600 buffer.init(*m_device, 256);
7601 VkBufferMemoryBarrier buf_barrier = {};
7602 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7603 buf_barrier.pNext = NULL;
7604 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7605 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7606 buf_barrier.buffer = buffer.handle();
7607 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7608 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7609 buf_barrier.offset = 0;
7610 buf_barrier.size = VK_WHOLE_SIZE;
7611 // Can't send buffer barrier during a render pass
7612 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7613 VK_PIPELINE_STAGE_HOST_BIT,
7614 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7615 &buf_barrier, 0, nullptr);
7616 m_errorMonitor->VerifyFound();
7617 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7618
7619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7620 "which is not less than total size");
7621 buf_barrier.offset = 257;
7622 // Offset greater than total size
7623 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7624 VK_PIPELINE_STAGE_HOST_BIT,
7625 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7626 &buf_barrier, 0, nullptr);
7627 m_errorMonitor->VerifyFound();
7628 buf_barrier.offset = 0;
7629
7630 m_errorMonitor->SetDesiredFailureMsg(
7631 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7632 buf_barrier.size = 257;
7633 // Size greater than total size
7634 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7635 VK_PIPELINE_STAGE_HOST_BIT,
7636 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7637 &buf_barrier, 0, nullptr);
7638 m_errorMonitor->VerifyFound();
7639 buf_barrier.size = VK_WHOLE_SIZE;
7640
7641 m_errorMonitor->SetDesiredFailureMsg(
7642 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7643 "Image is a depth and stencil format and thus must "
7644 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7645 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7646 VkDepthStencilObj ds_image(m_device);
7647 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7648 ASSERT_TRUE(ds_image.initialized());
7649 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7650 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7651 img_barrier.image = ds_image.handle();
7652 // Leave aspectMask at COLOR on purpose
7653 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7654 VK_PIPELINE_STAGE_HOST_BIT,
7655 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7656 nullptr, 1, &img_barrier);
7657 m_errorMonitor->VerifyFound();
7658}
7659
Karl Schultz6addd812016-02-02 17:17:23 -07007660TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007661 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007662 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007663
Karl Schultz6addd812016-02-02 17:17:23 -07007664 m_errorMonitor->SetDesiredFailureMsg(
7665 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007666 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7667
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007668 ASSERT_NO_FATAL_FAILURE(InitState());
7669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007670 uint32_t qfi = 0;
7671 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007672 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7673 buffCI.size = 1024;
7674 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7675 buffCI.queueFamilyIndexCount = 1;
7676 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007677
7678 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007679 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007680 ASSERT_VK_SUCCESS(err);
7681
7682 BeginCommandBuffer();
7683 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007684 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7685 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007686 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007687 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7688 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007690 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007691
Chia-I Wuf7458c52015-10-26 21:10:41 +08007692 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007693}
7694
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007695TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7696 // Create an out-of-range queueFamilyIndex
7697 m_errorMonitor->SetDesiredFailureMsg(
7698 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007699 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7700 "of the indices specified when the device was created, via the "
7701 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007702
7703 ASSERT_NO_FATAL_FAILURE(InitState());
7704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7705 VkBufferCreateInfo buffCI = {};
7706 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7707 buffCI.size = 1024;
7708 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7709 buffCI.queueFamilyIndexCount = 1;
7710 // Introduce failure by specifying invalid queue_family_index
7711 uint32_t qfi = 777;
7712 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007713 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007714
7715 VkBuffer ib;
7716 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007718 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007719 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007720}
7721
Karl Schultz6addd812016-02-02 17:17:23 -07007722TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7723 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7724 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007725
Karl Schultz6addd812016-02-02 17:17:23 -07007726 m_errorMonitor->SetDesiredFailureMsg(
7727 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007728 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007729
7730 ASSERT_NO_FATAL_FAILURE(InitState());
7731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007732
7733 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007734 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007735 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7736 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007738 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007739}
7740
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007741TEST_F(VkLayerTest, DSUsageBitsErrors) {
7742 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7743 "that do not have correct usage bits sets.");
7744 VkResult err;
7745
7746 ASSERT_NO_FATAL_FAILURE(InitState());
7747 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7748 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7749 ds_type_count[i].type = VkDescriptorType(i);
7750 ds_type_count[i].descriptorCount = 1;
7751 }
7752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7754 ds_pool_ci.pNext = NULL;
7755 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7756 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7757 ds_pool_ci.pPoolSizes = ds_type_count;
7758
7759 VkDescriptorPool ds_pool;
7760 err =
7761 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7762 ASSERT_VK_SUCCESS(err);
7763
7764 // Create 10 layouts where each has a single descriptor of different type
7765 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7766 {};
7767 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7768 dsl_binding[i].binding = 0;
7769 dsl_binding[i].descriptorType = VkDescriptorType(i);
7770 dsl_binding[i].descriptorCount = 1;
7771 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7772 dsl_binding[i].pImmutableSamplers = NULL;
7773 }
7774
7775 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7776 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7777 ds_layout_ci.pNext = NULL;
7778 ds_layout_ci.bindingCount = 1;
7779 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7780 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7781 ds_layout_ci.pBindings = dsl_binding + i;
7782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7783 NULL, ds_layouts + i);
7784 ASSERT_VK_SUCCESS(err);
7785 }
7786 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7787 VkDescriptorSetAllocateInfo alloc_info = {};
7788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7789 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7790 alloc_info.descriptorPool = ds_pool;
7791 alloc_info.pSetLayouts = ds_layouts;
7792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7793 descriptor_sets);
7794 ASSERT_VK_SUCCESS(err);
7795
7796 // Create a buffer & bufferView to be used for invalid updates
7797 VkBufferCreateInfo buff_ci = {};
7798 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7799 // This usage is not valid for any descriptor type
7800 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7801 buff_ci.size = 256;
7802 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7803 VkBuffer buffer;
7804 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7805 ASSERT_VK_SUCCESS(err);
7806
7807 VkBufferViewCreateInfo buff_view_ci = {};
7808 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7809 buff_view_ci.buffer = buffer;
7810 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7811 buff_view_ci.range = VK_WHOLE_SIZE;
7812 VkBufferView buff_view;
7813 err =
7814 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7815 ASSERT_VK_SUCCESS(err);
7816
7817 // Create an image to be used for invalid updates
7818 VkImageCreateInfo image_ci = {};
7819 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7820 image_ci.imageType = VK_IMAGE_TYPE_2D;
7821 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7822 image_ci.extent.width = 64;
7823 image_ci.extent.height = 64;
7824 image_ci.extent.depth = 1;
7825 image_ci.mipLevels = 1;
7826 image_ci.arrayLayers = 1;
7827 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7828 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7829 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7830 // This usage is not valid for any descriptor type
7831 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7832 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7833 VkImage image;
7834 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7835 ASSERT_VK_SUCCESS(err);
7836 // Bind memory to image
7837 VkMemoryRequirements mem_reqs;
7838 VkDeviceMemory image_mem;
7839 bool pass;
7840 VkMemoryAllocateInfo mem_alloc = {};
7841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7842 mem_alloc.pNext = NULL;
7843 mem_alloc.allocationSize = 0;
7844 mem_alloc.memoryTypeIndex = 0;
7845 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7846 mem_alloc.allocationSize = mem_reqs.size;
7847 pass =
7848 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7849 ASSERT_TRUE(pass);
7850 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7851 ASSERT_VK_SUCCESS(err);
7852 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7853 ASSERT_VK_SUCCESS(err);
7854 // Now create view for image
7855 VkImageViewCreateInfo image_view_ci = {};
7856 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7857 image_view_ci.image = image;
7858 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7859 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7860 image_view_ci.subresourceRange.layerCount = 1;
7861 image_view_ci.subresourceRange.baseArrayLayer = 0;
7862 image_view_ci.subresourceRange.levelCount = 1;
7863 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7864 VkImageView image_view;
7865 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7866 &image_view);
7867 ASSERT_VK_SUCCESS(err);
7868
7869 VkDescriptorBufferInfo buff_info = {};
7870 buff_info.buffer = buffer;
7871 VkDescriptorImageInfo img_info = {};
7872 img_info.imageView = image_view;
7873 VkWriteDescriptorSet descriptor_write = {};
7874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7875 descriptor_write.dstBinding = 0;
7876 descriptor_write.descriptorCount = 1;
7877 descriptor_write.pTexelBufferView = &buff_view;
7878 descriptor_write.pBufferInfo = &buff_info;
7879 descriptor_write.pImageInfo = &img_info;
7880
7881 // These error messages align with VkDescriptorType struct
7882 const char *error_msgs[] = {
7883 "", // placeholder, no error for SAMPLER descriptor
7884 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7885 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7886 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7887 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7888 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7889 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7890 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7891 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7892 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7893 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7894 // Start loop at 1 as SAMPLER desc type has no usage bit error
7895 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7896 descriptor_write.descriptorType = VkDescriptorType(i);
7897 descriptor_write.dstSet = descriptor_sets[i];
7898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7899 error_msgs[i]);
7900
7901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7902 NULL);
7903
7904 m_errorMonitor->VerifyFound();
7905 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7906 }
7907 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7908 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007909 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007910 vkDestroyImageView(m_device->device(), image_view, NULL);
7911 vkDestroyBuffer(m_device->device(), buffer, NULL);
7912 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7913 vkFreeDescriptorSets(m_device->device(), ds_pool,
7914 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7916}
7917
Karl Schultz6addd812016-02-02 17:17:23 -07007918TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007919 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07007920 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007921
Karl Schultz6addd812016-02-02 17:17:23 -07007922 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007923 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7924 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
7925 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007926
Tobin Ehlis3b780662015-05-28 12:11:26 -06007927 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007928 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007929 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007930 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7931 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007932
7933 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007934 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7935 ds_pool_ci.pNext = NULL;
7936 ds_pool_ci.maxSets = 1;
7937 ds_pool_ci.poolSizeCount = 1;
7938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007939
Tobin Ehlis3b780662015-05-28 12:11:26 -06007940 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007941 err =
7942 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007943 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007944 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007945 dsl_binding.binding = 0;
7946 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7947 dsl_binding.descriptorCount = 1;
7948 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7949 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007950
Tony Barboureb254902015-07-15 12:50:33 -06007951 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007952 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7953 ds_layout_ci.pNext = NULL;
7954 ds_layout_ci.bindingCount = 1;
7955 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007956
Tobin Ehlis3b780662015-05-28 12:11:26 -06007957 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7959 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007960 ASSERT_VK_SUCCESS(err);
7961
7962 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007963 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007965 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007966 alloc_info.descriptorPool = ds_pool;
7967 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7969 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007970 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007971
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007972 VkSamplerCreateInfo sampler_ci = {};
7973 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7974 sampler_ci.pNext = NULL;
7975 sampler_ci.magFilter = VK_FILTER_NEAREST;
7976 sampler_ci.minFilter = VK_FILTER_NEAREST;
7977 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7978 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7979 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7980 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7981 sampler_ci.mipLodBias = 1.0;
7982 sampler_ci.anisotropyEnable = VK_FALSE;
7983 sampler_ci.maxAnisotropy = 1;
7984 sampler_ci.compareEnable = VK_FALSE;
7985 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7986 sampler_ci.minLod = 1.0;
7987 sampler_ci.maxLod = 1.0;
7988 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7989 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7990 VkSampler sampler;
7991 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7992 ASSERT_VK_SUCCESS(err);
7993
7994 VkDescriptorImageInfo info = {};
7995 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007996
7997 VkWriteDescriptorSet descriptor_write;
7998 memset(&descriptor_write, 0, sizeof(descriptor_write));
7999 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008000 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008001 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008002 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008003 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008004 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008005
8006 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8007
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008008 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008009
Chia-I Wuf7458c52015-10-26 21:10:41 +08008010 vkDestroySampler(m_device->device(), sampler, NULL);
8011 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8012 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008013}
8014
Karl Schultz6addd812016-02-02 17:17:23 -07008015TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008016 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008017 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008018
Karl Schultz6addd812016-02-02 17:17:23 -07008019 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8021 " binding #0 with 1 total descriptors but update of 1 descriptors "
8022 "starting at binding offset of 0 combined with update array element "
8023 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008024
Tobin Ehlis3b780662015-05-28 12:11:26 -06008025 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008026 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008027 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8029 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008030
8031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8033 ds_pool_ci.pNext = NULL;
8034 ds_pool_ci.maxSets = 1;
8035 ds_pool_ci.poolSizeCount = 1;
8036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008037
Tobin Ehlis3b780662015-05-28 12:11:26 -06008038 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008039 err =
8040 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008041 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008042
Tony Barboureb254902015-07-15 12:50:33 -06008043 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008044 dsl_binding.binding = 0;
8045 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8046 dsl_binding.descriptorCount = 1;
8047 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8048 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008049
8050 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008051 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8052 ds_layout_ci.pNext = NULL;
8053 ds_layout_ci.bindingCount = 1;
8054 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008055
Tobin Ehlis3b780662015-05-28 12:11:26 -06008056 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008057 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8058 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008059 ASSERT_VK_SUCCESS(err);
8060
8061 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008062 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008063 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008064 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008065 alloc_info.descriptorPool = ds_pool;
8066 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008067 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8068 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008069 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008070
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008071 // Correctly update descriptor to avoid "NOT_UPDATED" error
8072 VkDescriptorBufferInfo buff_info = {};
8073 buff_info.buffer =
8074 VkBuffer(0); // Don't care about buffer handle for this test
8075 buff_info.offset = 0;
8076 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008077
8078 VkWriteDescriptorSet descriptor_write;
8079 memset(&descriptor_write, 0, sizeof(descriptor_write));
8080 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008081 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008082 descriptor_write.dstArrayElement =
8083 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008084 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008085 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8086 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008087
8088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8089
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008090 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008091
Chia-I Wuf7458c52015-10-26 21:10:41 +08008092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008094}
8095
Karl Schultz6addd812016-02-02 17:17:23 -07008096TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8097 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8098 // index 2
8099 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008100
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8102 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008103
Tobin Ehlis3b780662015-05-28 12:11:26 -06008104 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008105 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008106 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008107 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8108 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008109
8110 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008111 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8112 ds_pool_ci.pNext = NULL;
8113 ds_pool_ci.maxSets = 1;
8114 ds_pool_ci.poolSizeCount = 1;
8115 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008116
Tobin Ehlis3b780662015-05-28 12:11:26 -06008117 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008118 err =
8119 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008120 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008121
Tony Barboureb254902015-07-15 12:50:33 -06008122 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008123 dsl_binding.binding = 0;
8124 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8125 dsl_binding.descriptorCount = 1;
8126 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8127 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008128
8129 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008130 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8131 ds_layout_ci.pNext = NULL;
8132 ds_layout_ci.bindingCount = 1;
8133 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008134 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008135 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8136 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008137 ASSERT_VK_SUCCESS(err);
8138
8139 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008140 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008141 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008142 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008143 alloc_info.descriptorPool = ds_pool;
8144 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8146 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008147 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008148
Tony Barboureb254902015-07-15 12:50:33 -06008149 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008150 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8151 sampler_ci.pNext = NULL;
8152 sampler_ci.magFilter = VK_FILTER_NEAREST;
8153 sampler_ci.minFilter = VK_FILTER_NEAREST;
8154 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8155 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8156 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8157 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8158 sampler_ci.mipLodBias = 1.0;
8159 sampler_ci.anisotropyEnable = VK_FALSE;
8160 sampler_ci.maxAnisotropy = 1;
8161 sampler_ci.compareEnable = VK_FALSE;
8162 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8163 sampler_ci.minLod = 1.0;
8164 sampler_ci.maxLod = 1.0;
8165 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8166 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008167
Tobin Ehlis3b780662015-05-28 12:11:26 -06008168 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008169 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008170 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008171
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008172 VkDescriptorImageInfo info = {};
8173 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008174
8175 VkWriteDescriptorSet descriptor_write;
8176 memset(&descriptor_write, 0, sizeof(descriptor_write));
8177 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008178 descriptor_write.dstSet = descriptorSet;
8179 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008180 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008181 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008182 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008183 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008184
8185 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008187 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008188
Chia-I Wuf7458c52015-10-26 21:10:41 +08008189 vkDestroySampler(m_device->device(), sampler, NULL);
8190 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8191 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008192}
8193
Karl Schultz6addd812016-02-02 17:17:23 -07008194TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8195 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8196 // types
8197 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008198
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008200 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008201
Tobin Ehlis3b780662015-05-28 12:11:26 -06008202 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008203
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8206 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008207
8208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8210 ds_pool_ci.pNext = NULL;
8211 ds_pool_ci.maxSets = 1;
8212 ds_pool_ci.poolSizeCount = 1;
8213 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008214
Tobin Ehlis3b780662015-05-28 12:11:26 -06008215 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008216 err =
8217 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008218 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008219 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008220 dsl_binding.binding = 0;
8221 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8222 dsl_binding.descriptorCount = 1;
8223 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8224 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008225
Tony Barboureb254902015-07-15 12:50:33 -06008226 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008227 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8228 ds_layout_ci.pNext = NULL;
8229 ds_layout_ci.bindingCount = 1;
8230 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008231
Tobin Ehlis3b780662015-05-28 12:11:26 -06008232 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8234 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008235 ASSERT_VK_SUCCESS(err);
8236
8237 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008238 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008240 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008241 alloc_info.descriptorPool = ds_pool;
8242 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8244 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008245 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008246
Tony Barboureb254902015-07-15 12:50:33 -06008247 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008248 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8249 sampler_ci.pNext = NULL;
8250 sampler_ci.magFilter = VK_FILTER_NEAREST;
8251 sampler_ci.minFilter = VK_FILTER_NEAREST;
8252 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8253 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8254 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8255 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8256 sampler_ci.mipLodBias = 1.0;
8257 sampler_ci.anisotropyEnable = VK_FALSE;
8258 sampler_ci.maxAnisotropy = 1;
8259 sampler_ci.compareEnable = VK_FALSE;
8260 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8261 sampler_ci.minLod = 1.0;
8262 sampler_ci.maxLod = 1.0;
8263 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8264 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008265 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008266 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008267 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008268
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008269 VkDescriptorImageInfo info = {};
8270 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008271
8272 VkWriteDescriptorSet descriptor_write;
8273 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008274 descriptor_write.sType =
8275 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008276 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008277 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008278 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008280 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008281
8282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008284 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008285
Chia-I Wuf7458c52015-10-26 21:10:41 +08008286 vkDestroySampler(m_device->device(), sampler, NULL);
8287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008289}
8290
Karl Schultz6addd812016-02-02 17:17:23 -07008291TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008292 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008293 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008294
Karl Schultz6addd812016-02-02 17:17:23 -07008295 m_errorMonitor->SetDesiredFailureMsg(
8296 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008297 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008298
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008299 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008300 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8301 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008302 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008303 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8304 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008305
8306 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008307 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8308 ds_pool_ci.pNext = NULL;
8309 ds_pool_ci.maxSets = 1;
8310 ds_pool_ci.poolSizeCount = 1;
8311 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008312
8313 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008314 err =
8315 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008316 ASSERT_VK_SUCCESS(err);
8317
8318 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008319 dsl_binding.binding = 0;
8320 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8321 dsl_binding.descriptorCount = 1;
8322 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8323 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008324
8325 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008326 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8327 ds_layout_ci.pNext = NULL;
8328 ds_layout_ci.bindingCount = 1;
8329 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008330 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008331 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8332 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008333 ASSERT_VK_SUCCESS(err);
8334
8335 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008336 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008337 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008338 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008339 alloc_info.descriptorPool = ds_pool;
8340 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008341 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8342 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008343 ASSERT_VK_SUCCESS(err);
8344
Karl Schultz6addd812016-02-02 17:17:23 -07008345 VkSampler sampler =
8346 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008347
8348 VkDescriptorImageInfo descriptor_info;
8349 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8350 descriptor_info.sampler = sampler;
8351
8352 VkWriteDescriptorSet descriptor_write;
8353 memset(&descriptor_write, 0, sizeof(descriptor_write));
8354 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008355 descriptor_write.dstSet = descriptorSet;
8356 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008357 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8359 descriptor_write.pImageInfo = &descriptor_info;
8360
8361 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8362
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008363 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008364
Chia-I Wuf7458c52015-10-26 21:10:41 +08008365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008367}
8368
Karl Schultz6addd812016-02-02 17:17:23 -07008369TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8370 // Create a single combined Image/Sampler descriptor and send it an invalid
8371 // imageView
8372 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008373
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8375 "Attempted write update to combined "
8376 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008377 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008378
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008379 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008380 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008381 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8382 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008383
8384 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008385 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8386 ds_pool_ci.pNext = NULL;
8387 ds_pool_ci.maxSets = 1;
8388 ds_pool_ci.poolSizeCount = 1;
8389 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008390
8391 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008392 err =
8393 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008394 ASSERT_VK_SUCCESS(err);
8395
8396 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008397 dsl_binding.binding = 0;
8398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8399 dsl_binding.descriptorCount = 1;
8400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8401 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008402
8403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8405 ds_layout_ci.pNext = NULL;
8406 ds_layout_ci.bindingCount = 1;
8407 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008408 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008409 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8410 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008411 ASSERT_VK_SUCCESS(err);
8412
8413 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008414 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008416 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008417 alloc_info.descriptorPool = ds_pool;
8418 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8420 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008421 ASSERT_VK_SUCCESS(err);
8422
8423 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008424 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8425 sampler_ci.pNext = NULL;
8426 sampler_ci.magFilter = VK_FILTER_NEAREST;
8427 sampler_ci.minFilter = VK_FILTER_NEAREST;
8428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8432 sampler_ci.mipLodBias = 1.0;
8433 sampler_ci.anisotropyEnable = VK_FALSE;
8434 sampler_ci.maxAnisotropy = 1;
8435 sampler_ci.compareEnable = VK_FALSE;
8436 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8437 sampler_ci.minLod = 1.0;
8438 sampler_ci.maxLod = 1.0;
8439 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8440 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008441
8442 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008443 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008444 ASSERT_VK_SUCCESS(err);
8445
Karl Schultz6addd812016-02-02 17:17:23 -07008446 VkImageView view =
8447 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008448
8449 VkDescriptorImageInfo descriptor_info;
8450 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8451 descriptor_info.sampler = sampler;
8452 descriptor_info.imageView = view;
8453
8454 VkWriteDescriptorSet descriptor_write;
8455 memset(&descriptor_write, 0, sizeof(descriptor_write));
8456 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008457 descriptor_write.dstSet = descriptorSet;
8458 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008459 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8461 descriptor_write.pImageInfo = &descriptor_info;
8462
8463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8464
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008465 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008466
Chia-I Wuf7458c52015-10-26 21:10:41 +08008467 vkDestroySampler(m_device->device(), sampler, NULL);
8468 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8469 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008470}
8471
Karl Schultz6addd812016-02-02 17:17:23 -07008472TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8473 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8474 // into the other
8475 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008476
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8478 " binding #1 with type "
8479 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8480 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008481
Tobin Ehlis04356f92015-10-27 16:35:27 -06008482 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008483 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008484 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008485 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8486 ds_type_count[0].descriptorCount = 1;
8487 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8488 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008489
8490 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008491 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8492 ds_pool_ci.pNext = NULL;
8493 ds_pool_ci.maxSets = 1;
8494 ds_pool_ci.poolSizeCount = 2;
8495 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008496
8497 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008498 err =
8499 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008500 ASSERT_VK_SUCCESS(err);
8501 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008502 dsl_binding[0].binding = 0;
8503 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8504 dsl_binding[0].descriptorCount = 1;
8505 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8506 dsl_binding[0].pImmutableSamplers = NULL;
8507 dsl_binding[1].binding = 1;
8508 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8509 dsl_binding[1].descriptorCount = 1;
8510 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8511 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008512
8513 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008514 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8515 ds_layout_ci.pNext = NULL;
8516 ds_layout_ci.bindingCount = 2;
8517 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008518
8519 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008520 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8521 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008522 ASSERT_VK_SUCCESS(err);
8523
8524 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008525 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008526 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008527 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008528 alloc_info.descriptorPool = ds_pool;
8529 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008530 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8531 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008532 ASSERT_VK_SUCCESS(err);
8533
8534 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008535 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8536 sampler_ci.pNext = NULL;
8537 sampler_ci.magFilter = VK_FILTER_NEAREST;
8538 sampler_ci.minFilter = VK_FILTER_NEAREST;
8539 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8540 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8541 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8542 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8543 sampler_ci.mipLodBias = 1.0;
8544 sampler_ci.anisotropyEnable = VK_FALSE;
8545 sampler_ci.maxAnisotropy = 1;
8546 sampler_ci.compareEnable = VK_FALSE;
8547 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8548 sampler_ci.minLod = 1.0;
8549 sampler_ci.maxLod = 1.0;
8550 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8551 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008552
8553 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008554 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008555 ASSERT_VK_SUCCESS(err);
8556
8557 VkDescriptorImageInfo info = {};
8558 info.sampler = sampler;
8559
8560 VkWriteDescriptorSet descriptor_write;
8561 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8562 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008563 descriptor_write.dstSet = descriptorSet;
8564 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008565 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008566 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8567 descriptor_write.pImageInfo = &info;
8568 // This write update should succeed
8569 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8570 // Now perform a copy update that fails due to type mismatch
8571 VkCopyDescriptorSet copy_ds_update;
8572 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8573 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8574 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008575 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008576 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008577 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008578 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008579 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008581 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008582 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008583 m_errorMonitor->SetDesiredFailureMsg(
8584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008585 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008586 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8587 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8588 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008589 copy_ds_update.srcBinding =
8590 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008591 copy_ds_update.dstSet = descriptorSet;
8592 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008593 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008594 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8595
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008596 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008597
Tobin Ehlis04356f92015-10-27 16:35:27 -06008598 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008599 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008600 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8601 "update array offset of 0 and update of "
8602 "5 descriptors oversteps total number "
8603 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008604
Tobin Ehlis04356f92015-10-27 16:35:27 -06008605 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8606 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8607 copy_ds_update.srcSet = descriptorSet;
8608 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008609 copy_ds_update.dstSet = descriptorSet;
8610 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008611 copy_ds_update.descriptorCount =
8612 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008613 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8614
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008615 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008616
Chia-I Wuf7458c52015-10-26 21:10:41 +08008617 vkDestroySampler(m_device->device(), sampler, NULL);
8618 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8619 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008620}
8621
Karl Schultz6addd812016-02-02 17:17:23 -07008622TEST_F(VkLayerTest, NumSamplesMismatch) {
8623 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8624 // sampleCount
8625 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008626
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008628 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008629
Tobin Ehlis3b780662015-05-28 12:11:26 -06008630 ASSERT_NO_FATAL_FAILURE(InitState());
8631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008632 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008633 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008634 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008635
8636 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008637 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8638 ds_pool_ci.pNext = NULL;
8639 ds_pool_ci.maxSets = 1;
8640 ds_pool_ci.poolSizeCount = 1;
8641 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008642
Tobin Ehlis3b780662015-05-28 12:11:26 -06008643 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008644 err =
8645 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008646 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008647
Tony Barboureb254902015-07-15 12:50:33 -06008648 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008649 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008650 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008651 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008652 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8653 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008654
Tony Barboureb254902015-07-15 12:50:33 -06008655 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8656 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8657 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008658 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008659 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008660
Tobin Ehlis3b780662015-05-28 12:11:26 -06008661 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008662 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8663 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008664 ASSERT_VK_SUCCESS(err);
8665
8666 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008667 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008668 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008669 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008670 alloc_info.descriptorPool = ds_pool;
8671 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8673 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008674 ASSERT_VK_SUCCESS(err);
8675
Tony Barboureb254902015-07-15 12:50:33 -06008676 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008677 pipe_ms_state_ci.sType =
8678 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8679 pipe_ms_state_ci.pNext = NULL;
8680 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8681 pipe_ms_state_ci.sampleShadingEnable = 0;
8682 pipe_ms_state_ci.minSampleShading = 1.0;
8683 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008684
Tony Barboureb254902015-07-15 12:50:33 -06008685 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008686 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8687 pipeline_layout_ci.pNext = NULL;
8688 pipeline_layout_ci.setLayoutCount = 1;
8689 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008690
8691 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008692 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8693 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008694 ASSERT_VK_SUCCESS(err);
8695
Karl Schultz6addd812016-02-02 17:17:23 -07008696 VkShaderObj vs(m_device, bindStateVertShaderText,
8697 VK_SHADER_STAGE_VERTEX_BIT, this);
8698 VkShaderObj fs(m_device, bindStateFragShaderText,
8699 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008700 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008701 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008702 VkPipelineObj pipe(m_device);
8703 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008704 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008705 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008706 pipe.SetMSAA(&pipe_ms_state_ci);
8707 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008708
Tony Barbourfe3351b2015-07-28 10:17:20 -06008709 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008710 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8711 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008712
Mark Young29927482016-05-04 14:38:51 -06008713 // Render triangle (the error should trigger on the attempt to draw).
8714 Draw(3, 1, 0, 0);
8715
8716 // Finalize recording of the command buffer
8717 EndCommandBuffer();
8718
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008719 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008720
Chia-I Wuf7458c52015-10-26 21:10:41 +08008721 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8723 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008724}
Mark Young29927482016-05-04 14:38:51 -06008725
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008726TEST_F(VkLayerTest, RenderPassIncompatible) {
8727 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8728 "Initial case is drawing with an active renderpass that's "
8729 "not compatible with the bound PSO's creation renderpass");
8730 VkResult err;
8731
8732 ASSERT_NO_FATAL_FAILURE(InitState());
8733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8734
8735 VkDescriptorSetLayoutBinding dsl_binding = {};
8736 dsl_binding.binding = 0;
8737 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8738 dsl_binding.descriptorCount = 1;
8739 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8740 dsl_binding.pImmutableSamplers = NULL;
8741
8742 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8743 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8744 ds_layout_ci.pNext = NULL;
8745 ds_layout_ci.bindingCount = 1;
8746 ds_layout_ci.pBindings = &dsl_binding;
8747
8748 VkDescriptorSetLayout ds_layout;
8749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8750 &ds_layout);
8751 ASSERT_VK_SUCCESS(err);
8752
8753 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8754 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8755 pipeline_layout_ci.pNext = NULL;
8756 pipeline_layout_ci.setLayoutCount = 1;
8757 pipeline_layout_ci.pSetLayouts = &ds_layout;
8758
8759 VkPipelineLayout pipeline_layout;
8760 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8761 &pipeline_layout);
8762 ASSERT_VK_SUCCESS(err);
8763
8764 VkShaderObj vs(m_device, bindStateVertShaderText,
8765 VK_SHADER_STAGE_VERTEX_BIT, this);
8766 VkShaderObj fs(m_device, bindStateFragShaderText,
8767 VK_SHADER_STAGE_FRAGMENT_BIT,
8768 this); // We shouldn't need a fragment shader
8769 // but add it to be able to run on more devices
8770 // Create a renderpass that will be incompatible with default renderpass
8771 VkAttachmentReference attach = {};
8772 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8773 VkAttachmentReference color_att = {};
8774 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8775 VkSubpassDescription subpass = {};
8776 subpass.inputAttachmentCount = 1;
8777 subpass.pInputAttachments = &attach;
8778 subpass.colorAttachmentCount = 1;
8779 subpass.pColorAttachments = &color_att;
8780 VkRenderPassCreateInfo rpci = {};
8781 rpci.subpassCount = 1;
8782 rpci.pSubpasses = &subpass;
8783 rpci.attachmentCount = 1;
8784 VkAttachmentDescription attach_desc = {};
8785 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8786 // Format incompatible with PSO RP color attach format RGBA8_UNORM
8787 attach_desc.format = VK_FORMAT_UNDEFINED;
8788 rpci.pAttachments = &attach_desc;
8789 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8790 VkRenderPass rp;
8791 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8792 VkPipelineObj pipe(m_device);
8793 pipe.AddShader(&vs);
8794 pipe.AddShader(&fs);
8795 pipe.AddColorAttachment();
8796 VkViewport view_port = {};
8797 m_viewports.push_back(view_port);
8798 pipe.SetViewport(m_viewports);
8799 VkRect2D rect = {};
8800 m_scissors.push_back(rect);
8801 pipe.SetScissor(m_scissors);
8802 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8803
8804 VkCommandBufferInheritanceInfo cbii = {};
8805 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8806 cbii.renderPass = rp;
8807 cbii.subpass = 0;
8808 VkCommandBufferBeginInfo cbbi = {};
8809 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8810 cbbi.pInheritanceInfo = &cbii;
8811 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
8812 VkRenderPassBeginInfo rpbi = {};
8813 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8814 rpbi.framebuffer = m_framebuffer;
8815 rpbi.renderPass = rp;
8816 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
8817 VK_SUBPASS_CONTENTS_INLINE);
8818 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8819 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8820
8821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8822 " is incompatible w/ gfx pipeline ");
8823 // Render triangle (the error should trigger on the attempt to draw).
8824 Draw(3, 1, 0, 0);
8825
8826 // Finalize recording of the command buffer
8827 EndCommandBuffer();
8828
8829 m_errorMonitor->VerifyFound();
8830
8831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8833 vkDestroyRenderPass(m_device->device(), rp, NULL);
8834}
8835
Mark Youngc89c6312016-03-31 16:03:20 -06008836TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8837 // Create Pipeline where the number of blend attachments doesn't match the
8838 // number of color attachments. In this case, we don't add any color
8839 // blend attachments even though we have a color attachment.
8840 VkResult err;
8841
8842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008843 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008844
8845 ASSERT_NO_FATAL_FAILURE(InitState());
8846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8847 VkDescriptorPoolSize ds_type_count = {};
8848 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8849 ds_type_count.descriptorCount = 1;
8850
8851 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8852 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8853 ds_pool_ci.pNext = NULL;
8854 ds_pool_ci.maxSets = 1;
8855 ds_pool_ci.poolSizeCount = 1;
8856 ds_pool_ci.pPoolSizes = &ds_type_count;
8857
8858 VkDescriptorPool ds_pool;
8859 err =
8860 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8861 ASSERT_VK_SUCCESS(err);
8862
8863 VkDescriptorSetLayoutBinding dsl_binding = {};
8864 dsl_binding.binding = 0;
8865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8866 dsl_binding.descriptorCount = 1;
8867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8868 dsl_binding.pImmutableSamplers = NULL;
8869
8870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8872 ds_layout_ci.pNext = NULL;
8873 ds_layout_ci.bindingCount = 1;
8874 ds_layout_ci.pBindings = &dsl_binding;
8875
8876 VkDescriptorSetLayout ds_layout;
8877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8878 &ds_layout);
8879 ASSERT_VK_SUCCESS(err);
8880
8881 VkDescriptorSet descriptorSet;
8882 VkDescriptorSetAllocateInfo alloc_info = {};
8883 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8884 alloc_info.descriptorSetCount = 1;
8885 alloc_info.descriptorPool = ds_pool;
8886 alloc_info.pSetLayouts = &ds_layout;
8887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8888 &descriptorSet);
8889 ASSERT_VK_SUCCESS(err);
8890
8891 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8892 pipe_ms_state_ci.sType =
8893 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8894 pipe_ms_state_ci.pNext = NULL;
8895 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8896 pipe_ms_state_ci.sampleShadingEnable = 0;
8897 pipe_ms_state_ci.minSampleShading = 1.0;
8898 pipe_ms_state_ci.pSampleMask = NULL;
8899
8900 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8901 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8902 pipeline_layout_ci.pNext = NULL;
8903 pipeline_layout_ci.setLayoutCount = 1;
8904 pipeline_layout_ci.pSetLayouts = &ds_layout;
8905
8906 VkPipelineLayout pipeline_layout;
8907 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8908 &pipeline_layout);
8909 ASSERT_VK_SUCCESS(err);
8910
8911 VkShaderObj vs(m_device, bindStateVertShaderText,
8912 VK_SHADER_STAGE_VERTEX_BIT, this);
8913 VkShaderObj fs(m_device, bindStateFragShaderText,
8914 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008915 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06008916 // but add it to be able to run on more devices
8917 VkPipelineObj pipe(m_device);
8918 pipe.AddShader(&vs);
8919 pipe.AddShader(&fs);
8920 pipe.SetMSAA(&pipe_ms_state_ci);
8921 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8922
8923 BeginCommandBuffer();
8924 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8925 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8926
Mark Young29927482016-05-04 14:38:51 -06008927 // Render triangle (the error should trigger on the attempt to draw).
8928 Draw(3, 1, 0, 0);
8929
8930 // Finalize recording of the command buffer
8931 EndCommandBuffer();
8932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008933 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06008934
8935 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8937 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8938}
Mark Young29927482016-05-04 14:38:51 -06008939
Mark Muellerd4914412016-06-13 17:52:06 -06008940TEST_F(VkLayerTest, MissingClearAttachment) {
8941 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
8942 "structure passed to vkCmdClearAttachments");
8943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8944 "vkCmdClearAttachments() attachment index 1 not found in attachment "
8945 "reference array of active subpass 0");
8946
8947 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
8948 m_errorMonitor->VerifyFound();
8949}
8950
Karl Schultz6addd812016-02-02 17:17:23 -07008951TEST_F(VkLayerTest, ClearCmdNoDraw) {
8952 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
8953 // to issuing a Draw
8954 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008955
Karl Schultz6addd812016-02-02 17:17:23 -07008956 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07008957 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008958 "vkCmdClearAttachments() issued on CB object ");
8959
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008960 ASSERT_NO_FATAL_FAILURE(InitState());
8961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008962
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008963 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008964 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8965 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008966
8967 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008968 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8969 ds_pool_ci.pNext = NULL;
8970 ds_pool_ci.maxSets = 1;
8971 ds_pool_ci.poolSizeCount = 1;
8972 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008973
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008974 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008975 err =
8976 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008977 ASSERT_VK_SUCCESS(err);
8978
Tony Barboureb254902015-07-15 12:50:33 -06008979 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008980 dsl_binding.binding = 0;
8981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8982 dsl_binding.descriptorCount = 1;
8983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8984 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008985
Tony Barboureb254902015-07-15 12:50:33 -06008986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8988 ds_layout_ci.pNext = NULL;
8989 ds_layout_ci.bindingCount = 1;
8990 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008991
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008992 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8994 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008995 ASSERT_VK_SUCCESS(err);
8996
8997 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008998 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009000 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009001 alloc_info.descriptorPool = ds_pool;
9002 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009003 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9004 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009005 ASSERT_VK_SUCCESS(err);
9006
Tony Barboureb254902015-07-15 12:50:33 -06009007 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009008 pipe_ms_state_ci.sType =
9009 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9010 pipe_ms_state_ci.pNext = NULL;
9011 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9012 pipe_ms_state_ci.sampleShadingEnable = 0;
9013 pipe_ms_state_ci.minSampleShading = 1.0;
9014 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009015
Tony Barboureb254902015-07-15 12:50:33 -06009016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9018 pipeline_layout_ci.pNext = NULL;
9019 pipeline_layout_ci.setLayoutCount = 1;
9020 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009021
9022 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9024 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009025 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009026
Karl Schultz6addd812016-02-02 17:17:23 -07009027 VkShaderObj vs(m_device, bindStateVertShaderText,
9028 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009029 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009030 // on more devices
9031 VkShaderObj fs(m_device, bindStateFragShaderText,
9032 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009033
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009034 VkPipelineObj pipe(m_device);
9035 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009036 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009037 pipe.SetMSAA(&pipe_ms_state_ci);
9038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009039
9040 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009041
Karl Schultz6addd812016-02-02 17:17:23 -07009042 // Main thing we care about for this test is that the VkImage obj we're
9043 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009044 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009045 VkClearAttachment color_attachment;
9046 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9047 color_attachment.clearValue.color.float32[0] = 1.0;
9048 color_attachment.clearValue.color.float32[1] = 1.0;
9049 color_attachment.clearValue.color.float32[2] = 1.0;
9050 color_attachment.clearValue.color.float32[3] = 1.0;
9051 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009052 VkClearRect clear_rect = {
9053 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009054
Karl Schultz6addd812016-02-02 17:17:23 -07009055 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9056 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009057
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009058 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009059
Chia-I Wuf7458c52015-10-26 21:10:41 +08009060 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9061 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9062 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009063}
9064
Karl Schultz6addd812016-02-02 17:17:23 -07009065TEST_F(VkLayerTest, VtxBufferBadIndex) {
9066 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009067
Karl Schultz6addd812016-02-02 17:17:23 -07009068 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009069 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009070 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009071
Tobin Ehlis502480b2015-06-24 15:53:07 -06009072 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009073 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009075
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009076 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009077 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9078 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009079
9080 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009081 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9082 ds_pool_ci.pNext = NULL;
9083 ds_pool_ci.maxSets = 1;
9084 ds_pool_ci.poolSizeCount = 1;
9085 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009086
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009087 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009088 err =
9089 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009090 ASSERT_VK_SUCCESS(err);
9091
Tony Barboureb254902015-07-15 12:50:33 -06009092 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009093 dsl_binding.binding = 0;
9094 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9095 dsl_binding.descriptorCount = 1;
9096 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9097 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009098
Tony Barboureb254902015-07-15 12:50:33 -06009099 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009100 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9101 ds_layout_ci.pNext = NULL;
9102 ds_layout_ci.bindingCount = 1;
9103 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009104
Tobin Ehlis502480b2015-06-24 15:53:07 -06009105 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009106 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9107 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009108 ASSERT_VK_SUCCESS(err);
9109
9110 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009111 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009112 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009113 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009114 alloc_info.descriptorPool = ds_pool;
9115 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009116 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9117 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009118 ASSERT_VK_SUCCESS(err);
9119
Tony Barboureb254902015-07-15 12:50:33 -06009120 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009121 pipe_ms_state_ci.sType =
9122 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9123 pipe_ms_state_ci.pNext = NULL;
9124 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9125 pipe_ms_state_ci.sampleShadingEnable = 0;
9126 pipe_ms_state_ci.minSampleShading = 1.0;
9127 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009128
Tony Barboureb254902015-07-15 12:50:33 -06009129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9131 pipeline_layout_ci.pNext = NULL;
9132 pipeline_layout_ci.setLayoutCount = 1;
9133 pipeline_layout_ci.pSetLayouts = &ds_layout;
9134 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009135
Karl Schultz6addd812016-02-02 17:17:23 -07009136 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9137 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009138 ASSERT_VK_SUCCESS(err);
9139
Karl Schultz6addd812016-02-02 17:17:23 -07009140 VkShaderObj vs(m_device, bindStateVertShaderText,
9141 VK_SHADER_STAGE_VERTEX_BIT, this);
9142 VkShaderObj fs(m_device, bindStateFragShaderText,
9143 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009144 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009145 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009146 VkPipelineObj pipe(m_device);
9147 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009148 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009149 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009150 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009151 pipe.SetViewport(m_viewports);
9152 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009153 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009154
9155 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009156 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9157 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009158 // Don't care about actual data, just need to get to draw to flag error
9159 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009160 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9161 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009162 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009163 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009164
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009165 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009166
Chia-I Wuf7458c52015-10-26 21:10:41 +08009167 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009170}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009171// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9172TEST_F(VkLayerTest, InvalidImageLayout) {
9173 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9174 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9175 "images in the wrong layout when they're copied or transitioned.");
9176 // 3 in ValidateCmdBufImageLayouts
9177 // * -1 Attempt to submit cmd buf w/ deleted image
9178 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9179 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9180 m_errorMonitor->SetDesiredFailureMsg(
9181 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9182 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9183
9184 ASSERT_NO_FATAL_FAILURE(InitState());
9185 // Create src & dst images to use for copy operations
9186 VkImage src_image;
9187 VkImage dst_image;
9188
9189 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9190 const int32_t tex_width = 32;
9191 const int32_t tex_height = 32;
9192
9193 VkImageCreateInfo image_create_info = {};
9194 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9195 image_create_info.pNext = NULL;
9196 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9197 image_create_info.format = tex_format;
9198 image_create_info.extent.width = tex_width;
9199 image_create_info.extent.height = tex_height;
9200 image_create_info.extent.depth = 1;
9201 image_create_info.mipLevels = 1;
9202 image_create_info.arrayLayers = 4;
9203 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9204 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9205 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9206 image_create_info.flags = 0;
9207
9208 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9209 ASSERT_VK_SUCCESS(err);
9210 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9211 ASSERT_VK_SUCCESS(err);
9212
9213 BeginCommandBuffer();
9214 VkImageCopy copyRegion;
9215 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9216 copyRegion.srcSubresource.mipLevel = 0;
9217 copyRegion.srcSubresource.baseArrayLayer = 0;
9218 copyRegion.srcSubresource.layerCount = 1;
9219 copyRegion.srcOffset.x = 0;
9220 copyRegion.srcOffset.y = 0;
9221 copyRegion.srcOffset.z = 0;
9222 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9223 copyRegion.dstSubresource.mipLevel = 0;
9224 copyRegion.dstSubresource.baseArrayLayer = 0;
9225 copyRegion.dstSubresource.layerCount = 1;
9226 copyRegion.dstOffset.x = 0;
9227 copyRegion.dstOffset.y = 0;
9228 copyRegion.dstOffset.z = 0;
9229 copyRegion.extent.width = 1;
9230 copyRegion.extent.height = 1;
9231 copyRegion.extent.depth = 1;
9232 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9233 m_errorMonitor->VerifyFound();
9234 // Now cause error due to src image layout changing
9235 m_errorMonitor->SetDesiredFailureMsg(
9236 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9237 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9238 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9239 m_errorMonitor->VerifyFound();
9240 // Final src error is due to bad layout type
9241 m_errorMonitor->SetDesiredFailureMsg(
9242 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9243 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9244 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9245 m_errorMonitor->VerifyFound();
9246 // Now verify same checks for dst
9247 m_errorMonitor->SetDesiredFailureMsg(
9248 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9249 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9250 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9251 m_errorMonitor->VerifyFound();
9252 // Now cause error due to src image layout changing
9253 m_errorMonitor->SetDesiredFailureMsg(
9254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9255 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9256 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9257 m_errorMonitor->VerifyFound();
9258 m_errorMonitor->SetDesiredFailureMsg(
9259 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9260 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9261 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9262 m_errorMonitor->VerifyFound();
9263 // Now cause error due to bad image layout transition in PipelineBarrier
9264 VkImageMemoryBarrier image_barrier[1] = {};
9265 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9266 image_barrier[0].image = src_image;
9267 image_barrier[0].subresourceRange.layerCount = 2;
9268 image_barrier[0].subresourceRange.levelCount = 2;
9269 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9270 m_errorMonitor->SetDesiredFailureMsg(
9271 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9272 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9273 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9274 m_errorMonitor->VerifyFound();
9275
9276 // Finally some layout errors at RenderPass create time
9277 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9278 VkAttachmentReference attach = {};
9279 // perf warning for GENERAL layout w/ non-DS input attachment
9280 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9281 VkSubpassDescription subpass = {};
9282 subpass.inputAttachmentCount = 1;
9283 subpass.pInputAttachments = &attach;
9284 VkRenderPassCreateInfo rpci = {};
9285 rpci.subpassCount = 1;
9286 rpci.pSubpasses = &subpass;
9287 rpci.attachmentCount = 1;
9288 VkAttachmentDescription attach_desc = {};
9289 attach_desc.format = VK_FORMAT_UNDEFINED;
9290 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009291 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009292 VkRenderPass rp;
9293 m_errorMonitor->SetDesiredFailureMsg(
9294 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9295 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9296 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9297 m_errorMonitor->VerifyFound();
9298 // error w/ non-general layout
9299 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9300
9301 m_errorMonitor->SetDesiredFailureMsg(
9302 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9303 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9304 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9305 m_errorMonitor->VerifyFound();
9306 subpass.inputAttachmentCount = 0;
9307 subpass.colorAttachmentCount = 1;
9308 subpass.pColorAttachments = &attach;
9309 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9310 // perf warning for GENERAL layout on color attachment
9311 m_errorMonitor->SetDesiredFailureMsg(
9312 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9313 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9314 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9315 m_errorMonitor->VerifyFound();
9316 // error w/ non-color opt or GENERAL layout for color attachment
9317 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9318 m_errorMonitor->SetDesiredFailureMsg(
9319 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9320 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9321 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9322 m_errorMonitor->VerifyFound();
9323 subpass.colorAttachmentCount = 0;
9324 subpass.pDepthStencilAttachment = &attach;
9325 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9326 // perf warning for GENERAL layout on DS attachment
9327 m_errorMonitor->SetDesiredFailureMsg(
9328 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9329 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9330 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9331 m_errorMonitor->VerifyFound();
9332 // error w/ non-ds opt or GENERAL layout for color attachment
9333 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9334 m_errorMonitor->SetDesiredFailureMsg(
9335 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9336 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9337 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9338 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009339 // For this error we need a valid renderpass so create default one
9340 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9341 attach.attachment = 0;
9342 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9343 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9344 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9345 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9346 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9347 // Can't do a CLEAR load on READ_ONLY initialLayout
9348 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9349 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9350 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9352 " with invalid first layout "
9353 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9354 "ONLY_OPTIMAL");
9355 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9356 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009357
9358 vkDestroyImage(m_device->device(), src_image, NULL);
9359 vkDestroyImage(m_device->device(), dst_image, NULL);
9360}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009361#endif // DRAW_STATE_TESTS
9362
Tobin Ehlis0788f522015-05-26 16:11:58 -06009363#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009364#if GTEST_IS_THREADSAFE
9365struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009366 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009367 VkEvent event;
9368 bool bailout;
9369};
9370
Karl Schultz6addd812016-02-02 17:17:23 -07009371extern "C" void *AddToCommandBuffer(void *arg) {
9372 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009373
Karl Schultz6addd812016-02-02 17:17:23 -07009374 for (int i = 0; i < 10000; i++) {
9375 vkCmdSetEvent(data->commandBuffer, data->event,
9376 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009377 if (data->bailout) {
9378 break;
9379 }
9380 }
9381 return NULL;
9382}
9383
Karl Schultz6addd812016-02-02 17:17:23 -07009384TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009385 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009386
Karl Schultz6addd812016-02-02 17:17:23 -07009387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009389
Mike Stroyanaccf7692015-05-12 16:00:45 -06009390 ASSERT_NO_FATAL_FAILURE(InitState());
9391 ASSERT_NO_FATAL_FAILURE(InitViewport());
9392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9393
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009394 // Calls AllocateCommandBuffers
9395 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009396
9397 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009398 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009399
9400 VkEventCreateInfo event_info;
9401 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009402 VkResult err;
9403
9404 memset(&event_info, 0, sizeof(event_info));
9405 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9406
Chia-I Wuf7458c52015-10-26 21:10:41 +08009407 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009408 ASSERT_VK_SUCCESS(err);
9409
Mike Stroyanaccf7692015-05-12 16:00:45 -06009410 err = vkResetEvent(device(), event);
9411 ASSERT_VK_SUCCESS(err);
9412
9413 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009414 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009415 data.event = event;
9416 data.bailout = false;
9417 m_errorMonitor->SetBailout(&data.bailout);
9418 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009419 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009420 // Add many entries to command buffer from this thread at the same time.
9421 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009422
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009423 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009424 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009425
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009426 m_errorMonitor->SetBailout(NULL);
9427
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009428 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009429
Chia-I Wuf7458c52015-10-26 21:10:41 +08009430 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009431}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009432#endif // GTEST_IS_THREADSAFE
9433#endif // THREADING_TESTS
9434
Chris Forbes9f7ff632015-05-25 11:13:08 +12009435#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009436TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009438 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009439
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009440 ASSERT_NO_FATAL_FAILURE(InitState());
9441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9442
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009443 VkShaderModule module;
9444 VkShaderModuleCreateInfo moduleCreateInfo;
9445 struct icd_spv_header spv;
9446
9447 spv.magic = ICD_SPV_MAGIC;
9448 spv.version = ICD_SPV_VERSION;
9449 spv.gen_magic = 0;
9450
9451 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9452 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009453 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009454 moduleCreateInfo.codeSize = 4;
9455 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009456 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009458 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009459}
9460
Karl Schultz6addd812016-02-02 17:17:23 -07009461TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009463 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009464
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009465 ASSERT_NO_FATAL_FAILURE(InitState());
9466 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9467
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009468 VkShaderModule module;
9469 VkShaderModuleCreateInfo moduleCreateInfo;
9470 struct icd_spv_header spv;
9471
9472 spv.magic = ~ICD_SPV_MAGIC;
9473 spv.version = ICD_SPV_VERSION;
9474 spv.gen_magic = 0;
9475
9476 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9477 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009478 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009479 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9480 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009481 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009483 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009484}
9485
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009486#if 0
9487// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009488TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009490 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009491
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009492 ASSERT_NO_FATAL_FAILURE(InitState());
9493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9494
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009495 VkShaderModule module;
9496 VkShaderModuleCreateInfo moduleCreateInfo;
9497 struct icd_spv_header spv;
9498
9499 spv.magic = ICD_SPV_MAGIC;
9500 spv.version = ~ICD_SPV_VERSION;
9501 spv.gen_magic = 0;
9502
9503 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9504 moduleCreateInfo.pNext = NULL;
9505
Karl Schultz6addd812016-02-02 17:17:23 -07009506 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009507 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9508 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009509 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009511 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009512}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009513#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009514
Karl Schultz6addd812016-02-02 17:17:23 -07009515TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009517 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009518
Chris Forbes9f7ff632015-05-25 11:13:08 +12009519 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009521
9522 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009523 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009524 "\n"
9525 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009526 "out gl_PerVertex {\n"
9527 " vec4 gl_Position;\n"
9528 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009529 "void main(){\n"
9530 " gl_Position = vec4(1);\n"
9531 " x = 0;\n"
9532 "}\n";
9533 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009534 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009535 "\n"
9536 "layout(location=0) out vec4 color;\n"
9537 "void main(){\n"
9538 " color = vec4(1);\n"
9539 "}\n";
9540
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009543
9544 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009545 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009546 pipe.AddShader(&vs);
9547 pipe.AddShader(&fs);
9548
Chris Forbes9f7ff632015-05-25 11:13:08 +12009549 VkDescriptorSetObj descriptorSet(m_device);
9550 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009551 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009552
Tony Barbour5781e8f2015-08-04 16:23:11 -06009553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009554
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009555 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009556}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009557
Karl Schultz6addd812016-02-02 17:17:23 -07009558TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009560 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009561
Chris Forbes59cb88d2015-05-25 11:13:13 +12009562 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009564
9565 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009566 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009567 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009568 "out gl_PerVertex {\n"
9569 " vec4 gl_Position;\n"
9570 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009571 "void main(){\n"
9572 " gl_Position = vec4(1);\n"
9573 "}\n";
9574 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009575 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009576 "\n"
9577 "layout(location=0) in float x;\n"
9578 "layout(location=0) out vec4 color;\n"
9579 "void main(){\n"
9580 " color = vec4(x);\n"
9581 "}\n";
9582
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009583 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9584 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009585
9586 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009587 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009588 pipe.AddShader(&vs);
9589 pipe.AddShader(&fs);
9590
Chris Forbes59cb88d2015-05-25 11:13:13 +12009591 VkDescriptorSetObj descriptorSet(m_device);
9592 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009593 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009594
Tony Barbour5781e8f2015-08-04 16:23:11 -06009595 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009596
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009597 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009598}
9599
Karl Schultz6addd812016-02-02 17:17:23 -07009600TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009602 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009603
9604 ASSERT_NO_FATAL_FAILURE(InitState());
9605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9606
9607 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009608 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009609 "\n"
9610 "out gl_PerVertex {\n"
9611 " vec4 gl_Position;\n"
9612 "};\n"
9613 "void main(){\n"
9614 " gl_Position = vec4(1);\n"
9615 "}\n";
9616 char const *fsSource =
9617 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009618 "\n"
9619 "in block { layout(location=0) float x; } ins;\n"
9620 "layout(location=0) out vec4 color;\n"
9621 "void main(){\n"
9622 " color = vec4(ins.x);\n"
9623 "}\n";
9624
9625 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9626 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9627
9628 VkPipelineObj pipe(m_device);
9629 pipe.AddColorAttachment();
9630 pipe.AddShader(&vs);
9631 pipe.AddShader(&fs);
9632
9633 VkDescriptorSetObj descriptorSet(m_device);
9634 descriptorSet.AppendDummy();
9635 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9636
9637 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9638
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009639 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009640}
9641
Karl Schultz6addd812016-02-02 17:17:23 -07009642TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009644 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009645 "output arr[2] of float32' vs 'ptr to "
9646 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009647
9648 ASSERT_NO_FATAL_FAILURE(InitState());
9649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9650
9651 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009652 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009653 "\n"
9654 "layout(location=0) out float x[2];\n"
9655 "out gl_PerVertex {\n"
9656 " vec4 gl_Position;\n"
9657 "};\n"
9658 "void main(){\n"
9659 " x[0] = 0; x[1] = 0;\n"
9660 " gl_Position = vec4(1);\n"
9661 "}\n";
9662 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009663 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009664 "\n"
9665 "layout(location=0) in float x[3];\n"
9666 "layout(location=0) out vec4 color;\n"
9667 "void main(){\n"
9668 " color = vec4(x[0] + x[1] + x[2]);\n"
9669 "}\n";
9670
9671 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9672 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9673
9674 VkPipelineObj pipe(m_device);
9675 pipe.AddColorAttachment();
9676 pipe.AddShader(&vs);
9677 pipe.AddShader(&fs);
9678
9679 VkDescriptorSetObj descriptorSet(m_device);
9680 descriptorSet.AppendDummy();
9681 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9682
9683 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9684
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009685 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009686}
9687
Karl Schultz6addd812016-02-02 17:17:23 -07009688TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009690 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009691
Chris Forbesb56af562015-05-25 11:13:17 +12009692 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009694
9695 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009696 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009697 "\n"
9698 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009699 "out gl_PerVertex {\n"
9700 " vec4 gl_Position;\n"
9701 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009702 "void main(){\n"
9703 " x = 0;\n"
9704 " gl_Position = vec4(1);\n"
9705 "}\n";
9706 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009707 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009708 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009709 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009710 "layout(location=0) out vec4 color;\n"
9711 "void main(){\n"
9712 " color = vec4(x);\n"
9713 "}\n";
9714
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009717
9718 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009719 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009720 pipe.AddShader(&vs);
9721 pipe.AddShader(&fs);
9722
Chris Forbesb56af562015-05-25 11:13:17 +12009723 VkDescriptorSetObj descriptorSet(m_device);
9724 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009726
Tony Barbour5781e8f2015-08-04 16:23:11 -06009727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009728
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009729 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009730}
9731
Karl Schultz6addd812016-02-02 17:17:23 -07009732TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009734 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009735
9736 ASSERT_NO_FATAL_FAILURE(InitState());
9737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9738
9739 char const *vsSource =
9740 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009741 "\n"
9742 "out block { layout(location=0) int x; } outs;\n"
9743 "out gl_PerVertex {\n"
9744 " vec4 gl_Position;\n"
9745 "};\n"
9746 "void main(){\n"
9747 " outs.x = 0;\n"
9748 " gl_Position = vec4(1);\n"
9749 "}\n";
9750 char const *fsSource =
9751 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009752 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009753 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009754 "layout(location=0) out vec4 color;\n"
9755 "void main(){\n"
9756 " color = vec4(ins.x);\n"
9757 "}\n";
9758
9759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9761
9762 VkPipelineObj pipe(m_device);
9763 pipe.AddColorAttachment();
9764 pipe.AddShader(&vs);
9765 pipe.AddShader(&fs);
9766
9767 VkDescriptorSetObj descriptorSet(m_device);
9768 descriptorSet.AppendDummy();
9769 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9770
9771 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9772
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009773 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009774}
9775
9776TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9778 "location 0.0 which is not written by vertex shader");
9779
9780 ASSERT_NO_FATAL_FAILURE(InitState());
9781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9782
9783 char const *vsSource =
9784 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009785 "\n"
9786 "out block { layout(location=1) float x; } outs;\n"
9787 "out gl_PerVertex {\n"
9788 " vec4 gl_Position;\n"
9789 "};\n"
9790 "void main(){\n"
9791 " outs.x = 0;\n"
9792 " gl_Position = vec4(1);\n"
9793 "}\n";
9794 char const *fsSource =
9795 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009796 "\n"
9797 "in block { layout(location=0) float x; } ins;\n"
9798 "layout(location=0) out vec4 color;\n"
9799 "void main(){\n"
9800 " color = vec4(ins.x);\n"
9801 "}\n";
9802
9803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9805
9806 VkPipelineObj pipe(m_device);
9807 pipe.AddColorAttachment();
9808 pipe.AddShader(&vs);
9809 pipe.AddShader(&fs);
9810
9811 VkDescriptorSetObj descriptorSet(m_device);
9812 descriptorSet.AppendDummy();
9813 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9814
9815 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009817 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009818}
9819
9820TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9822 "location 0.1 which is not written by vertex shader");
9823
9824 ASSERT_NO_FATAL_FAILURE(InitState());
9825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9826
9827 char const *vsSource =
9828 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009829 "\n"
9830 "out block { layout(location=0, component=0) float x; } outs;\n"
9831 "out gl_PerVertex {\n"
9832 " vec4 gl_Position;\n"
9833 "};\n"
9834 "void main(){\n"
9835 " outs.x = 0;\n"
9836 " gl_Position = vec4(1);\n"
9837 "}\n";
9838 char const *fsSource =
9839 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009840 "\n"
9841 "in block { layout(location=0, component=1) float x; } ins;\n"
9842 "layout(location=0) out vec4 color;\n"
9843 "void main(){\n"
9844 " color = vec4(ins.x);\n"
9845 "}\n";
9846
9847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9849
9850 VkPipelineObj pipe(m_device);
9851 pipe.AddColorAttachment();
9852 pipe.AddShader(&vs);
9853 pipe.AddShader(&fs);
9854
9855 VkDescriptorSetObj descriptorSet(m_device);
9856 descriptorSet.AppendDummy();
9857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9858
9859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9860
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009861 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009862}
9863
Karl Schultz6addd812016-02-02 17:17:23 -07009864TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009866 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009867
Chris Forbesde136e02015-05-25 11:13:28 +12009868 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12009870
9871 VkVertexInputBindingDescription input_binding;
9872 memset(&input_binding, 0, sizeof(input_binding));
9873
9874 VkVertexInputAttributeDescription input_attrib;
9875 memset(&input_attrib, 0, sizeof(input_attrib));
9876 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9877
9878 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009879 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009880 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009881 "out gl_PerVertex {\n"
9882 " vec4 gl_Position;\n"
9883 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009884 "void main(){\n"
9885 " gl_Position = vec4(1);\n"
9886 "}\n";
9887 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009888 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009889 "\n"
9890 "layout(location=0) out vec4 color;\n"
9891 "void main(){\n"
9892 " color = vec4(1);\n"
9893 "}\n";
9894
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009895 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9896 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12009897
9898 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009899 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12009900 pipe.AddShader(&vs);
9901 pipe.AddShader(&fs);
9902
9903 pipe.AddVertexInputBindings(&input_binding, 1);
9904 pipe.AddVertexInputAttribs(&input_attrib, 1);
9905
Chris Forbesde136e02015-05-25 11:13:28 +12009906 VkDescriptorSetObj descriptorSet(m_device);
9907 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009908 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12009909
Tony Barbour5781e8f2015-08-04 16:23:11 -06009910 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12009911
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009912 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12009913}
9914
Karl Schultz6addd812016-02-02 17:17:23 -07009915TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009917 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13009918
9919 ASSERT_NO_FATAL_FAILURE(InitState());
9920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9921
9922 VkVertexInputBindingDescription input_binding;
9923 memset(&input_binding, 0, sizeof(input_binding));
9924
9925 VkVertexInputAttributeDescription input_attrib;
9926 memset(&input_attrib, 0, sizeof(input_attrib));
9927 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9928
9929 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009930 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009931 "\n"
9932 "layout(location=1) in float x;\n"
9933 "out gl_PerVertex {\n"
9934 " vec4 gl_Position;\n"
9935 "};\n"
9936 "void main(){\n"
9937 " gl_Position = vec4(x);\n"
9938 "}\n";
9939 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009940 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009941 "\n"
9942 "layout(location=0) out vec4 color;\n"
9943 "void main(){\n"
9944 " color = vec4(1);\n"
9945 "}\n";
9946
9947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9949
9950 VkPipelineObj pipe(m_device);
9951 pipe.AddColorAttachment();
9952 pipe.AddShader(&vs);
9953 pipe.AddShader(&fs);
9954
9955 pipe.AddVertexInputBindings(&input_binding, 1);
9956 pipe.AddVertexInputAttribs(&input_attrib, 1);
9957
9958 VkDescriptorSetObj descriptorSet(m_device);
9959 descriptorSet.AppendDummy();
9960 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9961
9962 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9963
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009964 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13009965}
9966
Karl Schultz6addd812016-02-02 17:17:23 -07009967TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
9968 m_errorMonitor->SetDesiredFailureMsg(
9969 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009970 "VS consumes input at location 0 but not provided");
9971
Chris Forbes62e8e502015-05-25 11:13:29 +12009972 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12009974
9975 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009976 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009977 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009978 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07009979 "out gl_PerVertex {\n"
9980 " vec4 gl_Position;\n"
9981 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009982 "void main(){\n"
9983 " gl_Position = x;\n"
9984 "}\n";
9985 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009986 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009987 "\n"
9988 "layout(location=0) out vec4 color;\n"
9989 "void main(){\n"
9990 " color = vec4(1);\n"
9991 "}\n";
9992
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9994 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12009995
9996 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009997 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12009998 pipe.AddShader(&vs);
9999 pipe.AddShader(&fs);
10000
Chris Forbes62e8e502015-05-25 11:13:29 +120010001 VkDescriptorSetObj descriptorSet(m_device);
10002 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010003 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010004
Tony Barbour5781e8f2015-08-04 16:23:11 -060010005 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010006
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010007 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010008}
10009
Karl Schultz6addd812016-02-02 17:17:23 -070010010TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10011 m_errorMonitor->SetDesiredFailureMsg(
10012 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010013 "location 0 does not match VS input type");
10014
Chris Forbesc97d98e2015-05-25 11:13:31 +120010015 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010017
10018 VkVertexInputBindingDescription input_binding;
10019 memset(&input_binding, 0, sizeof(input_binding));
10020
10021 VkVertexInputAttributeDescription input_attrib;
10022 memset(&input_attrib, 0, sizeof(input_attrib));
10023 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10024
10025 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010026 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010027 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010028 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010029 "out gl_PerVertex {\n"
10030 " vec4 gl_Position;\n"
10031 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010032 "void main(){\n"
10033 " gl_Position = vec4(x);\n"
10034 "}\n";
10035 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010036 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010037 "\n"
10038 "layout(location=0) out vec4 color;\n"
10039 "void main(){\n"
10040 " color = vec4(1);\n"
10041 "}\n";
10042
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010043 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10044 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010045
10046 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010047 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010048 pipe.AddShader(&vs);
10049 pipe.AddShader(&fs);
10050
10051 pipe.AddVertexInputBindings(&input_binding, 1);
10052 pipe.AddVertexInputAttribs(&input_attrib, 1);
10053
Chris Forbesc97d98e2015-05-25 11:13:31 +120010054 VkDescriptorSetObj descriptorSet(m_device);
10055 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010057
Tony Barbour5781e8f2015-08-04 16:23:11 -060010058 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010059
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010060 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010061}
10062
Chris Forbesc68b43c2016-04-06 11:18:47 +120010063TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10064 m_errorMonitor->SetDesiredFailureMsg(
10065 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10066 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10067
10068 ASSERT_NO_FATAL_FAILURE(InitState());
10069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10070
10071 char const *vsSource =
10072 "#version 450\n"
10073 "\n"
10074 "out gl_PerVertex {\n"
10075 " vec4 gl_Position;\n"
10076 "};\n"
10077 "void main(){\n"
10078 " gl_Position = vec4(1);\n"
10079 "}\n";
10080 char const *fsSource =
10081 "#version 450\n"
10082 "\n"
10083 "layout(location=0) out vec4 color;\n"
10084 "void main(){\n"
10085 " color = vec4(1);\n"
10086 "}\n";
10087
10088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10090
10091 VkPipelineObj pipe(m_device);
10092 pipe.AddColorAttachment();
10093 pipe.AddShader(&vs);
10094 pipe.AddShader(&vs);
10095 pipe.AddShader(&fs);
10096
10097 VkDescriptorSetObj descriptorSet(m_device);
10098 descriptorSet.AppendDummy();
10099 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10100
10101 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10102
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010103 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010104}
10105
Karl Schultz6addd812016-02-02 17:17:23 -070010106TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010107 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010108
10109 ASSERT_NO_FATAL_FAILURE(InitState());
10110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10111
10112 VkVertexInputBindingDescription input_binding;
10113 memset(&input_binding, 0, sizeof(input_binding));
10114
10115 VkVertexInputAttributeDescription input_attribs[2];
10116 memset(input_attribs, 0, sizeof(input_attribs));
10117
10118 for (int i = 0; i < 2; i++) {
10119 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10120 input_attribs[i].location = i;
10121 }
10122
10123 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010124 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010125 "\n"
10126 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010127 "out gl_PerVertex {\n"
10128 " vec4 gl_Position;\n"
10129 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010130 "void main(){\n"
10131 " gl_Position = x[0] + x[1];\n"
10132 "}\n";
10133 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010134 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010135 "\n"
10136 "layout(location=0) out vec4 color;\n"
10137 "void main(){\n"
10138 " color = vec4(1);\n"
10139 "}\n";
10140
10141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10143
10144 VkPipelineObj pipe(m_device);
10145 pipe.AddColorAttachment();
10146 pipe.AddShader(&vs);
10147 pipe.AddShader(&fs);
10148
10149 pipe.AddVertexInputBindings(&input_binding, 1);
10150 pipe.AddVertexInputAttribs(input_attribs, 2);
10151
10152 VkDescriptorSetObj descriptorSet(m_device);
10153 descriptorSet.AppendDummy();
10154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10155
10156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10157
10158 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010159 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010160}
10161
Chris Forbes2682b242015-11-24 11:13:14 +130010162TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10163{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010164 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010165
10166 ASSERT_NO_FATAL_FAILURE(InitState());
10167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10168
10169 VkVertexInputBindingDescription input_binding;
10170 memset(&input_binding, 0, sizeof(input_binding));
10171
10172 VkVertexInputAttributeDescription input_attribs[2];
10173 memset(input_attribs, 0, sizeof(input_attribs));
10174
10175 for (int i = 0; i < 2; i++) {
10176 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10177 input_attribs[i].location = i;
10178 }
10179
10180 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010181 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010182 "\n"
10183 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010184 "out gl_PerVertex {\n"
10185 " vec4 gl_Position;\n"
10186 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010187 "void main(){\n"
10188 " gl_Position = x[0] + x[1];\n"
10189 "}\n";
10190 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010191 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010192 "\n"
10193 "layout(location=0) out vec4 color;\n"
10194 "void main(){\n"
10195 " color = vec4(1);\n"
10196 "}\n";
10197
10198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10200
10201 VkPipelineObj pipe(m_device);
10202 pipe.AddColorAttachment();
10203 pipe.AddShader(&vs);
10204 pipe.AddShader(&fs);
10205
10206 pipe.AddVertexInputBindings(&input_binding, 1);
10207 pipe.AddVertexInputAttribs(input_attribs, 2);
10208
10209 VkDescriptorSetObj descriptorSet(m_device);
10210 descriptorSet.AppendDummy();
10211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10212
10213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010215 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010216}
Chris Forbes2682b242015-11-24 11:13:14 +130010217
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010218TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10219{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010220 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010221
10222 ASSERT_NO_FATAL_FAILURE(InitState());
10223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10224
10225 char const *vsSource =
10226 "#version 450\n"
10227 "out gl_PerVertex {\n"
10228 " vec4 gl_Position;\n"
10229 "};\n"
10230 "void main(){\n"
10231 " gl_Position = vec4(0);\n"
10232 "}\n";
10233 char const *fsSource =
10234 "#version 450\n"
10235 "\n"
10236 "layout(location=0) out vec4 color;\n"
10237 "void main(){\n"
10238 " color = vec4(1);\n"
10239 "}\n";
10240
10241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10243
10244 VkPipelineObj pipe(m_device);
10245 pipe.AddColorAttachment();
10246 pipe.AddShader(&vs);
10247 pipe.AddShader(&fs);
10248
10249 VkDescriptorSetObj descriptorSet(m_device);
10250 descriptorSet.AppendDummy();
10251 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10252
10253 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10254
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010255 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010256}
10257
Chris Forbes912c9192016-04-05 17:50:35 +120010258TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10259{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010260 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010261
10262 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10263
10264 ASSERT_NO_FATAL_FAILURE(InitState());
10265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10266
10267 char const *vsSource =
10268 "#version 450\n"
10269 "out gl_PerVertex {\n"
10270 " vec4 gl_Position;\n"
10271 "};\n"
10272 "layout(location=0) out vec3 x;\n"
10273 "layout(location=1) out ivec3 y;\n"
10274 "layout(location=2) out vec3 z;\n"
10275 "void main(){\n"
10276 " gl_Position = vec4(0);\n"
10277 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10278 "}\n";
10279 char const *fsSource =
10280 "#version 450\n"
10281 "\n"
10282 "layout(location=0) out vec4 color;\n"
10283 "layout(location=0) in float x;\n"
10284 "layout(location=1) flat in int y;\n"
10285 "layout(location=2) in vec2 z;\n"
10286 "void main(){\n"
10287 " color = vec4(1 + x + y + z.x);\n"
10288 "}\n";
10289
10290 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10291 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10292
10293 VkPipelineObj pipe(m_device);
10294 pipe.AddColorAttachment();
10295 pipe.AddShader(&vs);
10296 pipe.AddShader(&fs);
10297
10298 VkDescriptorSetObj descriptorSet(m_device);
10299 descriptorSet.AppendDummy();
10300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10301
10302 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10303
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010304 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010305}
10306
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010307TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10308{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010309 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010310
10311 ASSERT_NO_FATAL_FAILURE(InitState());
10312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10313
Chris Forbesc1e852d2016-04-04 19:26:42 +120010314 if (!m_device->phy().features().tessellationShader) {
10315 printf("Device does not support tessellation shaders; skipped.\n");
10316 return;
10317 }
10318
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010319 char const *vsSource =
10320 "#version 450\n"
10321 "void main(){}\n";
10322 char const *tcsSource =
10323 "#version 450\n"
10324 "layout(location=0) out int x[];\n"
10325 "layout(vertices=3) out;\n"
10326 "void main(){\n"
10327 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10328 " gl_TessLevelInner[0] = 1;\n"
10329 " x[gl_InvocationID] = gl_InvocationID;\n"
10330 "}\n";
10331 char const *tesSource =
10332 "#version 450\n"
10333 "layout(triangles, equal_spacing, cw) in;\n"
10334 "layout(location=0) in int x[];\n"
10335 "out gl_PerVertex { vec4 gl_Position; };\n"
10336 "void main(){\n"
10337 " gl_Position.xyz = gl_TessCoord;\n"
10338 " gl_Position.w = x[0] + x[1] + x[2];\n"
10339 "}\n";
10340 char const *fsSource =
10341 "#version 450\n"
10342 "layout(location=0) out vec4 color;\n"
10343 "void main(){\n"
10344 " color = vec4(1);\n"
10345 "}\n";
10346
10347 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10348 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10349 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10350 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10351
10352 VkPipelineInputAssemblyStateCreateInfo iasci{
10353 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10354 nullptr,
10355 0,
10356 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10357 VK_FALSE};
10358
Chris Forbesb4cacb62016-04-04 19:15:00 +120010359 VkPipelineTessellationStateCreateInfo tsci{
10360 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10361 nullptr,
10362 0,
10363 3};
10364
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010365 VkPipelineObj pipe(m_device);
10366 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010367 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010368 pipe.AddColorAttachment();
10369 pipe.AddShader(&vs);
10370 pipe.AddShader(&tcs);
10371 pipe.AddShader(&tes);
10372 pipe.AddShader(&fs);
10373
10374 VkDescriptorSetObj descriptorSet(m_device);
10375 descriptorSet.AppendDummy();
10376 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10377
10378 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010380 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010381}
10382
Chris Forbesa0ab8152016-04-20 13:34:27 +120010383TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10384{
10385 m_errorMonitor->ExpectSuccess();
10386
10387 ASSERT_NO_FATAL_FAILURE(InitState());
10388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10389
10390 if (!m_device->phy().features().geometryShader) {
10391 printf("Device does not support geometry shaders; skipped.\n");
10392 return;
10393 }
10394
10395 char const *vsSource =
10396 "#version 450\n"
10397 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10398 "void main(){\n"
10399 " vs_out.x = vec4(1);\n"
10400 "}\n";
10401 char const *gsSource =
10402 "#version 450\n"
10403 "layout(triangles) in;\n"
10404 "layout(triangle_strip, max_vertices=3) out;\n"
10405 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10406 "out gl_PerVertex { vec4 gl_Position; };\n"
10407 "void main() {\n"
10408 " gl_Position = gs_in[0].x;\n"
10409 " EmitVertex();\n"
10410 "}\n";
10411 char const *fsSource =
10412 "#version 450\n"
10413 "layout(location=0) out vec4 color;\n"
10414 "void main(){\n"
10415 " color = vec4(1);\n"
10416 "}\n";
10417
10418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10419 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10420 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10421
10422 VkPipelineObj pipe(m_device);
10423 pipe.AddColorAttachment();
10424 pipe.AddShader(&vs);
10425 pipe.AddShader(&gs);
10426 pipe.AddShader(&fs);
10427
10428 VkDescriptorSetObj descriptorSet(m_device);
10429 descriptorSet.AppendDummy();
10430 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10431
10432 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10433
10434 m_errorMonitor->VerifyNotFound();
10435}
10436
Chris Forbesa0193bc2016-04-04 19:19:47 +120010437TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10438{
10439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10440 "is per-vertex in tessellation control shader stage "
10441 "but per-patch in tessellation evaluation shader stage");
10442
10443 ASSERT_NO_FATAL_FAILURE(InitState());
10444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10445
Chris Forbesc1e852d2016-04-04 19:26:42 +120010446 if (!m_device->phy().features().tessellationShader) {
10447 printf("Device does not support tessellation shaders; skipped.\n");
10448 return;
10449 }
10450
Chris Forbesa0193bc2016-04-04 19:19:47 +120010451 char const *vsSource =
10452 "#version 450\n"
10453 "void main(){}\n";
10454 char const *tcsSource =
10455 "#version 450\n"
10456 "layout(location=0) out int x[];\n"
10457 "layout(vertices=3) out;\n"
10458 "void main(){\n"
10459 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10460 " gl_TessLevelInner[0] = 1;\n"
10461 " x[gl_InvocationID] = gl_InvocationID;\n"
10462 "}\n";
10463 char const *tesSource =
10464 "#version 450\n"
10465 "layout(triangles, equal_spacing, cw) in;\n"
10466 "layout(location=0) patch in int x;\n"
10467 "out gl_PerVertex { vec4 gl_Position; };\n"
10468 "void main(){\n"
10469 " gl_Position.xyz = gl_TessCoord;\n"
10470 " gl_Position.w = x;\n"
10471 "}\n";
10472 char const *fsSource =
10473 "#version 450\n"
10474 "layout(location=0) out vec4 color;\n"
10475 "void main(){\n"
10476 " color = vec4(1);\n"
10477 "}\n";
10478
10479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10480 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10481 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10483
10484 VkPipelineInputAssemblyStateCreateInfo iasci{
10485 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10486 nullptr,
10487 0,
10488 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10489 VK_FALSE};
10490
10491 VkPipelineTessellationStateCreateInfo tsci{
10492 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10493 nullptr,
10494 0,
10495 3};
10496
10497 VkPipelineObj pipe(m_device);
10498 pipe.SetInputAssembly(&iasci);
10499 pipe.SetTessellation(&tsci);
10500 pipe.AddColorAttachment();
10501 pipe.AddShader(&vs);
10502 pipe.AddShader(&tcs);
10503 pipe.AddShader(&tes);
10504 pipe.AddShader(&fs);
10505
10506 VkDescriptorSetObj descriptorSet(m_device);
10507 descriptorSet.AppendDummy();
10508 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10509
10510 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10511
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010512 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010513}
10514
Karl Schultz6addd812016-02-02 17:17:23 -070010515TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10516 m_errorMonitor->SetDesiredFailureMsg(
10517 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010518 "Duplicate vertex input binding descriptions for binding 0");
10519
Chris Forbes280ba2c2015-06-12 11:16:41 +120010520 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010522
10523 /* Two binding descriptions for binding 0 */
10524 VkVertexInputBindingDescription input_bindings[2];
10525 memset(input_bindings, 0, sizeof(input_bindings));
10526
10527 VkVertexInputAttributeDescription input_attrib;
10528 memset(&input_attrib, 0, sizeof(input_attrib));
10529 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10530
10531 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010532 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010533 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010534 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010535 "out gl_PerVertex {\n"
10536 " vec4 gl_Position;\n"
10537 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010538 "void main(){\n"
10539 " gl_Position = vec4(x);\n"
10540 "}\n";
10541 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010542 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010543 "\n"
10544 "layout(location=0) out vec4 color;\n"
10545 "void main(){\n"
10546 " color = vec4(1);\n"
10547 "}\n";
10548
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010549 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10550 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010551
10552 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010553 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010554 pipe.AddShader(&vs);
10555 pipe.AddShader(&fs);
10556
10557 pipe.AddVertexInputBindings(input_bindings, 2);
10558 pipe.AddVertexInputAttribs(&input_attrib, 1);
10559
Chris Forbes280ba2c2015-06-12 11:16:41 +120010560 VkDescriptorSetObj descriptorSet(m_device);
10561 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010562 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010563
Tony Barbour5781e8f2015-08-04 16:23:11 -060010564 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010565
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010566 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010567}
Chris Forbes8f68b562015-05-25 11:13:32 +120010568
Chris Forbes35efec72016-04-21 14:32:08 +120010569TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10570 m_errorMonitor->ExpectSuccess();
10571
10572 ASSERT_NO_FATAL_FAILURE(InitState());
10573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10574
10575 if (!m_device->phy().features().tessellationShader) {
10576 printf("Device does not support 64bit vertex attributes; skipped.\n");
10577 return;
10578 }
10579
10580 VkVertexInputBindingDescription input_bindings[1];
10581 memset(input_bindings, 0, sizeof(input_bindings));
10582
10583 VkVertexInputAttributeDescription input_attribs[4];
10584 memset(input_attribs, 0, sizeof(input_attribs));
10585 input_attribs[0].location = 0;
10586 input_attribs[0].offset = 0;
10587 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10588 input_attribs[1].location = 2;
10589 input_attribs[1].offset = 32;
10590 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10591 input_attribs[2].location = 4;
10592 input_attribs[2].offset = 64;
10593 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10594 input_attribs[3].location = 6;
10595 input_attribs[3].offset = 96;
10596 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10597
10598 char const *vsSource =
10599 "#version 450\n"
10600 "\n"
10601 "layout(location=0) in dmat4 x;\n"
10602 "out gl_PerVertex {\n"
10603 " vec4 gl_Position;\n"
10604 "};\n"
10605 "void main(){\n"
10606 " gl_Position = vec4(x[0][0]);\n"
10607 "}\n";
10608 char const *fsSource =
10609 "#version 450\n"
10610 "\n"
10611 "layout(location=0) out vec4 color;\n"
10612 "void main(){\n"
10613 " color = vec4(1);\n"
10614 "}\n";
10615
10616 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10617 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10618
10619 VkPipelineObj pipe(m_device);
10620 pipe.AddColorAttachment();
10621 pipe.AddShader(&vs);
10622 pipe.AddShader(&fs);
10623
10624 pipe.AddVertexInputBindings(input_bindings, 1);
10625 pipe.AddVertexInputAttribs(input_attribs, 4);
10626
10627 VkDescriptorSetObj descriptorSet(m_device);
10628 descriptorSet.AppendDummy();
10629 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10630
10631 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10632
10633 m_errorMonitor->VerifyNotFound();
10634}
10635
Karl Schultz6addd812016-02-02 17:17:23 -070010636TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010638 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010639
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010640 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010641
10642 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010643 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010644 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010645 "out gl_PerVertex {\n"
10646 " vec4 gl_Position;\n"
10647 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010648 "void main(){\n"
10649 " gl_Position = vec4(1);\n"
10650 "}\n";
10651 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010652 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010653 "\n"
10654 "void main(){\n"
10655 "}\n";
10656
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010659
10660 VkPipelineObj pipe(m_device);
10661 pipe.AddShader(&vs);
10662 pipe.AddShader(&fs);
10663
Chia-I Wu08accc62015-07-07 11:50:03 +080010664 /* set up CB 0, not written */
10665 pipe.AddColorAttachment();
10666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010667
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010668 VkDescriptorSetObj descriptorSet(m_device);
10669 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010670 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010671
Tony Barbour5781e8f2015-08-04 16:23:11 -060010672 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010673
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010674 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010675}
10676
Karl Schultz6addd812016-02-02 17:17:23 -070010677TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010678 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010679 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010680 "FS writes to output location 1 with no matching attachment");
10681
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010682 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010683
10684 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010685 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010686 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010687 "out gl_PerVertex {\n"
10688 " vec4 gl_Position;\n"
10689 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010690 "void main(){\n"
10691 " gl_Position = vec4(1);\n"
10692 "}\n";
10693 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010694 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010695 "\n"
10696 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010697 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010698 "void main(){\n"
10699 " x = vec4(1);\n"
10700 " y = vec4(1);\n"
10701 "}\n";
10702
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010705
10706 VkPipelineObj pipe(m_device);
10707 pipe.AddShader(&vs);
10708 pipe.AddShader(&fs);
10709
Chia-I Wu08accc62015-07-07 11:50:03 +080010710 /* set up CB 0, not written */
10711 pipe.AddColorAttachment();
10712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010713 /* FS writes CB 1, but we don't configure it */
10714
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010715 VkDescriptorSetObj descriptorSet(m_device);
10716 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010717 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010718
Tony Barbour5781e8f2015-08-04 16:23:11 -060010719 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010720
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010721 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010722}
10723
Karl Schultz6addd812016-02-02 17:17:23 -070010724TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010726 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010727
Chris Forbesa36d69e2015-05-25 11:13:44 +120010728 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010729
10730 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010731 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010732 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010733 "out gl_PerVertex {\n"
10734 " vec4 gl_Position;\n"
10735 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010736 "void main(){\n"
10737 " gl_Position = vec4(1);\n"
10738 "}\n";
10739 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010740 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010741 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010742 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010743 "void main(){\n"
10744 " x = ivec4(1);\n"
10745 "}\n";
10746
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010747 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010749
10750 VkPipelineObj pipe(m_device);
10751 pipe.AddShader(&vs);
10752 pipe.AddShader(&fs);
10753
Chia-I Wu08accc62015-07-07 11:50:03 +080010754 /* set up CB 0; type is UNORM by default */
10755 pipe.AddColorAttachment();
10756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010757
Chris Forbesa36d69e2015-05-25 11:13:44 +120010758 VkDescriptorSetObj descriptorSet(m_device);
10759 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010760 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010761
Tony Barbour5781e8f2015-08-04 16:23:11 -060010762 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010763
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010764 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010765}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010766
Karl Schultz6addd812016-02-02 17:17:23 -070010767TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010769 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010770
Chris Forbes556c76c2015-08-14 12:04:59 +120010771 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010772
10773 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010774 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010775 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010776 "out gl_PerVertex {\n"
10777 " vec4 gl_Position;\n"
10778 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010779 "void main(){\n"
10780 " gl_Position = vec4(1);\n"
10781 "}\n";
10782 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010783 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010784 "\n"
10785 "layout(location=0) out vec4 x;\n"
10786 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10787 "void main(){\n"
10788 " x = vec4(bar.y);\n"
10789 "}\n";
10790
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010791 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10792 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010793
Chris Forbes556c76c2015-08-14 12:04:59 +120010794 VkPipelineObj pipe(m_device);
10795 pipe.AddShader(&vs);
10796 pipe.AddShader(&fs);
10797
10798 /* set up CB 0; type is UNORM by default */
10799 pipe.AddColorAttachment();
10800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10801
10802 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010803 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010804
10805 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10806
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010807 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010808}
10809
Chris Forbes5c59e902016-02-26 16:56:09 +130010810TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10812 "not declared in layout");
10813
10814 ASSERT_NO_FATAL_FAILURE(InitState());
10815
10816 char const *vsSource =
10817 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010818 "\n"
10819 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10820 "out gl_PerVertex {\n"
10821 " vec4 gl_Position;\n"
10822 "};\n"
10823 "void main(){\n"
10824 " gl_Position = vec4(consts.x);\n"
10825 "}\n";
10826 char const *fsSource =
10827 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010828 "\n"
10829 "layout(location=0) out vec4 x;\n"
10830 "void main(){\n"
10831 " x = vec4(1);\n"
10832 "}\n";
10833
10834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10836
10837 VkPipelineObj pipe(m_device);
10838 pipe.AddShader(&vs);
10839 pipe.AddShader(&fs);
10840
10841 /* set up CB 0; type is UNORM by default */
10842 pipe.AddColorAttachment();
10843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10844
10845 VkDescriptorSetObj descriptorSet(m_device);
10846 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10847
10848 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10849
10850 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010851 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010852}
10853
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010854TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10855 m_errorMonitor->SetDesiredFailureMsg(
10856 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10857 "Shader uses descriptor slot 0.0");
10858
10859 ASSERT_NO_FATAL_FAILURE(InitState());
10860
10861 char const *csSource =
10862 "#version 450\n"
10863 "\n"
10864 "layout(local_size_x=1) in;\n"
10865 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10866 "void main(){\n"
10867 " x = vec4(1);\n"
10868 "}\n";
10869
10870 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10871
10872 VkDescriptorSetObj descriptorSet(m_device);
10873 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10874
10875 VkComputePipelineCreateInfo cpci = {
10876 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10877 nullptr, 0, {
10878 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10879 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10880 cs.handle(), "main", nullptr
10881 },
10882 descriptorSet.GetPipelineLayout(),
10883 VK_NULL_HANDLE, -1
10884 };
10885
10886 VkPipeline pipe;
10887 VkResult err = vkCreateComputePipelines(
10888 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10889
10890 m_errorMonitor->VerifyFound();
10891
10892 if (err == VK_SUCCESS) {
10893 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10894 }
10895}
10896
10897TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
10898 m_errorMonitor->ExpectSuccess();
10899
10900 ASSERT_NO_FATAL_FAILURE(InitState());
10901
10902 char const *csSource =
10903 "#version 450\n"
10904 "\n"
10905 "layout(local_size_x=1) in;\n"
10906 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10907 "void main(){\n"
10908 " // x is not used.\n"
10909 "}\n";
10910
10911 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10912
10913 VkDescriptorSetObj descriptorSet(m_device);
10914 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10915
10916 VkComputePipelineCreateInfo cpci = {
10917 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10918 nullptr, 0, {
10919 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10920 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10921 cs.handle(), "main", nullptr
10922 },
10923 descriptorSet.GetPipelineLayout(),
10924 VK_NULL_HANDLE, -1
10925 };
10926
10927 VkPipeline pipe;
10928 VkResult err = vkCreateComputePipelines(
10929 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10930
10931 m_errorMonitor->VerifyNotFound();
10932
10933 if (err == VK_SUCCESS) {
10934 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10935 }
10936}
10937
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010938#endif // SHADER_CHECKER_TESTS
10939
10940#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060010941TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070010942 m_errorMonitor->SetDesiredFailureMsg(
10943 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010944 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010945
10946 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010947
10948 // Create an image
10949 VkImage image;
10950
Karl Schultz6addd812016-02-02 17:17:23 -070010951 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10952 const int32_t tex_width = 32;
10953 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010954
10955 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010956 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10957 image_create_info.pNext = NULL;
10958 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10959 image_create_info.format = tex_format;
10960 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010961 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070010962 image_create_info.extent.depth = 1;
10963 image_create_info.mipLevels = 1;
10964 image_create_info.arrayLayers = 1;
10965 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10966 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10967 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10968 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010969
10970 // Introduce error by sending down a bogus width extent
10971 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010972 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010973
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010974 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010975}
10976
Mark Youngc48c4c12016-04-11 14:26:49 -060010977TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
10978 m_errorMonitor->SetDesiredFailureMsg(
10979 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10980 "CreateImage extents is 0 for at least one required dimension");
10981
10982 ASSERT_NO_FATAL_FAILURE(InitState());
10983
10984 // Create an image
10985 VkImage image;
10986
10987 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10988 const int32_t tex_width = 32;
10989 const int32_t tex_height = 32;
10990
10991 VkImageCreateInfo image_create_info = {};
10992 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10993 image_create_info.pNext = NULL;
10994 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10995 image_create_info.format = tex_format;
10996 image_create_info.extent.width = tex_width;
10997 image_create_info.extent.height = tex_height;
10998 image_create_info.extent.depth = 1;
10999 image_create_info.mipLevels = 1;
11000 image_create_info.arrayLayers = 1;
11001 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11002 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11003 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11004 image_create_info.flags = 0;
11005
11006 // Introduce error by sending down a bogus width extent
11007 image_create_info.extent.width = 0;
11008 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11009
11010 m_errorMonitor->VerifyFound();
11011}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011012#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011013
Tobin Ehliscde08892015-09-22 10:11:37 -060011014#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011015TEST_F(VkLayerTest, InvalidImageView) {
11016 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011017
Karl Schultz6addd812016-02-02 17:17:23 -070011018 m_errorMonitor->SetDesiredFailureMsg(
11019 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011020 "vkCreateImageView called with baseMipLevel 10 ");
11021
Tobin Ehliscde08892015-09-22 10:11:37 -060011022 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011023
Mike Stroyana3082432015-09-25 13:39:21 -060011024 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011025 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011026
Karl Schultz6addd812016-02-02 17:17:23 -070011027 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11028 const int32_t tex_width = 32;
11029 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011030
11031 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011032 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11033 image_create_info.pNext = NULL;
11034 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11035 image_create_info.format = tex_format;
11036 image_create_info.extent.width = tex_width;
11037 image_create_info.extent.height = tex_height;
11038 image_create_info.extent.depth = 1;
11039 image_create_info.mipLevels = 1;
11040 image_create_info.arrayLayers = 1;
11041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11042 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11043 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11044 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011045
Chia-I Wuf7458c52015-10-26 21:10:41 +080011046 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011047 ASSERT_VK_SUCCESS(err);
11048
11049 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011050 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11051 image_view_create_info.image = image;
11052 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11053 image_view_create_info.format = tex_format;
11054 image_view_create_info.subresourceRange.layerCount = 1;
11055 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11056 image_view_create_info.subresourceRange.levelCount = 1;
11057 image_view_create_info.subresourceRange.aspectMask =
11058 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011059
11060 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011061 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11062 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011063
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011064 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011065 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011066}
Mike Stroyana3082432015-09-25 13:39:21 -060011067
Karl Schultz6addd812016-02-02 17:17:23 -070011068TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011069 TEST_DESCRIPTION(
11070 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011072 "vkCreateImageView: Color image "
11073 "formats must have ONLY the "
11074 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011075
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011076 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011077
Karl Schultz6addd812016-02-02 17:17:23 -070011078 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011079 VkImageObj image(m_device);
11080 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11081 VK_IMAGE_TILING_LINEAR, 0);
11082 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011083
11084 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011085 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011086 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011087 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11088 image_view_create_info.format = tex_format;
11089 image_view_create_info.subresourceRange.baseMipLevel = 0;
11090 image_view_create_info.subresourceRange.levelCount = 1;
11091 // Cause an error by setting an invalid image aspect
11092 image_view_create_info.subresourceRange.aspectMask =
11093 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011094
11095 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011096 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011097
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011098 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011099}
11100
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011101TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011102 VkResult err;
11103 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011104
Karl Schultz6addd812016-02-02 17:17:23 -070011105 m_errorMonitor->SetDesiredFailureMsg(
11106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011107 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011108
Mike Stroyana3082432015-09-25 13:39:21 -060011109 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011110
11111 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011112 VkImage srcImage;
11113 VkImage dstImage;
11114 VkDeviceMemory srcMem;
11115 VkDeviceMemory destMem;
11116 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011117
11118 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011119 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11120 image_create_info.pNext = NULL;
11121 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11122 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11123 image_create_info.extent.width = 32;
11124 image_create_info.extent.height = 32;
11125 image_create_info.extent.depth = 1;
11126 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011127 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011128 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11129 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11130 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11131 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011132
Karl Schultz6addd812016-02-02 17:17:23 -070011133 err =
11134 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011135 ASSERT_VK_SUCCESS(err);
11136
Karl Schultz6addd812016-02-02 17:17:23 -070011137 err =
11138 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011139 ASSERT_VK_SUCCESS(err);
11140
11141 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011142 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011143 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11144 memAlloc.pNext = NULL;
11145 memAlloc.allocationSize = 0;
11146 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011147
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011148 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011149 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011150 pass =
11151 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011152 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011153 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011154 ASSERT_VK_SUCCESS(err);
11155
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011156 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011157 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011158 pass =
11159 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011160 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011161 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011162 ASSERT_VK_SUCCESS(err);
11163
11164 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11165 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011166 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011167 ASSERT_VK_SUCCESS(err);
11168
11169 BeginCommandBuffer();
11170 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011171 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011172 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011173 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011174 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011175 copyRegion.srcOffset.x = 0;
11176 copyRegion.srcOffset.y = 0;
11177 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011178 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011179 copyRegion.dstSubresource.mipLevel = 0;
11180 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011181 // Introduce failure by forcing the dst layerCount to differ from src
11182 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011183 copyRegion.dstOffset.x = 0;
11184 copyRegion.dstOffset.y = 0;
11185 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011186 copyRegion.extent.width = 1;
11187 copyRegion.extent.height = 1;
11188 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011189 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11190 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011191 EndCommandBuffer();
11192
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011193 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011194
Chia-I Wuf7458c52015-10-26 21:10:41 +080011195 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011196 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011197 vkFreeMemory(m_device->device(), srcMem, NULL);
11198 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011199}
11200
Tony Barbourd6673642016-05-05 14:46:39 -060011201TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11202
11203 TEST_DESCRIPTION("Creating images with unsuported formats ");
11204
11205 ASSERT_NO_FATAL_FAILURE(InitState());
11206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11207 VkImageObj image(m_device);
11208 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11209 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11210 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11211 VK_IMAGE_TILING_OPTIMAL, 0);
11212 ASSERT_TRUE(image.initialized());
11213
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011214 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11215 VkImageCreateInfo image_create_info;
11216 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11217 image_create_info.pNext = NULL;
11218 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11219 image_create_info.format = VK_FORMAT_UNDEFINED;
11220 image_create_info.extent.width = 32;
11221 image_create_info.extent.height = 32;
11222 image_create_info.extent.depth = 1;
11223 image_create_info.mipLevels = 1;
11224 image_create_info.arrayLayers = 1;
11225 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11226 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11227 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11228 image_create_info.flags = 0;
11229
11230 m_errorMonitor->SetDesiredFailureMsg(
11231 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11232 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11233
11234 VkImage localImage;
11235 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11236 m_errorMonitor->VerifyFound();
11237
Tony Barbourd6673642016-05-05 14:46:39 -060011238 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011239 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011240 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11241 VkFormat format = static_cast<VkFormat>(f);
11242 VkFormatProperties fProps = m_device->format_properties(format);
11243 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11244 fProps.optimalTilingFeatures == 0) {
11245 unsupported = format;
11246 break;
11247 }
11248 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011249
Tony Barbourd6673642016-05-05 14:46:39 -060011250 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011251 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011253 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011254
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011255 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011256 m_errorMonitor->VerifyFound();
11257 }
11258}
11259
11260TEST_F(VkLayerTest, ImageLayerViewTests) {
11261 VkResult ret;
11262 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11263
11264 ASSERT_NO_FATAL_FAILURE(InitState());
11265
11266 VkImageObj image(m_device);
11267 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11268 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11269 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11270 VK_IMAGE_TILING_OPTIMAL, 0);
11271 ASSERT_TRUE(image.initialized());
11272
11273 VkImageView imgView;
11274 VkImageViewCreateInfo imgViewInfo = {};
11275 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11276 imgViewInfo.image = image.handle();
11277 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11278 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11279 imgViewInfo.subresourceRange.layerCount = 1;
11280 imgViewInfo.subresourceRange.baseMipLevel = 0;
11281 imgViewInfo.subresourceRange.levelCount = 1;
11282 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11283
11284 m_errorMonitor->SetDesiredFailureMsg(
11285 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11286 "vkCreateImageView called with baseMipLevel");
11287 // View can't have baseMipLevel >= image's mipLevels - Expect
11288 // VIEW_CREATE_ERROR
11289 imgViewInfo.subresourceRange.baseMipLevel = 1;
11290 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11291 m_errorMonitor->VerifyFound();
11292 imgViewInfo.subresourceRange.baseMipLevel = 0;
11293
11294 m_errorMonitor->SetDesiredFailureMsg(
11295 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11296 "vkCreateImageView called with baseArrayLayer");
11297 // View can't have baseArrayLayer >= image's arraySize - Expect
11298 // VIEW_CREATE_ERROR
11299 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11300 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11301 m_errorMonitor->VerifyFound();
11302 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11303
11304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11305 "vkCreateImageView called with 0 in "
11306 "pCreateInfo->subresourceRange."
11307 "levelCount");
11308 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11309 imgViewInfo.subresourceRange.levelCount = 0;
11310 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11311 m_errorMonitor->VerifyFound();
11312 imgViewInfo.subresourceRange.levelCount = 1;
11313
11314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11315 "vkCreateImageView called with 0 in "
11316 "pCreateInfo->subresourceRange."
11317 "layerCount");
11318 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11319 imgViewInfo.subresourceRange.layerCount = 0;
11320 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11321 m_errorMonitor->VerifyFound();
11322 imgViewInfo.subresourceRange.layerCount = 1;
11323
11324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11325 "but both must be color formats");
11326 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11327 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11328 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11329 m_errorMonitor->VerifyFound();
11330 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11331
11332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11333 "Formats MUST be IDENTICAL unless "
11334 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11335 "was set on image creation.");
11336 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11337 // VIEW_CREATE_ERROR
11338 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11339 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11340 m_errorMonitor->VerifyFound();
11341 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11342
11343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11344 "can support ImageViews with "
11345 "differing formats but they must be "
11346 "in the same compatibility class.");
11347 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11348 // VIEW_CREATE_ERROR
11349 VkImageCreateInfo mutImgInfo = image.create_info();
11350 VkImage mutImage;
11351 mutImgInfo.format = VK_FORMAT_R8_UINT;
11352 assert(
11353 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11354 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11355 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11356 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11357 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11358 ASSERT_VK_SUCCESS(ret);
11359 imgViewInfo.image = mutImage;
11360 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11361 m_errorMonitor->VerifyFound();
11362 imgViewInfo.image = image.handle();
11363 vkDestroyImage(m_device->handle(), mutImage, NULL);
11364}
11365
11366TEST_F(VkLayerTest, MiscImageLayerTests) {
11367
11368 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11369
11370 ASSERT_NO_FATAL_FAILURE(InitState());
11371
11372 VkImageObj image(m_device);
11373 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11374 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11375 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11376 VK_IMAGE_TILING_OPTIMAL, 0);
11377 ASSERT_TRUE(image.initialized());
11378
11379 m_errorMonitor->SetDesiredFailureMsg(
11380 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11381 "number of layers in image subresource is zero");
11382 vk_testing::Buffer buffer;
11383 VkMemoryPropertyFlags reqs = 0;
11384 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11385 VkBufferImageCopy region = {};
11386 region.bufferRowLength = 128;
11387 region.bufferImageHeight = 128;
11388 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11389 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11390 region.imageSubresource.layerCount = 0;
11391 region.imageExtent.height = 4;
11392 region.imageExtent.width = 4;
11393 region.imageExtent.depth = 1;
11394 m_commandBuffer->BeginCommandBuffer();
11395 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11396 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11397 1, &region);
11398 m_errorMonitor->VerifyFound();
11399 region.imageSubresource.layerCount = 1;
11400
11401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11402 "aspectMasks for each region must "
11403 "specify only COLOR or DEPTH or "
11404 "STENCIL");
11405 // Expect MISMATCHED_IMAGE_ASPECT
11406 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11407 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11408 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11409 1, &region);
11410 m_errorMonitor->VerifyFound();
11411 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11412
11413 m_errorMonitor->SetDesiredFailureMsg(
11414 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11415 "If the format of srcImage is a depth, stencil, depth stencil or "
11416 "integer-based format then filter must be VK_FILTER_NEAREST");
11417 // Expect INVALID_FILTER
11418 VkImageObj intImage1(m_device);
11419 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11420 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11421 0);
11422 VkImageObj intImage2(m_device);
11423 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11424 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11425 0);
11426 VkImageBlit blitRegion = {};
11427 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11428 blitRegion.srcSubresource.baseArrayLayer = 0;
11429 blitRegion.srcSubresource.layerCount = 1;
11430 blitRegion.srcSubresource.mipLevel = 0;
11431 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11432 blitRegion.dstSubresource.baseArrayLayer = 0;
11433 blitRegion.dstSubresource.layerCount = 1;
11434 blitRegion.dstSubresource.mipLevel = 0;
11435
11436 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11437 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11438 16, &blitRegion, VK_FILTER_LINEAR);
11439 m_errorMonitor->VerifyFound();
11440
11441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11442 "called with 0 in ppMemoryBarriers");
11443 VkImageMemoryBarrier img_barrier;
11444 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11445 img_barrier.pNext = NULL;
11446 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11447 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11448 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11449 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11450 img_barrier.image = image.handle();
11451 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11452 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11453 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11454 img_barrier.subresourceRange.baseArrayLayer = 0;
11455 img_barrier.subresourceRange.baseMipLevel = 0;
11456 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11457 img_barrier.subresourceRange.layerCount = 0;
11458 img_barrier.subresourceRange.levelCount = 1;
11459 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11460 VK_PIPELINE_STAGE_HOST_BIT,
11461 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11462 nullptr, 1, &img_barrier);
11463 m_errorMonitor->VerifyFound();
11464 img_barrier.subresourceRange.layerCount = 1;
11465}
11466
11467TEST_F(VkLayerTest, ImageFormatLimits) {
11468
11469 TEST_DESCRIPTION("Exceed the limits of image format ");
11470
11471 m_errorMonitor->SetDesiredFailureMsg(
11472 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11473 "CreateImage extents exceed allowable limits for format");
11474 VkImageCreateInfo image_create_info = {};
11475 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11476 image_create_info.pNext = NULL;
11477 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11478 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11479 image_create_info.extent.width = 32;
11480 image_create_info.extent.height = 32;
11481 image_create_info.extent.depth = 1;
11482 image_create_info.mipLevels = 1;
11483 image_create_info.arrayLayers = 1;
11484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11485 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11486 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11487 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11488 image_create_info.flags = 0;
11489
11490 VkImage nullImg;
11491 VkImageFormatProperties imgFmtProps;
11492 vkGetPhysicalDeviceImageFormatProperties(
11493 gpu(), image_create_info.format, image_create_info.imageType,
11494 image_create_info.tiling, image_create_info.usage,
11495 image_create_info.flags, &imgFmtProps);
11496 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11497 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11498 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11499 m_errorMonitor->VerifyFound();
11500 image_create_info.extent.depth = 1;
11501
11502 m_errorMonitor->SetDesiredFailureMsg(
11503 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11504 "exceeds allowable maximum supported by format of");
11505 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11506 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11507 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11508 m_errorMonitor->VerifyFound();
11509 image_create_info.mipLevels = 1;
11510
11511 m_errorMonitor->SetDesiredFailureMsg(
11512 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11513 "exceeds allowable maximum supported by format of");
11514 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11515 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11516 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11517 m_errorMonitor->VerifyFound();
11518 image_create_info.arrayLayers = 1;
11519
11520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11521 "is not supported by format");
11522 int samples = imgFmtProps.sampleCounts >> 1;
11523 image_create_info.samples = (VkSampleCountFlagBits)samples;
11524 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11525 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11526 m_errorMonitor->VerifyFound();
11527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11528
11529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11530 "pCreateInfo->initialLayout, must be "
11531 "VK_IMAGE_LAYOUT_UNDEFINED or "
11532 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11533 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11534 // Expect INVALID_LAYOUT
11535 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11536 m_errorMonitor->VerifyFound();
11537 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11538}
11539
Karl Schultz6addd812016-02-02 17:17:23 -070011540TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011541 VkResult err;
11542 bool pass;
11543
11544 // Create color images with different format sizes and try to copy between them
11545 m_errorMonitor->SetDesiredFailureMsg(
11546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11547 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11548
11549 ASSERT_NO_FATAL_FAILURE(InitState());
11550
11551 // Create two images of different types and try to copy between them
11552 VkImage srcImage;
11553 VkImage dstImage;
11554 VkDeviceMemory srcMem;
11555 VkDeviceMemory destMem;
11556 VkMemoryRequirements memReqs;
11557
11558 VkImageCreateInfo image_create_info = {};
11559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11560 image_create_info.pNext = NULL;
11561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11562 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11563 image_create_info.extent.width = 32;
11564 image_create_info.extent.height = 32;
11565 image_create_info.extent.depth = 1;
11566 image_create_info.mipLevels = 1;
11567 image_create_info.arrayLayers = 1;
11568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11569 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11570 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11571 image_create_info.flags = 0;
11572
11573 err =
11574 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11575 ASSERT_VK_SUCCESS(err);
11576
11577 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11578 // Introduce failure by creating second image with a different-sized format.
11579 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11580
11581 err =
11582 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11583 ASSERT_VK_SUCCESS(err);
11584
11585 // Allocate memory
11586 VkMemoryAllocateInfo memAlloc = {};
11587 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11588 memAlloc.pNext = NULL;
11589 memAlloc.allocationSize = 0;
11590 memAlloc.memoryTypeIndex = 0;
11591
11592 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11593 memAlloc.allocationSize = memReqs.size;
11594 pass =
11595 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11596 ASSERT_TRUE(pass);
11597 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11598 ASSERT_VK_SUCCESS(err);
11599
11600 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11601 memAlloc.allocationSize = memReqs.size;
11602 pass =
11603 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11604 ASSERT_TRUE(pass);
11605 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11606 ASSERT_VK_SUCCESS(err);
11607
11608 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11609 ASSERT_VK_SUCCESS(err);
11610 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11611 ASSERT_VK_SUCCESS(err);
11612
11613 BeginCommandBuffer();
11614 VkImageCopy copyRegion;
11615 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11616 copyRegion.srcSubresource.mipLevel = 0;
11617 copyRegion.srcSubresource.baseArrayLayer = 0;
11618 copyRegion.srcSubresource.layerCount = 0;
11619 copyRegion.srcOffset.x = 0;
11620 copyRegion.srcOffset.y = 0;
11621 copyRegion.srcOffset.z = 0;
11622 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11623 copyRegion.dstSubresource.mipLevel = 0;
11624 copyRegion.dstSubresource.baseArrayLayer = 0;
11625 copyRegion.dstSubresource.layerCount = 0;
11626 copyRegion.dstOffset.x = 0;
11627 copyRegion.dstOffset.y = 0;
11628 copyRegion.dstOffset.z = 0;
11629 copyRegion.extent.width = 1;
11630 copyRegion.extent.height = 1;
11631 copyRegion.extent.depth = 1;
11632 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11633 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11634 EndCommandBuffer();
11635
11636 m_errorMonitor->VerifyFound();
11637
11638 vkDestroyImage(m_device->device(), srcImage, NULL);
11639 vkDestroyImage(m_device->device(), dstImage, NULL);
11640 vkFreeMemory(m_device->device(), srcMem, NULL);
11641 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011642}
11643
Karl Schultz6addd812016-02-02 17:17:23 -070011644TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11645 VkResult err;
11646 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011647
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011648 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011649 m_errorMonitor->SetDesiredFailureMsg(
11650 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011651 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011652
Mike Stroyana3082432015-09-25 13:39:21 -060011653 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011654
11655 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011656 VkImage srcImage;
11657 VkImage dstImage;
11658 VkDeviceMemory srcMem;
11659 VkDeviceMemory destMem;
11660 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011661
11662 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011663 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11664 image_create_info.pNext = NULL;
11665 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11666 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11667 image_create_info.extent.width = 32;
11668 image_create_info.extent.height = 32;
11669 image_create_info.extent.depth = 1;
11670 image_create_info.mipLevels = 1;
11671 image_create_info.arrayLayers = 1;
11672 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11673 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11674 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11675 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011676
Karl Schultz6addd812016-02-02 17:17:23 -070011677 err =
11678 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011679 ASSERT_VK_SUCCESS(err);
11680
Karl Schultzbdb75952016-04-19 11:36:49 -060011681 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11682
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011683 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011684 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011685 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11686 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011687
Karl Schultz6addd812016-02-02 17:17:23 -070011688 err =
11689 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011690 ASSERT_VK_SUCCESS(err);
11691
11692 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011693 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011694 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11695 memAlloc.pNext = NULL;
11696 memAlloc.allocationSize = 0;
11697 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011698
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011699 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011700 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011701 pass =
11702 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011703 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011704 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011705 ASSERT_VK_SUCCESS(err);
11706
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011707 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011708 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011709 pass =
11710 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011711 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011712 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011713 ASSERT_VK_SUCCESS(err);
11714
11715 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11716 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011717 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011718 ASSERT_VK_SUCCESS(err);
11719
11720 BeginCommandBuffer();
11721 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011722 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011723 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011724 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011725 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011726 copyRegion.srcOffset.x = 0;
11727 copyRegion.srcOffset.y = 0;
11728 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011729 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011730 copyRegion.dstSubresource.mipLevel = 0;
11731 copyRegion.dstSubresource.baseArrayLayer = 0;
11732 copyRegion.dstSubresource.layerCount = 0;
11733 copyRegion.dstOffset.x = 0;
11734 copyRegion.dstOffset.y = 0;
11735 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011736 copyRegion.extent.width = 1;
11737 copyRegion.extent.height = 1;
11738 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011739 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11740 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011741 EndCommandBuffer();
11742
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011743 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011744
Chia-I Wuf7458c52015-10-26 21:10:41 +080011745 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011746 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011747 vkFreeMemory(m_device->device(), srcMem, NULL);
11748 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011749}
11750
Karl Schultz6addd812016-02-02 17:17:23 -070011751TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11752 VkResult err;
11753 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011754
Karl Schultz6addd812016-02-02 17:17:23 -070011755 m_errorMonitor->SetDesiredFailureMsg(
11756 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011757 "vkCmdResolveImage called with source sample count less than 2.");
11758
Mike Stroyana3082432015-09-25 13:39:21 -060011759 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011760
11761 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011762 VkImage srcImage;
11763 VkImage dstImage;
11764 VkDeviceMemory srcMem;
11765 VkDeviceMemory destMem;
11766 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011767
11768 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011769 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11770 image_create_info.pNext = NULL;
11771 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11772 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11773 image_create_info.extent.width = 32;
11774 image_create_info.extent.height = 1;
11775 image_create_info.extent.depth = 1;
11776 image_create_info.mipLevels = 1;
11777 image_create_info.arrayLayers = 1;
11778 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11779 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11780 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11781 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011782
Karl Schultz6addd812016-02-02 17:17:23 -070011783 err =
11784 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011785 ASSERT_VK_SUCCESS(err);
11786
Karl Schultz6addd812016-02-02 17:17:23 -070011787 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011788
Karl Schultz6addd812016-02-02 17:17:23 -070011789 err =
11790 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011791 ASSERT_VK_SUCCESS(err);
11792
11793 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011794 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011795 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11796 memAlloc.pNext = NULL;
11797 memAlloc.allocationSize = 0;
11798 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011799
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011800 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011801 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011802 pass =
11803 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011804 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011805 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011806 ASSERT_VK_SUCCESS(err);
11807
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011808 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011809 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011810 pass =
11811 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011812 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011813 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011814 ASSERT_VK_SUCCESS(err);
11815
11816 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11817 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011818 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011819 ASSERT_VK_SUCCESS(err);
11820
11821 BeginCommandBuffer();
11822 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011823 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11824 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011825 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011826 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011827 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011828 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011829 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011830 resolveRegion.srcOffset.x = 0;
11831 resolveRegion.srcOffset.y = 0;
11832 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011833 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011834 resolveRegion.dstSubresource.mipLevel = 0;
11835 resolveRegion.dstSubresource.baseArrayLayer = 0;
11836 resolveRegion.dstSubresource.layerCount = 0;
11837 resolveRegion.dstOffset.x = 0;
11838 resolveRegion.dstOffset.y = 0;
11839 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011840 resolveRegion.extent.width = 1;
11841 resolveRegion.extent.height = 1;
11842 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011843 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11844 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011845 EndCommandBuffer();
11846
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011847 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011848
Chia-I Wuf7458c52015-10-26 21:10:41 +080011849 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011850 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011851 vkFreeMemory(m_device->device(), srcMem, NULL);
11852 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011853}
11854
Karl Schultz6addd812016-02-02 17:17:23 -070011855TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11856 VkResult err;
11857 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011858
Karl Schultz6addd812016-02-02 17:17:23 -070011859 m_errorMonitor->SetDesiredFailureMsg(
11860 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011861 "vkCmdResolveImage called with dest sample count greater than 1.");
11862
Mike Stroyana3082432015-09-25 13:39:21 -060011863 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011864
Chris Forbesa7530692016-05-08 12:35:39 +120011865 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011866 VkImage srcImage;
11867 VkImage dstImage;
11868 VkDeviceMemory srcMem;
11869 VkDeviceMemory destMem;
11870 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011871
11872 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011873 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11874 image_create_info.pNext = NULL;
11875 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11876 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11877 image_create_info.extent.width = 32;
11878 image_create_info.extent.height = 1;
11879 image_create_info.extent.depth = 1;
11880 image_create_info.mipLevels = 1;
11881 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120011882 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070011883 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11884 // Note: Some implementations expect color attachment usage for any
11885 // multisample surface
11886 image_create_info.usage =
11887 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11888 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011889
Karl Schultz6addd812016-02-02 17:17:23 -070011890 err =
11891 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011892 ASSERT_VK_SUCCESS(err);
11893
Karl Schultz6addd812016-02-02 17:17:23 -070011894 // Note: Some implementations expect color attachment usage for any
11895 // multisample surface
11896 image_create_info.usage =
11897 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011898
Karl Schultz6addd812016-02-02 17:17:23 -070011899 err =
11900 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011901 ASSERT_VK_SUCCESS(err);
11902
11903 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011904 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011905 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11906 memAlloc.pNext = NULL;
11907 memAlloc.allocationSize = 0;
11908 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011909
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011910 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011911 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011912 pass =
11913 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011914 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011915 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011916 ASSERT_VK_SUCCESS(err);
11917
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011918 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011919 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011920 pass =
11921 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011922 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011923 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011924 ASSERT_VK_SUCCESS(err);
11925
11926 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11927 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011928 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011929 ASSERT_VK_SUCCESS(err);
11930
11931 BeginCommandBuffer();
11932 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011933 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11934 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011935 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011936 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011937 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011938 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011939 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011940 resolveRegion.srcOffset.x = 0;
11941 resolveRegion.srcOffset.y = 0;
11942 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011943 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011944 resolveRegion.dstSubresource.mipLevel = 0;
11945 resolveRegion.dstSubresource.baseArrayLayer = 0;
11946 resolveRegion.dstSubresource.layerCount = 0;
11947 resolveRegion.dstOffset.x = 0;
11948 resolveRegion.dstOffset.y = 0;
11949 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011950 resolveRegion.extent.width = 1;
11951 resolveRegion.extent.height = 1;
11952 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011953 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11954 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011955 EndCommandBuffer();
11956
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011957 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011958
Chia-I Wuf7458c52015-10-26 21:10:41 +080011959 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011960 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011961 vkFreeMemory(m_device->device(), srcMem, NULL);
11962 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011963}
11964
Karl Schultz6addd812016-02-02 17:17:23 -070011965TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
11966 VkResult err;
11967 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011968
Karl Schultz6addd812016-02-02 17:17:23 -070011969 m_errorMonitor->SetDesiredFailureMsg(
11970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011971 "vkCmdResolveImage called with unmatched source and dest formats.");
11972
Mike Stroyana3082432015-09-25 13:39:21 -060011973 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011974
11975 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011976 VkImage srcImage;
11977 VkImage dstImage;
11978 VkDeviceMemory srcMem;
11979 VkDeviceMemory destMem;
11980 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011981
11982 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011983 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11984 image_create_info.pNext = NULL;
11985 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11986 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11987 image_create_info.extent.width = 32;
11988 image_create_info.extent.height = 1;
11989 image_create_info.extent.depth = 1;
11990 image_create_info.mipLevels = 1;
11991 image_create_info.arrayLayers = 1;
11992 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11993 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11994 // Note: Some implementations expect color attachment usage for any
11995 // multisample surface
11996 image_create_info.usage =
11997 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11998 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011999
Karl Schultz6addd812016-02-02 17:17:23 -070012000 err =
12001 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012002 ASSERT_VK_SUCCESS(err);
12003
Karl Schultz6addd812016-02-02 17:17:23 -070012004 // Set format to something other than source image
12005 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12006 // Note: Some implementations expect color attachment usage for any
12007 // multisample surface
12008 image_create_info.usage =
12009 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12010 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012011
Karl Schultz6addd812016-02-02 17:17:23 -070012012 err =
12013 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012014 ASSERT_VK_SUCCESS(err);
12015
12016 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012017 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012018 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12019 memAlloc.pNext = NULL;
12020 memAlloc.allocationSize = 0;
12021 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012022
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012023 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012024 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012025 pass =
12026 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012027 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012028 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012029 ASSERT_VK_SUCCESS(err);
12030
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012031 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012032 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012033 pass =
12034 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012035 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012036 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012037 ASSERT_VK_SUCCESS(err);
12038
12039 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12040 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012041 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012042 ASSERT_VK_SUCCESS(err);
12043
12044 BeginCommandBuffer();
12045 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012046 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12047 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012048 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012049 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012050 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012051 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012052 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012053 resolveRegion.srcOffset.x = 0;
12054 resolveRegion.srcOffset.y = 0;
12055 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012056 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012057 resolveRegion.dstSubresource.mipLevel = 0;
12058 resolveRegion.dstSubresource.baseArrayLayer = 0;
12059 resolveRegion.dstSubresource.layerCount = 0;
12060 resolveRegion.dstOffset.x = 0;
12061 resolveRegion.dstOffset.y = 0;
12062 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012063 resolveRegion.extent.width = 1;
12064 resolveRegion.extent.height = 1;
12065 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012066 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12067 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012068 EndCommandBuffer();
12069
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012070 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012071
Chia-I Wuf7458c52015-10-26 21:10:41 +080012072 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012073 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012074 vkFreeMemory(m_device->device(), srcMem, NULL);
12075 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012076}
12077
Karl Schultz6addd812016-02-02 17:17:23 -070012078TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12079 VkResult err;
12080 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012081
Karl Schultz6addd812016-02-02 17:17:23 -070012082 m_errorMonitor->SetDesiredFailureMsg(
12083 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012084 "vkCmdResolveImage called with unmatched source and dest image types.");
12085
Mike Stroyana3082432015-09-25 13:39:21 -060012086 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012087
12088 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012089 VkImage srcImage;
12090 VkImage dstImage;
12091 VkDeviceMemory srcMem;
12092 VkDeviceMemory destMem;
12093 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012094
12095 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012096 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12097 image_create_info.pNext = NULL;
12098 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12099 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12100 image_create_info.extent.width = 32;
12101 image_create_info.extent.height = 1;
12102 image_create_info.extent.depth = 1;
12103 image_create_info.mipLevels = 1;
12104 image_create_info.arrayLayers = 1;
12105 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12106 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12107 // Note: Some implementations expect color attachment usage for any
12108 // multisample surface
12109 image_create_info.usage =
12110 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12111 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012112
Karl Schultz6addd812016-02-02 17:17:23 -070012113 err =
12114 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012115 ASSERT_VK_SUCCESS(err);
12116
Karl Schultz6addd812016-02-02 17:17:23 -070012117 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12118 // Note: Some implementations expect color attachment usage for any
12119 // multisample surface
12120 image_create_info.usage =
12121 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012123
Karl Schultz6addd812016-02-02 17:17:23 -070012124 err =
12125 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012126 ASSERT_VK_SUCCESS(err);
12127
12128 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012129 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012130 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12131 memAlloc.pNext = NULL;
12132 memAlloc.allocationSize = 0;
12133 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012134
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012135 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012136 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012137 pass =
12138 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012139 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012140 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012141 ASSERT_VK_SUCCESS(err);
12142
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012143 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012144 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012145 pass =
12146 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012147 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012148 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012149 ASSERT_VK_SUCCESS(err);
12150
12151 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12152 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012153 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012154 ASSERT_VK_SUCCESS(err);
12155
12156 BeginCommandBuffer();
12157 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012158 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12159 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012160 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012161 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012162 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012163 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012164 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012165 resolveRegion.srcOffset.x = 0;
12166 resolveRegion.srcOffset.y = 0;
12167 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012168 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012169 resolveRegion.dstSubresource.mipLevel = 0;
12170 resolveRegion.dstSubresource.baseArrayLayer = 0;
12171 resolveRegion.dstSubresource.layerCount = 0;
12172 resolveRegion.dstOffset.x = 0;
12173 resolveRegion.dstOffset.y = 0;
12174 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012175 resolveRegion.extent.width = 1;
12176 resolveRegion.extent.height = 1;
12177 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012178 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12179 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012180 EndCommandBuffer();
12181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012182 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012183
Chia-I Wuf7458c52015-10-26 21:10:41 +080012184 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012185 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012186 vkFreeMemory(m_device->device(), srcMem, NULL);
12187 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012188}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012189
Karl Schultz6addd812016-02-02 17:17:23 -070012190TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012191 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012192 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12193 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012194 // The image format check comes 2nd in validation so we trigger it first,
12195 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012196 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012197
Karl Schultz6addd812016-02-02 17:17:23 -070012198 m_errorMonitor->SetDesiredFailureMsg(
12199 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012200 "Combination depth/stencil image formats can have only the ");
12201
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012202 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012203
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012205 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12206 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012207
12208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12210 ds_pool_ci.pNext = NULL;
12211 ds_pool_ci.maxSets = 1;
12212 ds_pool_ci.poolSizeCount = 1;
12213 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012214
12215 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012216 err =
12217 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012218 ASSERT_VK_SUCCESS(err);
12219
12220 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012221 dsl_binding.binding = 0;
12222 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12223 dsl_binding.descriptorCount = 1;
12224 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12225 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012226
12227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12229 ds_layout_ci.pNext = NULL;
12230 ds_layout_ci.bindingCount = 1;
12231 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012232 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12234 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012235 ASSERT_VK_SUCCESS(err);
12236
12237 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012238 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012239 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012240 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012241 alloc_info.descriptorPool = ds_pool;
12242 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012243 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12244 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012245 ASSERT_VK_SUCCESS(err);
12246
Karl Schultz6addd812016-02-02 17:17:23 -070012247 VkImage image_bad;
12248 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012249 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012250 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012251 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012252 const int32_t tex_width = 32;
12253 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012254
12255 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012256 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12257 image_create_info.pNext = NULL;
12258 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12259 image_create_info.format = tex_format_bad;
12260 image_create_info.extent.width = tex_width;
12261 image_create_info.extent.height = tex_height;
12262 image_create_info.extent.depth = 1;
12263 image_create_info.mipLevels = 1;
12264 image_create_info.arrayLayers = 1;
12265 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12266 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12267 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12268 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12269 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012270
Karl Schultz6addd812016-02-02 17:17:23 -070012271 err =
12272 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012273 ASSERT_VK_SUCCESS(err);
12274 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012275 image_create_info.usage =
12276 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12277 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12278 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012279 ASSERT_VK_SUCCESS(err);
12280
12281 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012282 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12283 image_view_create_info.image = image_bad;
12284 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12285 image_view_create_info.format = tex_format_bad;
12286 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12287 image_view_create_info.subresourceRange.baseMipLevel = 0;
12288 image_view_create_info.subresourceRange.layerCount = 1;
12289 image_view_create_info.subresourceRange.levelCount = 1;
12290 image_view_create_info.subresourceRange.aspectMask =
12291 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012292
12293 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012294 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12295 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012296
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012297 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012298
Chia-I Wuf7458c52015-10-26 21:10:41 +080012299 vkDestroyImage(m_device->device(), image_bad, NULL);
12300 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012301 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12302 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012303}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012304
12305TEST_F(VkLayerTest, ClearImageErrors) {
12306 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12307 "ClearDepthStencilImage with a color image.");
12308
12309 ASSERT_NO_FATAL_FAILURE(InitState());
12310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12311
12312 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12313 BeginCommandBuffer();
12314 m_commandBuffer->EndRenderPass();
12315
12316 // Color image
12317 VkClearColorValue clear_color;
12318 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12319 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12320 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12321 const int32_t img_width = 32;
12322 const int32_t img_height = 32;
12323 VkImageCreateInfo image_create_info = {};
12324 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12325 image_create_info.pNext = NULL;
12326 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12327 image_create_info.format = color_format;
12328 image_create_info.extent.width = img_width;
12329 image_create_info.extent.height = img_height;
12330 image_create_info.extent.depth = 1;
12331 image_create_info.mipLevels = 1;
12332 image_create_info.arrayLayers = 1;
12333 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12334 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12335 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12336
12337 vk_testing::Image color_image;
12338 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12339 reqs);
12340
12341 const VkImageSubresourceRange color_range =
12342 vk_testing::Image::subresource_range(image_create_info,
12343 VK_IMAGE_ASPECT_COLOR_BIT);
12344
12345 // Depth/Stencil image
12346 VkClearDepthStencilValue clear_value = {0};
12347 reqs = 0; // don't need HOST_VISIBLE DS image
12348 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12349 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12350 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12351 ds_image_create_info.extent.width = 64;
12352 ds_image_create_info.extent.height = 64;
12353 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12354 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12355
12356 vk_testing::Image ds_image;
12357 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12358 reqs);
12359
12360 const VkImageSubresourceRange ds_range =
12361 vk_testing::Image::subresource_range(ds_image_create_info,
12362 VK_IMAGE_ASPECT_DEPTH_BIT);
12363
12364 m_errorMonitor->SetDesiredFailureMsg(
12365 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12366 "vkCmdClearColorImage called with depth/stencil image.");
12367
12368 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12369 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12370 &color_range);
12371
12372 m_errorMonitor->VerifyFound();
12373
Tony Barbour26434b92016-06-02 09:43:50 -060012374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12375 "vkCmdClearColorImage called with "
12376 "image created without "
12377 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12378
12379 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12380 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12381 &color_range);
12382
12383 m_errorMonitor->VerifyFound();
12384
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012385 // Call CmdClearDepthStencilImage with color image
12386 m_errorMonitor->SetDesiredFailureMsg(
12387 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12388 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12389
12390 vkCmdClearDepthStencilImage(
12391 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12392 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12393 &ds_range);
12394
12395 m_errorMonitor->VerifyFound();
12396}
Tobin Ehliscde08892015-09-22 10:11:37 -060012397#endif // IMAGE_TESTS
12398
Tony Barbour300a6082015-04-07 13:44:53 -060012399int main(int argc, char **argv) {
12400 int result;
12401
Cody Northrop8e54a402016-03-08 22:25:52 -070012402#ifdef ANDROID
12403 int vulkanSupport = InitVulkan();
12404 if (vulkanSupport == 0)
12405 return 1;
12406#endif
12407
Tony Barbour300a6082015-04-07 13:44:53 -060012408 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012409 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012410
12411 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12412
12413 result = RUN_ALL_TESTS();
12414
Tony Barbour6918cd52015-04-09 12:58:51 -060012415 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012416 return result;
12417}