blob: d0979cc0a00822e6aa1a03617bf3f5226842ce74 [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
Mark Youngc89c6312016-03-31 16:03:20 -06008726TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8727 // Create Pipeline where the number of blend attachments doesn't match the
8728 // number of color attachments. In this case, we don't add any color
8729 // blend attachments even though we have a color attachment.
8730 VkResult err;
8731
8732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008733 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008734
8735 ASSERT_NO_FATAL_FAILURE(InitState());
8736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8737 VkDescriptorPoolSize ds_type_count = {};
8738 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8739 ds_type_count.descriptorCount = 1;
8740
8741 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8742 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8743 ds_pool_ci.pNext = NULL;
8744 ds_pool_ci.maxSets = 1;
8745 ds_pool_ci.poolSizeCount = 1;
8746 ds_pool_ci.pPoolSizes = &ds_type_count;
8747
8748 VkDescriptorPool ds_pool;
8749 err =
8750 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8751 ASSERT_VK_SUCCESS(err);
8752
8753 VkDescriptorSetLayoutBinding dsl_binding = {};
8754 dsl_binding.binding = 0;
8755 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8756 dsl_binding.descriptorCount = 1;
8757 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8758 dsl_binding.pImmutableSamplers = NULL;
8759
8760 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8761 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8762 ds_layout_ci.pNext = NULL;
8763 ds_layout_ci.bindingCount = 1;
8764 ds_layout_ci.pBindings = &dsl_binding;
8765
8766 VkDescriptorSetLayout ds_layout;
8767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8768 &ds_layout);
8769 ASSERT_VK_SUCCESS(err);
8770
8771 VkDescriptorSet descriptorSet;
8772 VkDescriptorSetAllocateInfo alloc_info = {};
8773 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8774 alloc_info.descriptorSetCount = 1;
8775 alloc_info.descriptorPool = ds_pool;
8776 alloc_info.pSetLayouts = &ds_layout;
8777 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8778 &descriptorSet);
8779 ASSERT_VK_SUCCESS(err);
8780
8781 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8782 pipe_ms_state_ci.sType =
8783 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8784 pipe_ms_state_ci.pNext = NULL;
8785 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8786 pipe_ms_state_ci.sampleShadingEnable = 0;
8787 pipe_ms_state_ci.minSampleShading = 1.0;
8788 pipe_ms_state_ci.pSampleMask = NULL;
8789
8790 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8791 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8792 pipeline_layout_ci.pNext = NULL;
8793 pipeline_layout_ci.setLayoutCount = 1;
8794 pipeline_layout_ci.pSetLayouts = &ds_layout;
8795
8796 VkPipelineLayout pipeline_layout;
8797 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8798 &pipeline_layout);
8799 ASSERT_VK_SUCCESS(err);
8800
8801 VkShaderObj vs(m_device, bindStateVertShaderText,
8802 VK_SHADER_STAGE_VERTEX_BIT, this);
8803 VkShaderObj fs(m_device, bindStateFragShaderText,
8804 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008805 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06008806 // but add it to be able to run on more devices
8807 VkPipelineObj pipe(m_device);
8808 pipe.AddShader(&vs);
8809 pipe.AddShader(&fs);
8810 pipe.SetMSAA(&pipe_ms_state_ci);
8811 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8812
8813 BeginCommandBuffer();
8814 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8815 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8816
Mark Young29927482016-05-04 14:38:51 -06008817 // Render triangle (the error should trigger on the attempt to draw).
8818 Draw(3, 1, 0, 0);
8819
8820 // Finalize recording of the command buffer
8821 EndCommandBuffer();
8822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008823 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06008824
8825 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8828}
Mark Young29927482016-05-04 14:38:51 -06008829
Mark Muellerd4914412016-06-13 17:52:06 -06008830TEST_F(VkLayerTest, MissingClearAttachment) {
8831 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
8832 "structure passed to vkCmdClearAttachments");
8833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8834 "vkCmdClearAttachments() attachment index 1 not found in attachment "
8835 "reference array of active subpass 0");
8836
8837 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
8838 m_errorMonitor->VerifyFound();
8839}
8840
Karl Schultz6addd812016-02-02 17:17:23 -07008841TEST_F(VkLayerTest, ClearCmdNoDraw) {
8842 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
8843 // to issuing a Draw
8844 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008845
Karl Schultz6addd812016-02-02 17:17:23 -07008846 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07008847 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008848 "vkCmdClearAttachments() issued on CB object ");
8849
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008850 ASSERT_NO_FATAL_FAILURE(InitState());
8851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008852
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008853 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008854 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8855 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008856
8857 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008858 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8859 ds_pool_ci.pNext = NULL;
8860 ds_pool_ci.maxSets = 1;
8861 ds_pool_ci.poolSizeCount = 1;
8862 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008863
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008864 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008865 err =
8866 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008867 ASSERT_VK_SUCCESS(err);
8868
Tony Barboureb254902015-07-15 12:50:33 -06008869 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008870 dsl_binding.binding = 0;
8871 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8872 dsl_binding.descriptorCount = 1;
8873 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8874 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008875
Tony Barboureb254902015-07-15 12:50:33 -06008876 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008877 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8878 ds_layout_ci.pNext = NULL;
8879 ds_layout_ci.bindingCount = 1;
8880 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008881
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008882 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8884 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008885 ASSERT_VK_SUCCESS(err);
8886
8887 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008888 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008890 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008891 alloc_info.descriptorPool = ds_pool;
8892 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8894 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008895 ASSERT_VK_SUCCESS(err);
8896
Tony Barboureb254902015-07-15 12:50:33 -06008897 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008898 pipe_ms_state_ci.sType =
8899 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8900 pipe_ms_state_ci.pNext = NULL;
8901 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8902 pipe_ms_state_ci.sampleShadingEnable = 0;
8903 pipe_ms_state_ci.minSampleShading = 1.0;
8904 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008905
Tony Barboureb254902015-07-15 12:50:33 -06008906 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008907 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8908 pipeline_layout_ci.pNext = NULL;
8909 pipeline_layout_ci.setLayoutCount = 1;
8910 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008911
8912 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8914 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008915 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008916
Karl Schultz6addd812016-02-02 17:17:23 -07008917 VkShaderObj vs(m_device, bindStateVertShaderText,
8918 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06008919 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07008920 // on more devices
8921 VkShaderObj fs(m_device, bindStateFragShaderText,
8922 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008923
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008924 VkPipelineObj pipe(m_device);
8925 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008926 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008927 pipe.SetMSAA(&pipe_ms_state_ci);
8928 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008929
8930 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008931
Karl Schultz6addd812016-02-02 17:17:23 -07008932 // Main thing we care about for this test is that the VkImage obj we're
8933 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008934 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008935 VkClearAttachment color_attachment;
8936 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8937 color_attachment.clearValue.color.float32[0] = 1.0;
8938 color_attachment.clearValue.color.float32[1] = 1.0;
8939 color_attachment.clearValue.color.float32[2] = 1.0;
8940 color_attachment.clearValue.color.float32[3] = 1.0;
8941 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008942 VkClearRect clear_rect = {
8943 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008944
Karl Schultz6addd812016-02-02 17:17:23 -07008945 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8946 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008947
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008948 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008949
Chia-I Wuf7458c52015-10-26 21:10:41 +08008950 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8952 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008953}
8954
Karl Schultz6addd812016-02-02 17:17:23 -07008955TEST_F(VkLayerTest, VtxBufferBadIndex) {
8956 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008957
Karl Schultz6addd812016-02-02 17:17:23 -07008958 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008959 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008960 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008961
Tobin Ehlis502480b2015-06-24 15:53:07 -06008962 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008963 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008965
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008966 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8968 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008969
8970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8972 ds_pool_ci.pNext = NULL;
8973 ds_pool_ci.maxSets = 1;
8974 ds_pool_ci.poolSizeCount = 1;
8975 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008976
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008977 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008978 err =
8979 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008980 ASSERT_VK_SUCCESS(err);
8981
Tony Barboureb254902015-07-15 12:50:33 -06008982 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008983 dsl_binding.binding = 0;
8984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8985 dsl_binding.descriptorCount = 1;
8986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8987 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008988
Tony Barboureb254902015-07-15 12:50:33 -06008989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8991 ds_layout_ci.pNext = NULL;
8992 ds_layout_ci.bindingCount = 1;
8993 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008994
Tobin Ehlis502480b2015-06-24 15:53:07 -06008995 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8997 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008998 ASSERT_VK_SUCCESS(err);
8999
9000 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009001 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009002 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009003 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009004 alloc_info.descriptorPool = ds_pool;
9005 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009006 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9007 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009008 ASSERT_VK_SUCCESS(err);
9009
Tony Barboureb254902015-07-15 12:50:33 -06009010 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009011 pipe_ms_state_ci.sType =
9012 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9013 pipe_ms_state_ci.pNext = NULL;
9014 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9015 pipe_ms_state_ci.sampleShadingEnable = 0;
9016 pipe_ms_state_ci.minSampleShading = 1.0;
9017 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009018
Tony Barboureb254902015-07-15 12:50:33 -06009019 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009020 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9021 pipeline_layout_ci.pNext = NULL;
9022 pipeline_layout_ci.setLayoutCount = 1;
9023 pipeline_layout_ci.pSetLayouts = &ds_layout;
9024 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009025
Karl Schultz6addd812016-02-02 17:17:23 -07009026 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9027 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009028 ASSERT_VK_SUCCESS(err);
9029
Karl Schultz6addd812016-02-02 17:17:23 -07009030 VkShaderObj vs(m_device, bindStateVertShaderText,
9031 VK_SHADER_STAGE_VERTEX_BIT, this);
9032 VkShaderObj fs(m_device, bindStateFragShaderText,
9033 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009034 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009035 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009036 VkPipelineObj pipe(m_device);
9037 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009038 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009039 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009040 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009041 pipe.SetViewport(m_viewports);
9042 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009043 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009044
9045 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009046 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9047 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009048 // Don't care about actual data, just need to get to draw to flag error
9049 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009050 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9051 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009052 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009053 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009055 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009056
Chia-I Wuf7458c52015-10-26 21:10:41 +08009057 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009060}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009061// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9062TEST_F(VkLayerTest, InvalidImageLayout) {
9063 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9064 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9065 "images in the wrong layout when they're copied or transitioned.");
9066 // 3 in ValidateCmdBufImageLayouts
9067 // * -1 Attempt to submit cmd buf w/ deleted image
9068 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9069 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9070 m_errorMonitor->SetDesiredFailureMsg(
9071 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9072 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9073
9074 ASSERT_NO_FATAL_FAILURE(InitState());
9075 // Create src & dst images to use for copy operations
9076 VkImage src_image;
9077 VkImage dst_image;
9078
9079 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9080 const int32_t tex_width = 32;
9081 const int32_t tex_height = 32;
9082
9083 VkImageCreateInfo image_create_info = {};
9084 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9085 image_create_info.pNext = NULL;
9086 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9087 image_create_info.format = tex_format;
9088 image_create_info.extent.width = tex_width;
9089 image_create_info.extent.height = tex_height;
9090 image_create_info.extent.depth = 1;
9091 image_create_info.mipLevels = 1;
9092 image_create_info.arrayLayers = 4;
9093 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9094 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9095 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9096 image_create_info.flags = 0;
9097
9098 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9099 ASSERT_VK_SUCCESS(err);
9100 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9101 ASSERT_VK_SUCCESS(err);
9102
9103 BeginCommandBuffer();
9104 VkImageCopy copyRegion;
9105 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9106 copyRegion.srcSubresource.mipLevel = 0;
9107 copyRegion.srcSubresource.baseArrayLayer = 0;
9108 copyRegion.srcSubresource.layerCount = 1;
9109 copyRegion.srcOffset.x = 0;
9110 copyRegion.srcOffset.y = 0;
9111 copyRegion.srcOffset.z = 0;
9112 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9113 copyRegion.dstSubresource.mipLevel = 0;
9114 copyRegion.dstSubresource.baseArrayLayer = 0;
9115 copyRegion.dstSubresource.layerCount = 1;
9116 copyRegion.dstOffset.x = 0;
9117 copyRegion.dstOffset.y = 0;
9118 copyRegion.dstOffset.z = 0;
9119 copyRegion.extent.width = 1;
9120 copyRegion.extent.height = 1;
9121 copyRegion.extent.depth = 1;
9122 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9123 m_errorMonitor->VerifyFound();
9124 // Now cause error due to src image layout changing
9125 m_errorMonitor->SetDesiredFailureMsg(
9126 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9127 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9128 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9129 m_errorMonitor->VerifyFound();
9130 // Final src error is due to bad layout type
9131 m_errorMonitor->SetDesiredFailureMsg(
9132 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9133 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9134 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9135 m_errorMonitor->VerifyFound();
9136 // Now verify same checks for dst
9137 m_errorMonitor->SetDesiredFailureMsg(
9138 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9139 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9140 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9141 m_errorMonitor->VerifyFound();
9142 // Now cause error due to src image layout changing
9143 m_errorMonitor->SetDesiredFailureMsg(
9144 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9145 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9146 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9147 m_errorMonitor->VerifyFound();
9148 m_errorMonitor->SetDesiredFailureMsg(
9149 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9150 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9151 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9152 m_errorMonitor->VerifyFound();
9153 // Now cause error due to bad image layout transition in PipelineBarrier
9154 VkImageMemoryBarrier image_barrier[1] = {};
9155 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9156 image_barrier[0].image = src_image;
9157 image_barrier[0].subresourceRange.layerCount = 2;
9158 image_barrier[0].subresourceRange.levelCount = 2;
9159 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9160 m_errorMonitor->SetDesiredFailureMsg(
9161 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9162 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9163 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9164 m_errorMonitor->VerifyFound();
9165
9166 // Finally some layout errors at RenderPass create time
9167 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9168 VkAttachmentReference attach = {};
9169 // perf warning for GENERAL layout w/ non-DS input attachment
9170 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9171 VkSubpassDescription subpass = {};
9172 subpass.inputAttachmentCount = 1;
9173 subpass.pInputAttachments = &attach;
9174 VkRenderPassCreateInfo rpci = {};
9175 rpci.subpassCount = 1;
9176 rpci.pSubpasses = &subpass;
9177 rpci.attachmentCount = 1;
9178 VkAttachmentDescription attach_desc = {};
9179 attach_desc.format = VK_FORMAT_UNDEFINED;
9180 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009181 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009182 VkRenderPass rp;
9183 m_errorMonitor->SetDesiredFailureMsg(
9184 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9185 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9186 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9187 m_errorMonitor->VerifyFound();
9188 // error w/ non-general layout
9189 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9190
9191 m_errorMonitor->SetDesiredFailureMsg(
9192 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9193 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9194 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9195 m_errorMonitor->VerifyFound();
9196 subpass.inputAttachmentCount = 0;
9197 subpass.colorAttachmentCount = 1;
9198 subpass.pColorAttachments = &attach;
9199 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9200 // perf warning for GENERAL layout on color attachment
9201 m_errorMonitor->SetDesiredFailureMsg(
9202 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9203 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9204 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9205 m_errorMonitor->VerifyFound();
9206 // error w/ non-color opt or GENERAL layout for color attachment
9207 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9208 m_errorMonitor->SetDesiredFailureMsg(
9209 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9210 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9211 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9212 m_errorMonitor->VerifyFound();
9213 subpass.colorAttachmentCount = 0;
9214 subpass.pDepthStencilAttachment = &attach;
9215 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9216 // perf warning for GENERAL layout on DS attachment
9217 m_errorMonitor->SetDesiredFailureMsg(
9218 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9219 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9220 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9221 m_errorMonitor->VerifyFound();
9222 // error w/ non-ds opt or GENERAL layout for color attachment
9223 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9224 m_errorMonitor->SetDesiredFailureMsg(
9225 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9226 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9227 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9228 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009229 // For this error we need a valid renderpass so create default one
9230 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9231 attach.attachment = 0;
9232 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9233 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9234 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9235 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9236 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9237 // Can't do a CLEAR load on READ_ONLY initialLayout
9238 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9239 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9240 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9242 " with invalid first layout "
9243 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9244 "ONLY_OPTIMAL");
9245 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9246 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009247
9248 vkDestroyImage(m_device->device(), src_image, NULL);
9249 vkDestroyImage(m_device->device(), dst_image, NULL);
9250}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009251#endif // DRAW_STATE_TESTS
9252
Tobin Ehlis0788f522015-05-26 16:11:58 -06009253#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009254#if GTEST_IS_THREADSAFE
9255struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009256 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009257 VkEvent event;
9258 bool bailout;
9259};
9260
Karl Schultz6addd812016-02-02 17:17:23 -07009261extern "C" void *AddToCommandBuffer(void *arg) {
9262 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009263
Karl Schultz6addd812016-02-02 17:17:23 -07009264 for (int i = 0; i < 10000; i++) {
9265 vkCmdSetEvent(data->commandBuffer, data->event,
9266 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009267 if (data->bailout) {
9268 break;
9269 }
9270 }
9271 return NULL;
9272}
9273
Karl Schultz6addd812016-02-02 17:17:23 -07009274TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009275 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009276
Karl Schultz6addd812016-02-02 17:17:23 -07009277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9278 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009279
Mike Stroyanaccf7692015-05-12 16:00:45 -06009280 ASSERT_NO_FATAL_FAILURE(InitState());
9281 ASSERT_NO_FATAL_FAILURE(InitViewport());
9282 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9283
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009284 // Calls AllocateCommandBuffers
9285 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009286
9287 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009288 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009289
9290 VkEventCreateInfo event_info;
9291 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009292 VkResult err;
9293
9294 memset(&event_info, 0, sizeof(event_info));
9295 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9296
Chia-I Wuf7458c52015-10-26 21:10:41 +08009297 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009298 ASSERT_VK_SUCCESS(err);
9299
Mike Stroyanaccf7692015-05-12 16:00:45 -06009300 err = vkResetEvent(device(), event);
9301 ASSERT_VK_SUCCESS(err);
9302
9303 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009304 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009305 data.event = event;
9306 data.bailout = false;
9307 m_errorMonitor->SetBailout(&data.bailout);
9308 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009309 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009310 // Add many entries to command buffer from this thread at the same time.
9311 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009312
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009313 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009314 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009315
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009316 m_errorMonitor->SetBailout(NULL);
9317
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009318 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009319
Chia-I Wuf7458c52015-10-26 21:10:41 +08009320 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009321}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009322#endif // GTEST_IS_THREADSAFE
9323#endif // THREADING_TESTS
9324
Chris Forbes9f7ff632015-05-25 11:13:08 +12009325#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009326TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009328 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009329
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009330 ASSERT_NO_FATAL_FAILURE(InitState());
9331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9332
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009333 VkShaderModule module;
9334 VkShaderModuleCreateInfo moduleCreateInfo;
9335 struct icd_spv_header spv;
9336
9337 spv.magic = ICD_SPV_MAGIC;
9338 spv.version = ICD_SPV_VERSION;
9339 spv.gen_magic = 0;
9340
9341 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9342 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009343 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009344 moduleCreateInfo.codeSize = 4;
9345 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009346 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009347
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009348 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009349}
9350
Karl Schultz6addd812016-02-02 17:17:23 -07009351TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009353 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009354
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009355 ASSERT_NO_FATAL_FAILURE(InitState());
9356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9357
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009358 VkShaderModule module;
9359 VkShaderModuleCreateInfo moduleCreateInfo;
9360 struct icd_spv_header spv;
9361
9362 spv.magic = ~ICD_SPV_MAGIC;
9363 spv.version = ICD_SPV_VERSION;
9364 spv.gen_magic = 0;
9365
9366 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9367 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009368 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009369 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9370 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009371 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009372
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009373 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009374}
9375
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009376#if 0
9377// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009378TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009380 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009381
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009382 ASSERT_NO_FATAL_FAILURE(InitState());
9383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9384
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009385 VkShaderModule module;
9386 VkShaderModuleCreateInfo moduleCreateInfo;
9387 struct icd_spv_header spv;
9388
9389 spv.magic = ICD_SPV_MAGIC;
9390 spv.version = ~ICD_SPV_VERSION;
9391 spv.gen_magic = 0;
9392
9393 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9394 moduleCreateInfo.pNext = NULL;
9395
Karl Schultz6addd812016-02-02 17:17:23 -07009396 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009397 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9398 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009399 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009400
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009401 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009402}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009403#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009404
Karl Schultz6addd812016-02-02 17:17:23 -07009405TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009407 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009408
Chris Forbes9f7ff632015-05-25 11:13:08 +12009409 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009411
9412 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009413 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009414 "\n"
9415 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009416 "out gl_PerVertex {\n"
9417 " vec4 gl_Position;\n"
9418 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009419 "void main(){\n"
9420 " gl_Position = vec4(1);\n"
9421 " x = 0;\n"
9422 "}\n";
9423 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009424 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009425 "\n"
9426 "layout(location=0) out vec4 color;\n"
9427 "void main(){\n"
9428 " color = vec4(1);\n"
9429 "}\n";
9430
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009431 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9432 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009433
9434 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009435 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009436 pipe.AddShader(&vs);
9437 pipe.AddShader(&fs);
9438
Chris Forbes9f7ff632015-05-25 11:13:08 +12009439 VkDescriptorSetObj descriptorSet(m_device);
9440 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009441 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009442
Tony Barbour5781e8f2015-08-04 16:23:11 -06009443 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009445 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009446}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009447
Karl Schultz6addd812016-02-02 17:17:23 -07009448TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009450 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009451
Chris Forbes59cb88d2015-05-25 11:13:13 +12009452 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009454
9455 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009456 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009457 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009458 "out gl_PerVertex {\n"
9459 " vec4 gl_Position;\n"
9460 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009461 "void main(){\n"
9462 " gl_Position = vec4(1);\n"
9463 "}\n";
9464 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009465 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009466 "\n"
9467 "layout(location=0) in float x;\n"
9468 "layout(location=0) out vec4 color;\n"
9469 "void main(){\n"
9470 " color = vec4(x);\n"
9471 "}\n";
9472
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009473 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9474 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009475
9476 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009477 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009478 pipe.AddShader(&vs);
9479 pipe.AddShader(&fs);
9480
Chris Forbes59cb88d2015-05-25 11:13:13 +12009481 VkDescriptorSetObj descriptorSet(m_device);
9482 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009483 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009484
Tony Barbour5781e8f2015-08-04 16:23:11 -06009485 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009486
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009487 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009488}
9489
Karl Schultz6addd812016-02-02 17:17:23 -07009490TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009492 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009493
9494 ASSERT_NO_FATAL_FAILURE(InitState());
9495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9496
9497 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009498 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009499 "\n"
9500 "out gl_PerVertex {\n"
9501 " vec4 gl_Position;\n"
9502 "};\n"
9503 "void main(){\n"
9504 " gl_Position = vec4(1);\n"
9505 "}\n";
9506 char const *fsSource =
9507 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009508 "\n"
9509 "in block { layout(location=0) float x; } ins;\n"
9510 "layout(location=0) out vec4 color;\n"
9511 "void main(){\n"
9512 " color = vec4(ins.x);\n"
9513 "}\n";
9514
9515 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9516 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9517
9518 VkPipelineObj pipe(m_device);
9519 pipe.AddColorAttachment();
9520 pipe.AddShader(&vs);
9521 pipe.AddShader(&fs);
9522
9523 VkDescriptorSetObj descriptorSet(m_device);
9524 descriptorSet.AppendDummy();
9525 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9526
9527 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009529 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009530}
9531
Karl Schultz6addd812016-02-02 17:17:23 -07009532TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009534 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009535 "output arr[2] of float32' vs 'ptr to "
9536 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009537
9538 ASSERT_NO_FATAL_FAILURE(InitState());
9539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9540
9541 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009542 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009543 "\n"
9544 "layout(location=0) out float x[2];\n"
9545 "out gl_PerVertex {\n"
9546 " vec4 gl_Position;\n"
9547 "};\n"
9548 "void main(){\n"
9549 " x[0] = 0; x[1] = 0;\n"
9550 " gl_Position = vec4(1);\n"
9551 "}\n";
9552 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009553 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009554 "\n"
9555 "layout(location=0) in float x[3];\n"
9556 "layout(location=0) out vec4 color;\n"
9557 "void main(){\n"
9558 " color = vec4(x[0] + x[1] + x[2]);\n"
9559 "}\n";
9560
9561 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9562 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9563
9564 VkPipelineObj pipe(m_device);
9565 pipe.AddColorAttachment();
9566 pipe.AddShader(&vs);
9567 pipe.AddShader(&fs);
9568
9569 VkDescriptorSetObj descriptorSet(m_device);
9570 descriptorSet.AppendDummy();
9571 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9572
9573 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9574
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009575 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009576}
9577
Karl Schultz6addd812016-02-02 17:17:23 -07009578TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009580 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009581
Chris Forbesb56af562015-05-25 11:13:17 +12009582 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009584
9585 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009586 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009587 "\n"
9588 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009589 "out gl_PerVertex {\n"
9590 " vec4 gl_Position;\n"
9591 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009592 "void main(){\n"
9593 " x = 0;\n"
9594 " gl_Position = vec4(1);\n"
9595 "}\n";
9596 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009597 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009598 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009599 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009600 "layout(location=0) out vec4 color;\n"
9601 "void main(){\n"
9602 " color = vec4(x);\n"
9603 "}\n";
9604
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009605 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9606 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009607
9608 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009609 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009610 pipe.AddShader(&vs);
9611 pipe.AddShader(&fs);
9612
Chris Forbesb56af562015-05-25 11:13:17 +12009613 VkDescriptorSetObj descriptorSet(m_device);
9614 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009615 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009616
Tony Barbour5781e8f2015-08-04 16:23:11 -06009617 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009618
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009619 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009620}
9621
Karl Schultz6addd812016-02-02 17:17:23 -07009622TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009624 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009625
9626 ASSERT_NO_FATAL_FAILURE(InitState());
9627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9628
9629 char const *vsSource =
9630 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009631 "\n"
9632 "out block { layout(location=0) int x; } outs;\n"
9633 "out gl_PerVertex {\n"
9634 " vec4 gl_Position;\n"
9635 "};\n"
9636 "void main(){\n"
9637 " outs.x = 0;\n"
9638 " gl_Position = vec4(1);\n"
9639 "}\n";
9640 char const *fsSource =
9641 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009642 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009643 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009644 "layout(location=0) out vec4 color;\n"
9645 "void main(){\n"
9646 " color = vec4(ins.x);\n"
9647 "}\n";
9648
9649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9651
9652 VkPipelineObj pipe(m_device);
9653 pipe.AddColorAttachment();
9654 pipe.AddShader(&vs);
9655 pipe.AddShader(&fs);
9656
9657 VkDescriptorSetObj descriptorSet(m_device);
9658 descriptorSet.AppendDummy();
9659 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9660
9661 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009663 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009664}
9665
9666TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9668 "location 0.0 which is not written by vertex shader");
9669
9670 ASSERT_NO_FATAL_FAILURE(InitState());
9671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9672
9673 char const *vsSource =
9674 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009675 "\n"
9676 "out block { layout(location=1) float x; } outs;\n"
9677 "out gl_PerVertex {\n"
9678 " vec4 gl_Position;\n"
9679 "};\n"
9680 "void main(){\n"
9681 " outs.x = 0;\n"
9682 " gl_Position = vec4(1);\n"
9683 "}\n";
9684 char const *fsSource =
9685 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009686 "\n"
9687 "in block { layout(location=0) float x; } ins;\n"
9688 "layout(location=0) out vec4 color;\n"
9689 "void main(){\n"
9690 " color = vec4(ins.x);\n"
9691 "}\n";
9692
9693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9695
9696 VkPipelineObj pipe(m_device);
9697 pipe.AddColorAttachment();
9698 pipe.AddShader(&vs);
9699 pipe.AddShader(&fs);
9700
9701 VkDescriptorSetObj descriptorSet(m_device);
9702 descriptorSet.AppendDummy();
9703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9704
9705 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9706
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009707 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009708}
9709
9710TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9712 "location 0.1 which is not written by vertex shader");
9713
9714 ASSERT_NO_FATAL_FAILURE(InitState());
9715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9716
9717 char const *vsSource =
9718 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009719 "\n"
9720 "out block { layout(location=0, component=0) float x; } outs;\n"
9721 "out gl_PerVertex {\n"
9722 " vec4 gl_Position;\n"
9723 "};\n"
9724 "void main(){\n"
9725 " outs.x = 0;\n"
9726 " gl_Position = vec4(1);\n"
9727 "}\n";
9728 char const *fsSource =
9729 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009730 "\n"
9731 "in block { layout(location=0, component=1) float x; } ins;\n"
9732 "layout(location=0) out vec4 color;\n"
9733 "void main(){\n"
9734 " color = vec4(ins.x);\n"
9735 "}\n";
9736
9737 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9738 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9739
9740 VkPipelineObj pipe(m_device);
9741 pipe.AddColorAttachment();
9742 pipe.AddShader(&vs);
9743 pipe.AddShader(&fs);
9744
9745 VkDescriptorSetObj descriptorSet(m_device);
9746 descriptorSet.AppendDummy();
9747 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9748
9749 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9750
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009751 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009752}
9753
Karl Schultz6addd812016-02-02 17:17:23 -07009754TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009756 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009757
Chris Forbesde136e02015-05-25 11:13:28 +12009758 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12009760
9761 VkVertexInputBindingDescription input_binding;
9762 memset(&input_binding, 0, sizeof(input_binding));
9763
9764 VkVertexInputAttributeDescription input_attrib;
9765 memset(&input_attrib, 0, sizeof(input_attrib));
9766 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9767
9768 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009769 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009770 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009771 "out gl_PerVertex {\n"
9772 " vec4 gl_Position;\n"
9773 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009774 "void main(){\n"
9775 " gl_Position = vec4(1);\n"
9776 "}\n";
9777 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009778 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12009779 "\n"
9780 "layout(location=0) out vec4 color;\n"
9781 "void main(){\n"
9782 " color = vec4(1);\n"
9783 "}\n";
9784
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12009787
9788 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009789 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12009790 pipe.AddShader(&vs);
9791 pipe.AddShader(&fs);
9792
9793 pipe.AddVertexInputBindings(&input_binding, 1);
9794 pipe.AddVertexInputAttribs(&input_attrib, 1);
9795
Chris Forbesde136e02015-05-25 11:13:28 +12009796 VkDescriptorSetObj descriptorSet(m_device);
9797 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12009799
Tony Barbour5781e8f2015-08-04 16:23:11 -06009800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12009801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009802 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12009803}
9804
Karl Schultz6addd812016-02-02 17:17:23 -07009805TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009807 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13009808
9809 ASSERT_NO_FATAL_FAILURE(InitState());
9810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9811
9812 VkVertexInputBindingDescription input_binding;
9813 memset(&input_binding, 0, sizeof(input_binding));
9814
9815 VkVertexInputAttributeDescription input_attrib;
9816 memset(&input_attrib, 0, sizeof(input_attrib));
9817 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9818
9819 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009820 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009821 "\n"
9822 "layout(location=1) in float x;\n"
9823 "out gl_PerVertex {\n"
9824 " vec4 gl_Position;\n"
9825 "};\n"
9826 "void main(){\n"
9827 " gl_Position = vec4(x);\n"
9828 "}\n";
9829 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009830 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13009831 "\n"
9832 "layout(location=0) out vec4 color;\n"
9833 "void main(){\n"
9834 " color = vec4(1);\n"
9835 "}\n";
9836
9837 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9838 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9839
9840 VkPipelineObj pipe(m_device);
9841 pipe.AddColorAttachment();
9842 pipe.AddShader(&vs);
9843 pipe.AddShader(&fs);
9844
9845 pipe.AddVertexInputBindings(&input_binding, 1);
9846 pipe.AddVertexInputAttribs(&input_attrib, 1);
9847
9848 VkDescriptorSetObj descriptorSet(m_device);
9849 descriptorSet.AppendDummy();
9850 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9851
9852 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9853
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009854 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13009855}
9856
Karl Schultz6addd812016-02-02 17:17:23 -07009857TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
9858 m_errorMonitor->SetDesiredFailureMsg(
9859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009860 "VS consumes input at location 0 but not provided");
9861
Chris Forbes62e8e502015-05-25 11:13:29 +12009862 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12009864
9865 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009866 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009867 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009868 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07009869 "out gl_PerVertex {\n"
9870 " vec4 gl_Position;\n"
9871 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009872 "void main(){\n"
9873 " gl_Position = x;\n"
9874 "}\n";
9875 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009876 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12009877 "\n"
9878 "layout(location=0) out vec4 color;\n"
9879 "void main(){\n"
9880 " color = vec4(1);\n"
9881 "}\n";
9882
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009883 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9884 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12009885
9886 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009887 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12009888 pipe.AddShader(&vs);
9889 pipe.AddShader(&fs);
9890
Chris Forbes62e8e502015-05-25 11:13:29 +12009891 VkDescriptorSetObj descriptorSet(m_device);
9892 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009893 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12009894
Tony Barbour5781e8f2015-08-04 16:23:11 -06009895 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12009896
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009897 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12009898}
9899
Karl Schultz6addd812016-02-02 17:17:23 -07009900TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
9901 m_errorMonitor->SetDesiredFailureMsg(
9902 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009903 "location 0 does not match VS input type");
9904
Chris Forbesc97d98e2015-05-25 11:13:31 +12009905 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009907
9908 VkVertexInputBindingDescription input_binding;
9909 memset(&input_binding, 0, sizeof(input_binding));
9910
9911 VkVertexInputAttributeDescription input_attrib;
9912 memset(&input_attrib, 0, sizeof(input_attrib));
9913 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9914
9915 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009916 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009917 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009918 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009919 "out gl_PerVertex {\n"
9920 " vec4 gl_Position;\n"
9921 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009922 "void main(){\n"
9923 " gl_Position = vec4(x);\n"
9924 "}\n";
9925 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009926 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12009927 "\n"
9928 "layout(location=0) out vec4 color;\n"
9929 "void main(){\n"
9930 " color = vec4(1);\n"
9931 "}\n";
9932
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009935
9936 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009937 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009938 pipe.AddShader(&vs);
9939 pipe.AddShader(&fs);
9940
9941 pipe.AddVertexInputBindings(&input_binding, 1);
9942 pipe.AddVertexInputAttribs(&input_attrib, 1);
9943
Chris Forbesc97d98e2015-05-25 11:13:31 +12009944 VkDescriptorSetObj descriptorSet(m_device);
9945 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009946 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009947
Tony Barbour5781e8f2015-08-04 16:23:11 -06009948 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009949
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009950 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009951}
9952
Chris Forbesc68b43c2016-04-06 11:18:47 +12009953TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9954 m_errorMonitor->SetDesiredFailureMsg(
9955 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9956 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9957
9958 ASSERT_NO_FATAL_FAILURE(InitState());
9959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9960
9961 char const *vsSource =
9962 "#version 450\n"
9963 "\n"
9964 "out gl_PerVertex {\n"
9965 " vec4 gl_Position;\n"
9966 "};\n"
9967 "void main(){\n"
9968 " gl_Position = vec4(1);\n"
9969 "}\n";
9970 char const *fsSource =
9971 "#version 450\n"
9972 "\n"
9973 "layout(location=0) out vec4 color;\n"
9974 "void main(){\n"
9975 " color = vec4(1);\n"
9976 "}\n";
9977
9978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9980
9981 VkPipelineObj pipe(m_device);
9982 pipe.AddColorAttachment();
9983 pipe.AddShader(&vs);
9984 pipe.AddShader(&vs);
9985 pipe.AddShader(&fs);
9986
9987 VkDescriptorSetObj descriptorSet(m_device);
9988 descriptorSet.AppendDummy();
9989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9990
9991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009993 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009994}
9995
Karl Schultz6addd812016-02-02 17:17:23 -07009996TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009997 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009998
9999 ASSERT_NO_FATAL_FAILURE(InitState());
10000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10001
10002 VkVertexInputBindingDescription input_binding;
10003 memset(&input_binding, 0, sizeof(input_binding));
10004
10005 VkVertexInputAttributeDescription input_attribs[2];
10006 memset(input_attribs, 0, sizeof(input_attribs));
10007
10008 for (int i = 0; i < 2; i++) {
10009 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10010 input_attribs[i].location = i;
10011 }
10012
10013 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010014 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010015 "\n"
10016 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010017 "out gl_PerVertex {\n"
10018 " vec4 gl_Position;\n"
10019 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010020 "void main(){\n"
10021 " gl_Position = x[0] + x[1];\n"
10022 "}\n";
10023 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010024 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010025 "\n"
10026 "layout(location=0) out vec4 color;\n"
10027 "void main(){\n"
10028 " color = vec4(1);\n"
10029 "}\n";
10030
10031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10033
10034 VkPipelineObj pipe(m_device);
10035 pipe.AddColorAttachment();
10036 pipe.AddShader(&vs);
10037 pipe.AddShader(&fs);
10038
10039 pipe.AddVertexInputBindings(&input_binding, 1);
10040 pipe.AddVertexInputAttribs(input_attribs, 2);
10041
10042 VkDescriptorSetObj descriptorSet(m_device);
10043 descriptorSet.AppendDummy();
10044 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10045
10046 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10047
10048 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010049 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010050}
10051
Chris Forbes2682b242015-11-24 11:13:14 +130010052TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10053{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010054 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010055
10056 ASSERT_NO_FATAL_FAILURE(InitState());
10057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10058
10059 VkVertexInputBindingDescription input_binding;
10060 memset(&input_binding, 0, sizeof(input_binding));
10061
10062 VkVertexInputAttributeDescription input_attribs[2];
10063 memset(input_attribs, 0, sizeof(input_attribs));
10064
10065 for (int i = 0; i < 2; i++) {
10066 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10067 input_attribs[i].location = i;
10068 }
10069
10070 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010071 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010072 "\n"
10073 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010074 "out gl_PerVertex {\n"
10075 " vec4 gl_Position;\n"
10076 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010077 "void main(){\n"
10078 " gl_Position = x[0] + x[1];\n"
10079 "}\n";
10080 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010081 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010082 "\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(&fs);
10095
10096 pipe.AddVertexInputBindings(&input_binding, 1);
10097 pipe.AddVertexInputAttribs(input_attribs, 2);
10098
10099 VkDescriptorSetObj descriptorSet(m_device);
10100 descriptorSet.AppendDummy();
10101 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10102
10103 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10104
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010105 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010106}
Chris Forbes2682b242015-11-24 11:13:14 +130010107
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010108TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10109{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010110 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010111
10112 ASSERT_NO_FATAL_FAILURE(InitState());
10113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10114
10115 char const *vsSource =
10116 "#version 450\n"
10117 "out gl_PerVertex {\n"
10118 " vec4 gl_Position;\n"
10119 "};\n"
10120 "void main(){\n"
10121 " gl_Position = vec4(0);\n"
10122 "}\n";
10123 char const *fsSource =
10124 "#version 450\n"
10125 "\n"
10126 "layout(location=0) out vec4 color;\n"
10127 "void main(){\n"
10128 " color = vec4(1);\n"
10129 "}\n";
10130
10131 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10132 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10133
10134 VkPipelineObj pipe(m_device);
10135 pipe.AddColorAttachment();
10136 pipe.AddShader(&vs);
10137 pipe.AddShader(&fs);
10138
10139 VkDescriptorSetObj descriptorSet(m_device);
10140 descriptorSet.AppendDummy();
10141 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10142
10143 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10144
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010145 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010146}
10147
Chris Forbes912c9192016-04-05 17:50:35 +120010148TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10149{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010150 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010151
10152 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10153
10154 ASSERT_NO_FATAL_FAILURE(InitState());
10155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10156
10157 char const *vsSource =
10158 "#version 450\n"
10159 "out gl_PerVertex {\n"
10160 " vec4 gl_Position;\n"
10161 "};\n"
10162 "layout(location=0) out vec3 x;\n"
10163 "layout(location=1) out ivec3 y;\n"
10164 "layout(location=2) out vec3 z;\n"
10165 "void main(){\n"
10166 " gl_Position = vec4(0);\n"
10167 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10168 "}\n";
10169 char const *fsSource =
10170 "#version 450\n"
10171 "\n"
10172 "layout(location=0) out vec4 color;\n"
10173 "layout(location=0) in float x;\n"
10174 "layout(location=1) flat in int y;\n"
10175 "layout(location=2) in vec2 z;\n"
10176 "void main(){\n"
10177 " color = vec4(1 + x + y + z.x);\n"
10178 "}\n";
10179
10180 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10181 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10182
10183 VkPipelineObj pipe(m_device);
10184 pipe.AddColorAttachment();
10185 pipe.AddShader(&vs);
10186 pipe.AddShader(&fs);
10187
10188 VkDescriptorSetObj descriptorSet(m_device);
10189 descriptorSet.AppendDummy();
10190 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10191
10192 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10193
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010194 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010195}
10196
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010197TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10198{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010199 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010200
10201 ASSERT_NO_FATAL_FAILURE(InitState());
10202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10203
Chris Forbesc1e852d2016-04-04 19:26:42 +120010204 if (!m_device->phy().features().tessellationShader) {
10205 printf("Device does not support tessellation shaders; skipped.\n");
10206 return;
10207 }
10208
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010209 char const *vsSource =
10210 "#version 450\n"
10211 "void main(){}\n";
10212 char const *tcsSource =
10213 "#version 450\n"
10214 "layout(location=0) out int x[];\n"
10215 "layout(vertices=3) out;\n"
10216 "void main(){\n"
10217 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10218 " gl_TessLevelInner[0] = 1;\n"
10219 " x[gl_InvocationID] = gl_InvocationID;\n"
10220 "}\n";
10221 char const *tesSource =
10222 "#version 450\n"
10223 "layout(triangles, equal_spacing, cw) in;\n"
10224 "layout(location=0) in int x[];\n"
10225 "out gl_PerVertex { vec4 gl_Position; };\n"
10226 "void main(){\n"
10227 " gl_Position.xyz = gl_TessCoord;\n"
10228 " gl_Position.w = x[0] + x[1] + x[2];\n"
10229 "}\n";
10230 char const *fsSource =
10231 "#version 450\n"
10232 "layout(location=0) out vec4 color;\n"
10233 "void main(){\n"
10234 " color = vec4(1);\n"
10235 "}\n";
10236
10237 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10238 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10239 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10240 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10241
10242 VkPipelineInputAssemblyStateCreateInfo iasci{
10243 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10244 nullptr,
10245 0,
10246 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10247 VK_FALSE};
10248
Chris Forbesb4cacb62016-04-04 19:15:00 +120010249 VkPipelineTessellationStateCreateInfo tsci{
10250 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10251 nullptr,
10252 0,
10253 3};
10254
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010255 VkPipelineObj pipe(m_device);
10256 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010257 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010258 pipe.AddColorAttachment();
10259 pipe.AddShader(&vs);
10260 pipe.AddShader(&tcs);
10261 pipe.AddShader(&tes);
10262 pipe.AddShader(&fs);
10263
10264 VkDescriptorSetObj descriptorSet(m_device);
10265 descriptorSet.AppendDummy();
10266 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10267
10268 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10269
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010270 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010271}
10272
Chris Forbesa0ab8152016-04-20 13:34:27 +120010273TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10274{
10275 m_errorMonitor->ExpectSuccess();
10276
10277 ASSERT_NO_FATAL_FAILURE(InitState());
10278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10279
10280 if (!m_device->phy().features().geometryShader) {
10281 printf("Device does not support geometry shaders; skipped.\n");
10282 return;
10283 }
10284
10285 char const *vsSource =
10286 "#version 450\n"
10287 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10288 "void main(){\n"
10289 " vs_out.x = vec4(1);\n"
10290 "}\n";
10291 char const *gsSource =
10292 "#version 450\n"
10293 "layout(triangles) in;\n"
10294 "layout(triangle_strip, max_vertices=3) out;\n"
10295 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10296 "out gl_PerVertex { vec4 gl_Position; };\n"
10297 "void main() {\n"
10298 " gl_Position = gs_in[0].x;\n"
10299 " EmitVertex();\n"
10300 "}\n";
10301 char const *fsSource =
10302 "#version 450\n"
10303 "layout(location=0) out vec4 color;\n"
10304 "void main(){\n"
10305 " color = vec4(1);\n"
10306 "}\n";
10307
10308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10309 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10310 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10311
10312 VkPipelineObj pipe(m_device);
10313 pipe.AddColorAttachment();
10314 pipe.AddShader(&vs);
10315 pipe.AddShader(&gs);
10316 pipe.AddShader(&fs);
10317
10318 VkDescriptorSetObj descriptorSet(m_device);
10319 descriptorSet.AppendDummy();
10320 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10321
10322 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10323
10324 m_errorMonitor->VerifyNotFound();
10325}
10326
Chris Forbesa0193bc2016-04-04 19:19:47 +120010327TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10328{
10329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10330 "is per-vertex in tessellation control shader stage "
10331 "but per-patch in tessellation evaluation shader stage");
10332
10333 ASSERT_NO_FATAL_FAILURE(InitState());
10334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10335
Chris Forbesc1e852d2016-04-04 19:26:42 +120010336 if (!m_device->phy().features().tessellationShader) {
10337 printf("Device does not support tessellation shaders; skipped.\n");
10338 return;
10339 }
10340
Chris Forbesa0193bc2016-04-04 19:19:47 +120010341 char const *vsSource =
10342 "#version 450\n"
10343 "void main(){}\n";
10344 char const *tcsSource =
10345 "#version 450\n"
10346 "layout(location=0) out int x[];\n"
10347 "layout(vertices=3) out;\n"
10348 "void main(){\n"
10349 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10350 " gl_TessLevelInner[0] = 1;\n"
10351 " x[gl_InvocationID] = gl_InvocationID;\n"
10352 "}\n";
10353 char const *tesSource =
10354 "#version 450\n"
10355 "layout(triangles, equal_spacing, cw) in;\n"
10356 "layout(location=0) patch in int x;\n"
10357 "out gl_PerVertex { vec4 gl_Position; };\n"
10358 "void main(){\n"
10359 " gl_Position.xyz = gl_TessCoord;\n"
10360 " gl_Position.w = x;\n"
10361 "}\n";
10362 char const *fsSource =
10363 "#version 450\n"
10364 "layout(location=0) out vec4 color;\n"
10365 "void main(){\n"
10366 " color = vec4(1);\n"
10367 "}\n";
10368
10369 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10370 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10371 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10372 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10373
10374 VkPipelineInputAssemblyStateCreateInfo iasci{
10375 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10376 nullptr,
10377 0,
10378 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10379 VK_FALSE};
10380
10381 VkPipelineTessellationStateCreateInfo tsci{
10382 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10383 nullptr,
10384 0,
10385 3};
10386
10387 VkPipelineObj pipe(m_device);
10388 pipe.SetInputAssembly(&iasci);
10389 pipe.SetTessellation(&tsci);
10390 pipe.AddColorAttachment();
10391 pipe.AddShader(&vs);
10392 pipe.AddShader(&tcs);
10393 pipe.AddShader(&tes);
10394 pipe.AddShader(&fs);
10395
10396 VkDescriptorSetObj descriptorSet(m_device);
10397 descriptorSet.AppendDummy();
10398 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10399
10400 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010402 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010403}
10404
Karl Schultz6addd812016-02-02 17:17:23 -070010405TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10406 m_errorMonitor->SetDesiredFailureMsg(
10407 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010408 "Duplicate vertex input binding descriptions for binding 0");
10409
Chris Forbes280ba2c2015-06-12 11:16:41 +120010410 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010411 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010412
10413 /* Two binding descriptions for binding 0 */
10414 VkVertexInputBindingDescription input_bindings[2];
10415 memset(input_bindings, 0, sizeof(input_bindings));
10416
10417 VkVertexInputAttributeDescription input_attrib;
10418 memset(&input_attrib, 0, sizeof(input_attrib));
10419 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10420
10421 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010422 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010423 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010424 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010425 "out gl_PerVertex {\n"
10426 " vec4 gl_Position;\n"
10427 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010428 "void main(){\n"
10429 " gl_Position = vec4(x);\n"
10430 "}\n";
10431 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010432 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010433 "\n"
10434 "layout(location=0) out vec4 color;\n"
10435 "void main(){\n"
10436 " color = vec4(1);\n"
10437 "}\n";
10438
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010439 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10440 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010441
10442 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010443 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010444 pipe.AddShader(&vs);
10445 pipe.AddShader(&fs);
10446
10447 pipe.AddVertexInputBindings(input_bindings, 2);
10448 pipe.AddVertexInputAttribs(&input_attrib, 1);
10449
Chris Forbes280ba2c2015-06-12 11:16:41 +120010450 VkDescriptorSetObj descriptorSet(m_device);
10451 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010452 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010453
Tony Barbour5781e8f2015-08-04 16:23:11 -060010454 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010455
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010456 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010457}
Chris Forbes8f68b562015-05-25 11:13:32 +120010458
Chris Forbes35efec72016-04-21 14:32:08 +120010459TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10460 m_errorMonitor->ExpectSuccess();
10461
10462 ASSERT_NO_FATAL_FAILURE(InitState());
10463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10464
10465 if (!m_device->phy().features().tessellationShader) {
10466 printf("Device does not support 64bit vertex attributes; skipped.\n");
10467 return;
10468 }
10469
10470 VkVertexInputBindingDescription input_bindings[1];
10471 memset(input_bindings, 0, sizeof(input_bindings));
10472
10473 VkVertexInputAttributeDescription input_attribs[4];
10474 memset(input_attribs, 0, sizeof(input_attribs));
10475 input_attribs[0].location = 0;
10476 input_attribs[0].offset = 0;
10477 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10478 input_attribs[1].location = 2;
10479 input_attribs[1].offset = 32;
10480 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10481 input_attribs[2].location = 4;
10482 input_attribs[2].offset = 64;
10483 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10484 input_attribs[3].location = 6;
10485 input_attribs[3].offset = 96;
10486 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10487
10488 char const *vsSource =
10489 "#version 450\n"
10490 "\n"
10491 "layout(location=0) in dmat4 x;\n"
10492 "out gl_PerVertex {\n"
10493 " vec4 gl_Position;\n"
10494 "};\n"
10495 "void main(){\n"
10496 " gl_Position = vec4(x[0][0]);\n"
10497 "}\n";
10498 char const *fsSource =
10499 "#version 450\n"
10500 "\n"
10501 "layout(location=0) out vec4 color;\n"
10502 "void main(){\n"
10503 " color = vec4(1);\n"
10504 "}\n";
10505
10506 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10507 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10508
10509 VkPipelineObj pipe(m_device);
10510 pipe.AddColorAttachment();
10511 pipe.AddShader(&vs);
10512 pipe.AddShader(&fs);
10513
10514 pipe.AddVertexInputBindings(input_bindings, 1);
10515 pipe.AddVertexInputAttribs(input_attribs, 4);
10516
10517 VkDescriptorSetObj descriptorSet(m_device);
10518 descriptorSet.AppendDummy();
10519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10520
10521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10522
10523 m_errorMonitor->VerifyNotFound();
10524}
10525
Karl Schultz6addd812016-02-02 17:17:23 -070010526TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010528 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010529
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010530 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010531
10532 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010533 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010534 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010535 "out gl_PerVertex {\n"
10536 " vec4 gl_Position;\n"
10537 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010538 "void main(){\n"
10539 " gl_Position = vec4(1);\n"
10540 "}\n";
10541 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010542 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010543 "\n"
10544 "void main(){\n"
10545 "}\n";
10546
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010547 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10548 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010549
10550 VkPipelineObj pipe(m_device);
10551 pipe.AddShader(&vs);
10552 pipe.AddShader(&fs);
10553
Chia-I Wu08accc62015-07-07 11:50:03 +080010554 /* set up CB 0, not written */
10555 pipe.AddColorAttachment();
10556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010557
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010558 VkDescriptorSetObj descriptorSet(m_device);
10559 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010560 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010561
Tony Barbour5781e8f2015-08-04 16:23:11 -060010562 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010563
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010564 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010565}
10566
Karl Schultz6addd812016-02-02 17:17:23 -070010567TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010568 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010569 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010570 "FS writes to output location 1 with no matching attachment");
10571
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010572 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010573
10574 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010575 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010576 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010577 "out gl_PerVertex {\n"
10578 " vec4 gl_Position;\n"
10579 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010580 "void main(){\n"
10581 " gl_Position = vec4(1);\n"
10582 "}\n";
10583 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010584 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010585 "\n"
10586 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010587 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010588 "void main(){\n"
10589 " x = vec4(1);\n"
10590 " y = vec4(1);\n"
10591 "}\n";
10592
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010595
10596 VkPipelineObj pipe(m_device);
10597 pipe.AddShader(&vs);
10598 pipe.AddShader(&fs);
10599
Chia-I Wu08accc62015-07-07 11:50:03 +080010600 /* set up CB 0, not written */
10601 pipe.AddColorAttachment();
10602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010603 /* FS writes CB 1, but we don't configure it */
10604
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010605 VkDescriptorSetObj descriptorSet(m_device);
10606 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010607 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010608
Tony Barbour5781e8f2015-08-04 16:23:11 -060010609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010610
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010611 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010612}
10613
Karl Schultz6addd812016-02-02 17:17:23 -070010614TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010616 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010617
Chris Forbesa36d69e2015-05-25 11:13:44 +120010618 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010619
10620 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010621 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010622 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010623 "out gl_PerVertex {\n"
10624 " vec4 gl_Position;\n"
10625 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010626 "void main(){\n"
10627 " gl_Position = vec4(1);\n"
10628 "}\n";
10629 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010630 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010631 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010632 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010633 "void main(){\n"
10634 " x = ivec4(1);\n"
10635 "}\n";
10636
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010639
10640 VkPipelineObj pipe(m_device);
10641 pipe.AddShader(&vs);
10642 pipe.AddShader(&fs);
10643
Chia-I Wu08accc62015-07-07 11:50:03 +080010644 /* set up CB 0; type is UNORM by default */
10645 pipe.AddColorAttachment();
10646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010647
Chris Forbesa36d69e2015-05-25 11:13:44 +120010648 VkDescriptorSetObj descriptorSet(m_device);
10649 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010650 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010651
Tony Barbour5781e8f2015-08-04 16:23:11 -060010652 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010653
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010654 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010655}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010656
Karl Schultz6addd812016-02-02 17:17:23 -070010657TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010659 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010660
Chris Forbes556c76c2015-08-14 12:04:59 +120010661 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010662
10663 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010664 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010665 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010666 "out gl_PerVertex {\n"
10667 " vec4 gl_Position;\n"
10668 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010669 "void main(){\n"
10670 " gl_Position = vec4(1);\n"
10671 "}\n";
10672 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010673 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010674 "\n"
10675 "layout(location=0) out vec4 x;\n"
10676 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10677 "void main(){\n"
10678 " x = vec4(bar.y);\n"
10679 "}\n";
10680
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010681 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10682 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010683
Chris Forbes556c76c2015-08-14 12:04:59 +120010684 VkPipelineObj pipe(m_device);
10685 pipe.AddShader(&vs);
10686 pipe.AddShader(&fs);
10687
10688 /* set up CB 0; type is UNORM by default */
10689 pipe.AddColorAttachment();
10690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10691
10692 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010693 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010694
10695 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10696
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010697 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010698}
10699
Chris Forbes5c59e902016-02-26 16:56:09 +130010700TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10702 "not declared in layout");
10703
10704 ASSERT_NO_FATAL_FAILURE(InitState());
10705
10706 char const *vsSource =
10707 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010708 "\n"
10709 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10710 "out gl_PerVertex {\n"
10711 " vec4 gl_Position;\n"
10712 "};\n"
10713 "void main(){\n"
10714 " gl_Position = vec4(consts.x);\n"
10715 "}\n";
10716 char const *fsSource =
10717 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010718 "\n"
10719 "layout(location=0) out vec4 x;\n"
10720 "void main(){\n"
10721 " x = vec4(1);\n"
10722 "}\n";
10723
10724 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10725 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10726
10727 VkPipelineObj pipe(m_device);
10728 pipe.AddShader(&vs);
10729 pipe.AddShader(&fs);
10730
10731 /* set up CB 0; type is UNORM by default */
10732 pipe.AddColorAttachment();
10733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10734
10735 VkDescriptorSetObj descriptorSet(m_device);
10736 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10737
10738 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10739
10740 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010741 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010742}
10743
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010744TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10745 m_errorMonitor->SetDesiredFailureMsg(
10746 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10747 "Shader uses descriptor slot 0.0");
10748
10749 ASSERT_NO_FATAL_FAILURE(InitState());
10750
10751 char const *csSource =
10752 "#version 450\n"
10753 "\n"
10754 "layout(local_size_x=1) in;\n"
10755 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10756 "void main(){\n"
10757 " x = vec4(1);\n"
10758 "}\n";
10759
10760 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10761
10762 VkDescriptorSetObj descriptorSet(m_device);
10763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10764
10765 VkComputePipelineCreateInfo cpci = {
10766 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10767 nullptr, 0, {
10768 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10769 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10770 cs.handle(), "main", nullptr
10771 },
10772 descriptorSet.GetPipelineLayout(),
10773 VK_NULL_HANDLE, -1
10774 };
10775
10776 VkPipeline pipe;
10777 VkResult err = vkCreateComputePipelines(
10778 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10779
10780 m_errorMonitor->VerifyFound();
10781
10782 if (err == VK_SUCCESS) {
10783 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10784 }
10785}
10786
10787TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
10788 m_errorMonitor->ExpectSuccess();
10789
10790 ASSERT_NO_FATAL_FAILURE(InitState());
10791
10792 char const *csSource =
10793 "#version 450\n"
10794 "\n"
10795 "layout(local_size_x=1) in;\n"
10796 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10797 "void main(){\n"
10798 " // x is not used.\n"
10799 "}\n";
10800
10801 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
10802
10803 VkDescriptorSetObj descriptorSet(m_device);
10804 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10805
10806 VkComputePipelineCreateInfo cpci = {
10807 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
10808 nullptr, 0, {
10809 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
10810 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
10811 cs.handle(), "main", nullptr
10812 },
10813 descriptorSet.GetPipelineLayout(),
10814 VK_NULL_HANDLE, -1
10815 };
10816
10817 VkPipeline pipe;
10818 VkResult err = vkCreateComputePipelines(
10819 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
10820
10821 m_errorMonitor->VerifyNotFound();
10822
10823 if (err == VK_SUCCESS) {
10824 vkDestroyPipeline(m_device->device(), pipe, nullptr);
10825 }
10826}
10827
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010828#endif // SHADER_CHECKER_TESTS
10829
10830#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060010831TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070010832 m_errorMonitor->SetDesiredFailureMsg(
10833 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010834 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010835
10836 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010837
10838 // Create an image
10839 VkImage image;
10840
Karl Schultz6addd812016-02-02 17:17:23 -070010841 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10842 const int32_t tex_width = 32;
10843 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010844
10845 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10847 image_create_info.pNext = NULL;
10848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10849 image_create_info.format = tex_format;
10850 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010851 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070010852 image_create_info.extent.depth = 1;
10853 image_create_info.mipLevels = 1;
10854 image_create_info.arrayLayers = 1;
10855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10856 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10857 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10858 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010859
10860 // Introduce error by sending down a bogus width extent
10861 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010862 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010864 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060010865}
10866
Mark Youngc48c4c12016-04-11 14:26:49 -060010867TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
10868 m_errorMonitor->SetDesiredFailureMsg(
10869 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10870 "CreateImage extents is 0 for at least one required dimension");
10871
10872 ASSERT_NO_FATAL_FAILURE(InitState());
10873
10874 // Create an image
10875 VkImage image;
10876
10877 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10878 const int32_t tex_width = 32;
10879 const int32_t tex_height = 32;
10880
10881 VkImageCreateInfo image_create_info = {};
10882 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10883 image_create_info.pNext = NULL;
10884 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10885 image_create_info.format = tex_format;
10886 image_create_info.extent.width = tex_width;
10887 image_create_info.extent.height = tex_height;
10888 image_create_info.extent.depth = 1;
10889 image_create_info.mipLevels = 1;
10890 image_create_info.arrayLayers = 1;
10891 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10892 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10893 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10894 image_create_info.flags = 0;
10895
10896 // Introduce error by sending down a bogus width extent
10897 image_create_info.extent.width = 0;
10898 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
10899
10900 m_errorMonitor->VerifyFound();
10901}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010902#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120010903
Tobin Ehliscde08892015-09-22 10:11:37 -060010904#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070010905TEST_F(VkLayerTest, InvalidImageView) {
10906 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060010907
Karl Schultz6addd812016-02-02 17:17:23 -070010908 m_errorMonitor->SetDesiredFailureMsg(
10909 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010910 "vkCreateImageView called with baseMipLevel 10 ");
10911
Tobin Ehliscde08892015-09-22 10:11:37 -060010912 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060010913
Mike Stroyana3082432015-09-25 13:39:21 -060010914 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070010915 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060010916
Karl Schultz6addd812016-02-02 17:17:23 -070010917 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10918 const int32_t tex_width = 32;
10919 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060010920
10921 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010922 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10923 image_create_info.pNext = NULL;
10924 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10925 image_create_info.format = tex_format;
10926 image_create_info.extent.width = tex_width;
10927 image_create_info.extent.height = tex_height;
10928 image_create_info.extent.depth = 1;
10929 image_create_info.mipLevels = 1;
10930 image_create_info.arrayLayers = 1;
10931 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10932 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10933 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10934 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060010935
Chia-I Wuf7458c52015-10-26 21:10:41 +080010936 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060010937 ASSERT_VK_SUCCESS(err);
10938
10939 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010940 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10941 image_view_create_info.image = image;
10942 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10943 image_view_create_info.format = tex_format;
10944 image_view_create_info.subresourceRange.layerCount = 1;
10945 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
10946 image_view_create_info.subresourceRange.levelCount = 1;
10947 image_view_create_info.subresourceRange.aspectMask =
10948 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060010949
10950 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010951 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10952 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060010953
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010954 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060010955 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060010956}
Mike Stroyana3082432015-09-25 13:39:21 -060010957
Karl Schultz6addd812016-02-02 17:17:23 -070010958TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010959 TEST_DESCRIPTION(
10960 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010962 "vkCreateImageView: Color image "
10963 "formats must have ONLY the "
10964 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010965
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010966 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010967
Karl Schultz6addd812016-02-02 17:17:23 -070010968 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010969 VkImageObj image(m_device);
10970 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
10971 VK_IMAGE_TILING_LINEAR, 0);
10972 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010973
10974 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010975 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010976 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070010977 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10978 image_view_create_info.format = tex_format;
10979 image_view_create_info.subresourceRange.baseMipLevel = 0;
10980 image_view_create_info.subresourceRange.levelCount = 1;
10981 // Cause an error by setting an invalid image aspect
10982 image_view_create_info.subresourceRange.aspectMask =
10983 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010984
10985 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060010986 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010987
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010988 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010989}
10990
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010991TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010992 VkResult err;
10993 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010994
Karl Schultz6addd812016-02-02 17:17:23 -070010995 m_errorMonitor->SetDesiredFailureMsg(
10996 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010997 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010998
Mike Stroyana3082432015-09-25 13:39:21 -060010999 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011000
11001 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011002 VkImage srcImage;
11003 VkImage dstImage;
11004 VkDeviceMemory srcMem;
11005 VkDeviceMemory destMem;
11006 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011007
11008 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011009 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11010 image_create_info.pNext = NULL;
11011 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11012 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11013 image_create_info.extent.width = 32;
11014 image_create_info.extent.height = 32;
11015 image_create_info.extent.depth = 1;
11016 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011017 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011018 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11019 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11020 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11021 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011022
Karl Schultz6addd812016-02-02 17:17:23 -070011023 err =
11024 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011025 ASSERT_VK_SUCCESS(err);
11026
Karl Schultz6addd812016-02-02 17:17:23 -070011027 err =
11028 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011029 ASSERT_VK_SUCCESS(err);
11030
11031 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011032 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011033 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11034 memAlloc.pNext = NULL;
11035 memAlloc.allocationSize = 0;
11036 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011037
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011038 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011039 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011040 pass =
11041 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011042 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011043 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011044 ASSERT_VK_SUCCESS(err);
11045
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011046 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011047 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011048 pass =
11049 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011050 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011051 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011052 ASSERT_VK_SUCCESS(err);
11053
11054 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11055 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011056 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011057 ASSERT_VK_SUCCESS(err);
11058
11059 BeginCommandBuffer();
11060 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011061 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011062 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011063 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011064 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011065 copyRegion.srcOffset.x = 0;
11066 copyRegion.srcOffset.y = 0;
11067 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011068 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011069 copyRegion.dstSubresource.mipLevel = 0;
11070 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011071 // Introduce failure by forcing the dst layerCount to differ from src
11072 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011073 copyRegion.dstOffset.x = 0;
11074 copyRegion.dstOffset.y = 0;
11075 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011076 copyRegion.extent.width = 1;
11077 copyRegion.extent.height = 1;
11078 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011079 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11080 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011081 EndCommandBuffer();
11082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011083 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011084
Chia-I Wuf7458c52015-10-26 21:10:41 +080011085 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011086 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011087 vkFreeMemory(m_device->device(), srcMem, NULL);
11088 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011089}
11090
Tony Barbourd6673642016-05-05 14:46:39 -060011091TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11092
11093 TEST_DESCRIPTION("Creating images with unsuported formats ");
11094
11095 ASSERT_NO_FATAL_FAILURE(InitState());
11096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11097 VkImageObj image(m_device);
11098 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11099 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11100 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11101 VK_IMAGE_TILING_OPTIMAL, 0);
11102 ASSERT_TRUE(image.initialized());
11103
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011104 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11105 VkImageCreateInfo image_create_info;
11106 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11107 image_create_info.pNext = NULL;
11108 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11109 image_create_info.format = VK_FORMAT_UNDEFINED;
11110 image_create_info.extent.width = 32;
11111 image_create_info.extent.height = 32;
11112 image_create_info.extent.depth = 1;
11113 image_create_info.mipLevels = 1;
11114 image_create_info.arrayLayers = 1;
11115 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11116 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11117 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11118 image_create_info.flags = 0;
11119
11120 m_errorMonitor->SetDesiredFailureMsg(
11121 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11122 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11123
11124 VkImage localImage;
11125 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11126 m_errorMonitor->VerifyFound();
11127
Tony Barbourd6673642016-05-05 14:46:39 -060011128 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011129 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011130 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11131 VkFormat format = static_cast<VkFormat>(f);
11132 VkFormatProperties fProps = m_device->format_properties(format);
11133 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11134 fProps.optimalTilingFeatures == 0) {
11135 unsupported = format;
11136 break;
11137 }
11138 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011139
Tony Barbourd6673642016-05-05 14:46:39 -060011140 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011141 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011143 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011144
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011145 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011146 m_errorMonitor->VerifyFound();
11147 }
11148}
11149
11150TEST_F(VkLayerTest, ImageLayerViewTests) {
11151 VkResult ret;
11152 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11153
11154 ASSERT_NO_FATAL_FAILURE(InitState());
11155
11156 VkImageObj image(m_device);
11157 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11158 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11159 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11160 VK_IMAGE_TILING_OPTIMAL, 0);
11161 ASSERT_TRUE(image.initialized());
11162
11163 VkImageView imgView;
11164 VkImageViewCreateInfo imgViewInfo = {};
11165 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11166 imgViewInfo.image = image.handle();
11167 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11168 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11169 imgViewInfo.subresourceRange.layerCount = 1;
11170 imgViewInfo.subresourceRange.baseMipLevel = 0;
11171 imgViewInfo.subresourceRange.levelCount = 1;
11172 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11173
11174 m_errorMonitor->SetDesiredFailureMsg(
11175 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11176 "vkCreateImageView called with baseMipLevel");
11177 // View can't have baseMipLevel >= image's mipLevels - Expect
11178 // VIEW_CREATE_ERROR
11179 imgViewInfo.subresourceRange.baseMipLevel = 1;
11180 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11181 m_errorMonitor->VerifyFound();
11182 imgViewInfo.subresourceRange.baseMipLevel = 0;
11183
11184 m_errorMonitor->SetDesiredFailureMsg(
11185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11186 "vkCreateImageView called with baseArrayLayer");
11187 // View can't have baseArrayLayer >= image's arraySize - Expect
11188 // VIEW_CREATE_ERROR
11189 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11190 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11191 m_errorMonitor->VerifyFound();
11192 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11193
11194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11195 "vkCreateImageView called with 0 in "
11196 "pCreateInfo->subresourceRange."
11197 "levelCount");
11198 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11199 imgViewInfo.subresourceRange.levelCount = 0;
11200 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11201 m_errorMonitor->VerifyFound();
11202 imgViewInfo.subresourceRange.levelCount = 1;
11203
11204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11205 "vkCreateImageView called with 0 in "
11206 "pCreateInfo->subresourceRange."
11207 "layerCount");
11208 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11209 imgViewInfo.subresourceRange.layerCount = 0;
11210 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11211 m_errorMonitor->VerifyFound();
11212 imgViewInfo.subresourceRange.layerCount = 1;
11213
11214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11215 "but both must be color formats");
11216 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11217 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11218 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11219 m_errorMonitor->VerifyFound();
11220 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11221
11222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11223 "Formats MUST be IDENTICAL unless "
11224 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11225 "was set on image creation.");
11226 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11227 // VIEW_CREATE_ERROR
11228 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11229 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11230 m_errorMonitor->VerifyFound();
11231 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11232
11233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11234 "can support ImageViews with "
11235 "differing formats but they must be "
11236 "in the same compatibility class.");
11237 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11238 // VIEW_CREATE_ERROR
11239 VkImageCreateInfo mutImgInfo = image.create_info();
11240 VkImage mutImage;
11241 mutImgInfo.format = VK_FORMAT_R8_UINT;
11242 assert(
11243 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11244 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11245 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11246 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11247 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11248 ASSERT_VK_SUCCESS(ret);
11249 imgViewInfo.image = mutImage;
11250 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11251 m_errorMonitor->VerifyFound();
11252 imgViewInfo.image = image.handle();
11253 vkDestroyImage(m_device->handle(), mutImage, NULL);
11254}
11255
11256TEST_F(VkLayerTest, MiscImageLayerTests) {
11257
11258 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11259
11260 ASSERT_NO_FATAL_FAILURE(InitState());
11261
11262 VkImageObj image(m_device);
11263 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11264 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11265 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11266 VK_IMAGE_TILING_OPTIMAL, 0);
11267 ASSERT_TRUE(image.initialized());
11268
11269 m_errorMonitor->SetDesiredFailureMsg(
11270 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11271 "number of layers in image subresource is zero");
11272 vk_testing::Buffer buffer;
11273 VkMemoryPropertyFlags reqs = 0;
11274 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11275 VkBufferImageCopy region = {};
11276 region.bufferRowLength = 128;
11277 region.bufferImageHeight = 128;
11278 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11279 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11280 region.imageSubresource.layerCount = 0;
11281 region.imageExtent.height = 4;
11282 region.imageExtent.width = 4;
11283 region.imageExtent.depth = 1;
11284 m_commandBuffer->BeginCommandBuffer();
11285 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11286 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11287 1, &region);
11288 m_errorMonitor->VerifyFound();
11289 region.imageSubresource.layerCount = 1;
11290
11291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11292 "aspectMasks for each region must "
11293 "specify only COLOR or DEPTH or "
11294 "STENCIL");
11295 // Expect MISMATCHED_IMAGE_ASPECT
11296 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11298 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11299 1, &region);
11300 m_errorMonitor->VerifyFound();
11301 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11302
11303 m_errorMonitor->SetDesiredFailureMsg(
11304 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11305 "If the format of srcImage is a depth, stencil, depth stencil or "
11306 "integer-based format then filter must be VK_FILTER_NEAREST");
11307 // Expect INVALID_FILTER
11308 VkImageObj intImage1(m_device);
11309 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11310 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11311 0);
11312 VkImageObj intImage2(m_device);
11313 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11314 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11315 0);
11316 VkImageBlit blitRegion = {};
11317 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11318 blitRegion.srcSubresource.baseArrayLayer = 0;
11319 blitRegion.srcSubresource.layerCount = 1;
11320 blitRegion.srcSubresource.mipLevel = 0;
11321 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11322 blitRegion.dstSubresource.baseArrayLayer = 0;
11323 blitRegion.dstSubresource.layerCount = 1;
11324 blitRegion.dstSubresource.mipLevel = 0;
11325
11326 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11327 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11328 16, &blitRegion, VK_FILTER_LINEAR);
11329 m_errorMonitor->VerifyFound();
11330
11331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11332 "called with 0 in ppMemoryBarriers");
11333 VkImageMemoryBarrier img_barrier;
11334 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11335 img_barrier.pNext = NULL;
11336 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11337 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11338 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11339 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11340 img_barrier.image = image.handle();
11341 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11342 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11343 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11344 img_barrier.subresourceRange.baseArrayLayer = 0;
11345 img_barrier.subresourceRange.baseMipLevel = 0;
11346 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11347 img_barrier.subresourceRange.layerCount = 0;
11348 img_barrier.subresourceRange.levelCount = 1;
11349 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11350 VK_PIPELINE_STAGE_HOST_BIT,
11351 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11352 nullptr, 1, &img_barrier);
11353 m_errorMonitor->VerifyFound();
11354 img_barrier.subresourceRange.layerCount = 1;
11355}
11356
11357TEST_F(VkLayerTest, ImageFormatLimits) {
11358
11359 TEST_DESCRIPTION("Exceed the limits of image format ");
11360
11361 m_errorMonitor->SetDesiredFailureMsg(
11362 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11363 "CreateImage extents exceed allowable limits for format");
11364 VkImageCreateInfo image_create_info = {};
11365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11366 image_create_info.pNext = NULL;
11367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11368 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11369 image_create_info.extent.width = 32;
11370 image_create_info.extent.height = 32;
11371 image_create_info.extent.depth = 1;
11372 image_create_info.mipLevels = 1;
11373 image_create_info.arrayLayers = 1;
11374 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11375 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11376 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11377 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11378 image_create_info.flags = 0;
11379
11380 VkImage nullImg;
11381 VkImageFormatProperties imgFmtProps;
11382 vkGetPhysicalDeviceImageFormatProperties(
11383 gpu(), image_create_info.format, image_create_info.imageType,
11384 image_create_info.tiling, image_create_info.usage,
11385 image_create_info.flags, &imgFmtProps);
11386 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11387 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11388 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11389 m_errorMonitor->VerifyFound();
11390 image_create_info.extent.depth = 1;
11391
11392 m_errorMonitor->SetDesiredFailureMsg(
11393 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11394 "exceeds allowable maximum supported by format of");
11395 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11396 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11397 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11398 m_errorMonitor->VerifyFound();
11399 image_create_info.mipLevels = 1;
11400
11401 m_errorMonitor->SetDesiredFailureMsg(
11402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11403 "exceeds allowable maximum supported by format of");
11404 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11405 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11406 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11407 m_errorMonitor->VerifyFound();
11408 image_create_info.arrayLayers = 1;
11409
11410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11411 "is not supported by format");
11412 int samples = imgFmtProps.sampleCounts >> 1;
11413 image_create_info.samples = (VkSampleCountFlagBits)samples;
11414 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11415 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11416 m_errorMonitor->VerifyFound();
11417 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11418
11419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11420 "pCreateInfo->initialLayout, must be "
11421 "VK_IMAGE_LAYOUT_UNDEFINED or "
11422 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11423 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11424 // Expect INVALID_LAYOUT
11425 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11426 m_errorMonitor->VerifyFound();
11427 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11428}
11429
Karl Schultz6addd812016-02-02 17:17:23 -070011430TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011431 VkResult err;
11432 bool pass;
11433
11434 // Create color images with different format sizes and try to copy between them
11435 m_errorMonitor->SetDesiredFailureMsg(
11436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11437 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11438
11439 ASSERT_NO_FATAL_FAILURE(InitState());
11440
11441 // Create two images of different types and try to copy between them
11442 VkImage srcImage;
11443 VkImage dstImage;
11444 VkDeviceMemory srcMem;
11445 VkDeviceMemory destMem;
11446 VkMemoryRequirements memReqs;
11447
11448 VkImageCreateInfo image_create_info = {};
11449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11450 image_create_info.pNext = NULL;
11451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11452 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11453 image_create_info.extent.width = 32;
11454 image_create_info.extent.height = 32;
11455 image_create_info.extent.depth = 1;
11456 image_create_info.mipLevels = 1;
11457 image_create_info.arrayLayers = 1;
11458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11459 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11460 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11461 image_create_info.flags = 0;
11462
11463 err =
11464 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11465 ASSERT_VK_SUCCESS(err);
11466
11467 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11468 // Introduce failure by creating second image with a different-sized format.
11469 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11470
11471 err =
11472 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11473 ASSERT_VK_SUCCESS(err);
11474
11475 // Allocate memory
11476 VkMemoryAllocateInfo memAlloc = {};
11477 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11478 memAlloc.pNext = NULL;
11479 memAlloc.allocationSize = 0;
11480 memAlloc.memoryTypeIndex = 0;
11481
11482 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11483 memAlloc.allocationSize = memReqs.size;
11484 pass =
11485 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11486 ASSERT_TRUE(pass);
11487 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11488 ASSERT_VK_SUCCESS(err);
11489
11490 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11491 memAlloc.allocationSize = memReqs.size;
11492 pass =
11493 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11494 ASSERT_TRUE(pass);
11495 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11496 ASSERT_VK_SUCCESS(err);
11497
11498 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11499 ASSERT_VK_SUCCESS(err);
11500 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11501 ASSERT_VK_SUCCESS(err);
11502
11503 BeginCommandBuffer();
11504 VkImageCopy copyRegion;
11505 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11506 copyRegion.srcSubresource.mipLevel = 0;
11507 copyRegion.srcSubresource.baseArrayLayer = 0;
11508 copyRegion.srcSubresource.layerCount = 0;
11509 copyRegion.srcOffset.x = 0;
11510 copyRegion.srcOffset.y = 0;
11511 copyRegion.srcOffset.z = 0;
11512 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11513 copyRegion.dstSubresource.mipLevel = 0;
11514 copyRegion.dstSubresource.baseArrayLayer = 0;
11515 copyRegion.dstSubresource.layerCount = 0;
11516 copyRegion.dstOffset.x = 0;
11517 copyRegion.dstOffset.y = 0;
11518 copyRegion.dstOffset.z = 0;
11519 copyRegion.extent.width = 1;
11520 copyRegion.extent.height = 1;
11521 copyRegion.extent.depth = 1;
11522 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11523 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11524 EndCommandBuffer();
11525
11526 m_errorMonitor->VerifyFound();
11527
11528 vkDestroyImage(m_device->device(), srcImage, NULL);
11529 vkDestroyImage(m_device->device(), dstImage, NULL);
11530 vkFreeMemory(m_device->device(), srcMem, NULL);
11531 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011532}
11533
Karl Schultz6addd812016-02-02 17:17:23 -070011534TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11535 VkResult err;
11536 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011537
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011538 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011539 m_errorMonitor->SetDesiredFailureMsg(
11540 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011541 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011542
Mike Stroyana3082432015-09-25 13:39:21 -060011543 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011544
11545 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011546 VkImage srcImage;
11547 VkImage dstImage;
11548 VkDeviceMemory srcMem;
11549 VkDeviceMemory destMem;
11550 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011551
11552 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011553 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11554 image_create_info.pNext = NULL;
11555 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11556 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11557 image_create_info.extent.width = 32;
11558 image_create_info.extent.height = 32;
11559 image_create_info.extent.depth = 1;
11560 image_create_info.mipLevels = 1;
11561 image_create_info.arrayLayers = 1;
11562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11563 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11564 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11565 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011566
Karl Schultz6addd812016-02-02 17:17:23 -070011567 err =
11568 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011569 ASSERT_VK_SUCCESS(err);
11570
Karl Schultzbdb75952016-04-19 11:36:49 -060011571 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11572
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011573 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011574 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011575 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11576 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011577
Karl Schultz6addd812016-02-02 17:17:23 -070011578 err =
11579 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011580 ASSERT_VK_SUCCESS(err);
11581
11582 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011583 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011584 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11585 memAlloc.pNext = NULL;
11586 memAlloc.allocationSize = 0;
11587 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011588
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011589 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011590 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011591 pass =
11592 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011593 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011594 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011595 ASSERT_VK_SUCCESS(err);
11596
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011597 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011598 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011599 pass =
11600 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011601 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011602 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011603 ASSERT_VK_SUCCESS(err);
11604
11605 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11606 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011607 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011608 ASSERT_VK_SUCCESS(err);
11609
11610 BeginCommandBuffer();
11611 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011612 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011613 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011614 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011615 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011616 copyRegion.srcOffset.x = 0;
11617 copyRegion.srcOffset.y = 0;
11618 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011619 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011620 copyRegion.dstSubresource.mipLevel = 0;
11621 copyRegion.dstSubresource.baseArrayLayer = 0;
11622 copyRegion.dstSubresource.layerCount = 0;
11623 copyRegion.dstOffset.x = 0;
11624 copyRegion.dstOffset.y = 0;
11625 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011626 copyRegion.extent.width = 1;
11627 copyRegion.extent.height = 1;
11628 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011629 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11630 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011631 EndCommandBuffer();
11632
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011633 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011634
Chia-I Wuf7458c52015-10-26 21:10:41 +080011635 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011636 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011637 vkFreeMemory(m_device->device(), srcMem, NULL);
11638 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011639}
11640
Karl Schultz6addd812016-02-02 17:17:23 -070011641TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11642 VkResult err;
11643 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011644
Karl Schultz6addd812016-02-02 17:17:23 -070011645 m_errorMonitor->SetDesiredFailureMsg(
11646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011647 "vkCmdResolveImage called with source sample count less than 2.");
11648
Mike Stroyana3082432015-09-25 13:39:21 -060011649 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011650
11651 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011652 VkImage srcImage;
11653 VkImage dstImage;
11654 VkDeviceMemory srcMem;
11655 VkDeviceMemory destMem;
11656 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011657
11658 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011659 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11660 image_create_info.pNext = NULL;
11661 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11662 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11663 image_create_info.extent.width = 32;
11664 image_create_info.extent.height = 1;
11665 image_create_info.extent.depth = 1;
11666 image_create_info.mipLevels = 1;
11667 image_create_info.arrayLayers = 1;
11668 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11669 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11670 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11671 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011672
Karl Schultz6addd812016-02-02 17:17:23 -070011673 err =
11674 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011675 ASSERT_VK_SUCCESS(err);
11676
Karl Schultz6addd812016-02-02 17:17:23 -070011677 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011678
Karl Schultz6addd812016-02-02 17:17:23 -070011679 err =
11680 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011681 ASSERT_VK_SUCCESS(err);
11682
11683 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011684 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011685 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11686 memAlloc.pNext = NULL;
11687 memAlloc.allocationSize = 0;
11688 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011689
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011690 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011691 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011692 pass =
11693 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011694 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011695 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011696 ASSERT_VK_SUCCESS(err);
11697
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011698 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011699 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011700 pass =
11701 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011702 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011703 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011704 ASSERT_VK_SUCCESS(err);
11705
11706 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11707 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011708 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011709 ASSERT_VK_SUCCESS(err);
11710
11711 BeginCommandBuffer();
11712 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011713 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11714 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011715 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011716 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011717 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011718 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011719 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011720 resolveRegion.srcOffset.x = 0;
11721 resolveRegion.srcOffset.y = 0;
11722 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011723 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011724 resolveRegion.dstSubresource.mipLevel = 0;
11725 resolveRegion.dstSubresource.baseArrayLayer = 0;
11726 resolveRegion.dstSubresource.layerCount = 0;
11727 resolveRegion.dstOffset.x = 0;
11728 resolveRegion.dstOffset.y = 0;
11729 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011730 resolveRegion.extent.width = 1;
11731 resolveRegion.extent.height = 1;
11732 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011733 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11734 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011735 EndCommandBuffer();
11736
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011737 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011738
Chia-I Wuf7458c52015-10-26 21:10:41 +080011739 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011740 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011741 vkFreeMemory(m_device->device(), srcMem, NULL);
11742 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011743}
11744
Karl Schultz6addd812016-02-02 17:17:23 -070011745TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11746 VkResult err;
11747 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011748
Karl Schultz6addd812016-02-02 17:17:23 -070011749 m_errorMonitor->SetDesiredFailureMsg(
11750 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011751 "vkCmdResolveImage called with dest sample count greater than 1.");
11752
Mike Stroyana3082432015-09-25 13:39:21 -060011753 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011754
Chris Forbesa7530692016-05-08 12:35:39 +120011755 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011756 VkImage srcImage;
11757 VkImage dstImage;
11758 VkDeviceMemory srcMem;
11759 VkDeviceMemory destMem;
11760 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011761
11762 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011763 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11764 image_create_info.pNext = NULL;
11765 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11766 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11767 image_create_info.extent.width = 32;
11768 image_create_info.extent.height = 1;
11769 image_create_info.extent.depth = 1;
11770 image_create_info.mipLevels = 1;
11771 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120011772 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070011773 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11774 // Note: Some implementations expect color attachment usage for any
11775 // multisample surface
11776 image_create_info.usage =
11777 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11778 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011779
Karl Schultz6addd812016-02-02 17:17:23 -070011780 err =
11781 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011782 ASSERT_VK_SUCCESS(err);
11783
Karl Schultz6addd812016-02-02 17:17:23 -070011784 // Note: Some implementations expect color attachment usage for any
11785 // multisample surface
11786 image_create_info.usage =
11787 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_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, ResolveImageFormatMismatch) {
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 unmatched source and dest formats.");
11862
Mike Stroyana3082432015-09-25 13:39:21 -060011863 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011864
11865 // Create two images of different types and try to copy 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;
11882 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11883 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 // Set format to something other than source image
11895 image_create_info.format = VK_FORMAT_R32_SFLOAT;
11896 // Note: Some implementations expect color attachment usage for any
11897 // multisample surface
11898 image_create_info.usage =
11899 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11900 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011901
Karl Schultz6addd812016-02-02 17:17:23 -070011902 err =
11903 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011904 ASSERT_VK_SUCCESS(err);
11905
11906 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011907 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011908 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11909 memAlloc.pNext = NULL;
11910 memAlloc.allocationSize = 0;
11911 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011912
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011913 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011914 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011915 pass =
11916 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011917 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011918 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011919 ASSERT_VK_SUCCESS(err);
11920
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011921 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011922 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011923 pass =
11924 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011925 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011926 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011927 ASSERT_VK_SUCCESS(err);
11928
11929 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11930 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011931 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011932 ASSERT_VK_SUCCESS(err);
11933
11934 BeginCommandBuffer();
11935 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011936 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11937 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011938 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011939 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011940 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011941 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011942 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011943 resolveRegion.srcOffset.x = 0;
11944 resolveRegion.srcOffset.y = 0;
11945 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011946 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011947 resolveRegion.dstSubresource.mipLevel = 0;
11948 resolveRegion.dstSubresource.baseArrayLayer = 0;
11949 resolveRegion.dstSubresource.layerCount = 0;
11950 resolveRegion.dstOffset.x = 0;
11951 resolveRegion.dstOffset.y = 0;
11952 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011953 resolveRegion.extent.width = 1;
11954 resolveRegion.extent.height = 1;
11955 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011956 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11957 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011958 EndCommandBuffer();
11959
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011960 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011961
Chia-I Wuf7458c52015-10-26 21:10:41 +080011962 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011963 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011964 vkFreeMemory(m_device->device(), srcMem, NULL);
11965 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011966}
11967
Karl Schultz6addd812016-02-02 17:17:23 -070011968TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11969 VkResult err;
11970 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011971
Karl Schultz6addd812016-02-02 17:17:23 -070011972 m_errorMonitor->SetDesiredFailureMsg(
11973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011974 "vkCmdResolveImage called with unmatched source and dest image types.");
11975
Mike Stroyana3082432015-09-25 13:39:21 -060011976 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011977
11978 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011979 VkImage srcImage;
11980 VkImage dstImage;
11981 VkDeviceMemory srcMem;
11982 VkDeviceMemory destMem;
11983 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011984
11985 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11987 image_create_info.pNext = NULL;
11988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11989 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11990 image_create_info.extent.width = 32;
11991 image_create_info.extent.height = 1;
11992 image_create_info.extent.depth = 1;
11993 image_create_info.mipLevels = 1;
11994 image_create_info.arrayLayers = 1;
11995 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11996 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11997 // Note: Some implementations expect color attachment usage for any
11998 // multisample surface
11999 image_create_info.usage =
12000 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12001 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012002
Karl Schultz6addd812016-02-02 17:17:23 -070012003 err =
12004 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012005 ASSERT_VK_SUCCESS(err);
12006
Karl Schultz6addd812016-02-02 17:17:23 -070012007 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12008 // Note: Some implementations expect color attachment usage for any
12009 // multisample surface
12010 image_create_info.usage =
12011 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12012 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012013
Karl Schultz6addd812016-02-02 17:17:23 -070012014 err =
12015 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012016 ASSERT_VK_SUCCESS(err);
12017
12018 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012019 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012020 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12021 memAlloc.pNext = NULL;
12022 memAlloc.allocationSize = 0;
12023 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012024
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012025 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012026 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012027 pass =
12028 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012029 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012030 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012031 ASSERT_VK_SUCCESS(err);
12032
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012033 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012034 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012035 pass =
12036 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012037 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012038 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012039 ASSERT_VK_SUCCESS(err);
12040
12041 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12042 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012043 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012044 ASSERT_VK_SUCCESS(err);
12045
12046 BeginCommandBuffer();
12047 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012048 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12049 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012050 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012051 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012052 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012053 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012054 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012055 resolveRegion.srcOffset.x = 0;
12056 resolveRegion.srcOffset.y = 0;
12057 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012058 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012059 resolveRegion.dstSubresource.mipLevel = 0;
12060 resolveRegion.dstSubresource.baseArrayLayer = 0;
12061 resolveRegion.dstSubresource.layerCount = 0;
12062 resolveRegion.dstOffset.x = 0;
12063 resolveRegion.dstOffset.y = 0;
12064 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012065 resolveRegion.extent.width = 1;
12066 resolveRegion.extent.height = 1;
12067 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012068 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12069 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012070 EndCommandBuffer();
12071
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012072 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012073
Chia-I Wuf7458c52015-10-26 21:10:41 +080012074 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012075 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012076 vkFreeMemory(m_device->device(), srcMem, NULL);
12077 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012078}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012079
Karl Schultz6addd812016-02-02 17:17:23 -070012080TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012081 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012082 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12083 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012084 // The image format check comes 2nd in validation so we trigger it first,
12085 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012086 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012087
Karl Schultz6addd812016-02-02 17:17:23 -070012088 m_errorMonitor->SetDesiredFailureMsg(
12089 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012090 "Combination depth/stencil image formats can have only the ");
12091
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012092 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012093
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012094 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012095 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12096 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012097
12098 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012099 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12100 ds_pool_ci.pNext = NULL;
12101 ds_pool_ci.maxSets = 1;
12102 ds_pool_ci.poolSizeCount = 1;
12103 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012104
12105 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012106 err =
12107 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012108 ASSERT_VK_SUCCESS(err);
12109
12110 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012111 dsl_binding.binding = 0;
12112 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12113 dsl_binding.descriptorCount = 1;
12114 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12115 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012116
12117 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012118 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12119 ds_layout_ci.pNext = NULL;
12120 ds_layout_ci.bindingCount = 1;
12121 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012122 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012123 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12124 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012125 ASSERT_VK_SUCCESS(err);
12126
12127 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012128 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012129 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012130 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012131 alloc_info.descriptorPool = ds_pool;
12132 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012133 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12134 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012135 ASSERT_VK_SUCCESS(err);
12136
Karl Schultz6addd812016-02-02 17:17:23 -070012137 VkImage image_bad;
12138 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012139 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012140 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012141 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012142 const int32_t tex_width = 32;
12143 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012144
12145 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012146 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12147 image_create_info.pNext = NULL;
12148 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12149 image_create_info.format = tex_format_bad;
12150 image_create_info.extent.width = tex_width;
12151 image_create_info.extent.height = tex_height;
12152 image_create_info.extent.depth = 1;
12153 image_create_info.mipLevels = 1;
12154 image_create_info.arrayLayers = 1;
12155 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12156 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12157 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12158 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12159 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012160
Karl Schultz6addd812016-02-02 17:17:23 -070012161 err =
12162 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012163 ASSERT_VK_SUCCESS(err);
12164 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012165 image_create_info.usage =
12166 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12167 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12168 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012169 ASSERT_VK_SUCCESS(err);
12170
12171 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012172 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12173 image_view_create_info.image = image_bad;
12174 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12175 image_view_create_info.format = tex_format_bad;
12176 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12177 image_view_create_info.subresourceRange.baseMipLevel = 0;
12178 image_view_create_info.subresourceRange.layerCount = 1;
12179 image_view_create_info.subresourceRange.levelCount = 1;
12180 image_view_create_info.subresourceRange.aspectMask =
12181 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012182
12183 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012184 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12185 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012186
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012187 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012188
Chia-I Wuf7458c52015-10-26 21:10:41 +080012189 vkDestroyImage(m_device->device(), image_bad, NULL);
12190 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012191 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12192 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012193}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012194
12195TEST_F(VkLayerTest, ClearImageErrors) {
12196 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12197 "ClearDepthStencilImage with a color image.");
12198
12199 ASSERT_NO_FATAL_FAILURE(InitState());
12200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12201
12202 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12203 BeginCommandBuffer();
12204 m_commandBuffer->EndRenderPass();
12205
12206 // Color image
12207 VkClearColorValue clear_color;
12208 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12209 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12210 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12211 const int32_t img_width = 32;
12212 const int32_t img_height = 32;
12213 VkImageCreateInfo image_create_info = {};
12214 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12215 image_create_info.pNext = NULL;
12216 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12217 image_create_info.format = color_format;
12218 image_create_info.extent.width = img_width;
12219 image_create_info.extent.height = img_height;
12220 image_create_info.extent.depth = 1;
12221 image_create_info.mipLevels = 1;
12222 image_create_info.arrayLayers = 1;
12223 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12224 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12225 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12226
12227 vk_testing::Image color_image;
12228 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12229 reqs);
12230
12231 const VkImageSubresourceRange color_range =
12232 vk_testing::Image::subresource_range(image_create_info,
12233 VK_IMAGE_ASPECT_COLOR_BIT);
12234
12235 // Depth/Stencil image
12236 VkClearDepthStencilValue clear_value = {0};
12237 reqs = 0; // don't need HOST_VISIBLE DS image
12238 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12239 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12240 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12241 ds_image_create_info.extent.width = 64;
12242 ds_image_create_info.extent.height = 64;
12243 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12244 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12245
12246 vk_testing::Image ds_image;
12247 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12248 reqs);
12249
12250 const VkImageSubresourceRange ds_range =
12251 vk_testing::Image::subresource_range(ds_image_create_info,
12252 VK_IMAGE_ASPECT_DEPTH_BIT);
12253
12254 m_errorMonitor->SetDesiredFailureMsg(
12255 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12256 "vkCmdClearColorImage called with depth/stencil image.");
12257
12258 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12259 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12260 &color_range);
12261
12262 m_errorMonitor->VerifyFound();
12263
Tony Barbour26434b92016-06-02 09:43:50 -060012264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12265 "vkCmdClearColorImage called with "
12266 "image created without "
12267 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12268
12269 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12270 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12271 &color_range);
12272
12273 m_errorMonitor->VerifyFound();
12274
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012275 // Call CmdClearDepthStencilImage with color image
12276 m_errorMonitor->SetDesiredFailureMsg(
12277 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12278 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12279
12280 vkCmdClearDepthStencilImage(
12281 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12282 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12283 &ds_range);
12284
12285 m_errorMonitor->VerifyFound();
12286}
Tobin Ehliscde08892015-09-22 10:11:37 -060012287#endif // IMAGE_TESTS
12288
Tony Barbour300a6082015-04-07 13:44:53 -060012289int main(int argc, char **argv) {
12290 int result;
12291
Cody Northrop8e54a402016-03-08 22:25:52 -070012292#ifdef ANDROID
12293 int vulkanSupport = InitVulkan();
12294 if (vulkanSupport == 0)
12295 return 1;
12296#endif
12297
Tony Barbour300a6082015-04-07 13:44:53 -060012298 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012299 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012300
12301 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12302
12303 result = RUN_ALL_TESTS();
12304
Tony Barbour6918cd52015-04-09 12:58:51 -060012305 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012306 return result;
12307}