blob: f313f66b47026bbce69a1f9301a855b0c0c53ebc [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 Lobodzinski3780e142015-05-14 15:08:13 -050066} BsoFailSelect;
67
68struct vktriangle_vs_uniform {
69 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070070 float mvp[4][4];
71 float position[3][4];
72 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073};
74
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050075static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120076 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070077 "vec2 vertices[3];\n"
78 "out gl_PerVertex {\n"
79 " vec4 gl_Position;\n"
80 "};\n"
81 "void main() {\n"
82 " vertices[0] = vec2(-1.0, -1.0);\n"
83 " vertices[1] = vec2( 1.0, -1.0);\n"
84 " vertices[2] = vec2( 0.0, 1.0);\n"
85 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
86 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050087
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050088static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120089 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070090 "\n"
91 "layout(location = 0) out vec4 uFragColor;\n"
92 "void main(){\n"
93 " uFragColor = vec4(0,1,0,1);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Karl Schultz6addd812016-02-02 17:17:23 -070096static VKAPI_ATTR VkBool32 VKAPI_CALL
97myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
98 uint64_t srcObject, size_t location, int32_t msgCode,
99 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600101// ********************************************************
102// ErrorMonitor Usage:
103//
104// Call SetDesiredFailureMsg with a string to be compared against all
105// encountered log messages. Passing NULL will match all log messages.
106// logMsg will return true for skipCall only if msg is matched or NULL.
107//
108// Call DesiredMsgFound to determine if the desired failure message
109// was encountered.
110
Tony Barbour300a6082015-04-07 13:44:53 -0600111class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700112 public:
113 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_create_mutex(&m_mutex);
115 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700116 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600120
Dustin Graves48458142016-04-29 16:11:55 -0600121 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
122
Karl Schultz6addd812016-02-02 17:17:23 -0700123 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200124 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126 m_failureMsg.clear();
127 m_otherMsgs.clear();
128 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700129 m_msgFound = VK_FALSE;
130 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600132 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133
Karl Schultz6addd812016-02-02 17:17:23 -0700134 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600136 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600137 if (m_bailout != NULL) {
138 *m_bailout = true;
139 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600140 string errorString(msgString);
141 if (msgFlags & m_msgFlags) {
142 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200143 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
144 m_otherMsgs.push_back(m_failureMsg);
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700147 m_msgFound = VK_TRUE;
148 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 } else {
150 m_otherMsgs.push_back(errorString);
151 }
152 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600155 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156
Karl Schultz6addd812016-02-02 17:17:23 -0700157 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158
Karl Schultz6addd812016-02-02 17:17:23 -0700159 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600164
Karl Schultz6addd812016-02-02 17:17:23 -0700165 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 vector<string> otherMsgs = GetOtherFailureMsgs();
167 cout << "Other error messages logged for this test were:" << endl;
168 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
169 cout << " " << *iter << endl;
170 }
171 }
172
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200173 /* helpers */
174
175 void ExpectSuccess() {
176 // match anything
177 SetDesiredFailureMsg(~0u, "");
178 }
179
180 void VerifyFound() {
181 // Not seeing the desired message is a failure. /Before/ throwing, dump
182 // any other messages.
183 if (!DesiredMsgFound()) {
184 DumpFailureMsgs();
185 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
186 }
187 }
188
189 void VerifyNotFound() {
190 // ExpectSuccess() configured us to match anything. Any error is a
191 // failure.
192 if (DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
195 }
196 }
197
Karl Schultz6addd812016-02-02 17:17:23 -0700198 private:
199 VkFlags m_msgFlags;
200 string m_desiredMsg;
201 string m_failureMsg;
202 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600203 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700204 bool *m_bailout;
205 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Karl Schultz6addd812016-02-02 17:17:23 -0700208static VKAPI_ATTR VkBool32 VKAPI_CALL
209myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
210 uint64_t srcObject, size_t location, int32_t msgCode,
211 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
212 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700213 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700214 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600217 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600218 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600219}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500220
Karl Schultz6addd812016-02-02 17:17:23 -0700221class VkLayerTest : public VkRenderFramework {
222 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
224 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700225 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
226 BsoFailSelect failMask);
227 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
228 VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask);
231 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
232 VkDescriptorSetObj &descriptorSet,
233 BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
235 failMask);
236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700239 VkResult BeginCommandBuffer() {
240 return BeginCommandBuffer(*m_commandBuffer);
241 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700243 void Draw(uint32_t vertexCount, uint32_t instanceCount,
244 uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
246 firstInstance);
247 }
248 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
249 uint32_t firstIndex, int32_t vertexOffset,
250 uint32_t firstInstance) {
251 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
252 vertexOffset, firstInstance);
253 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700255 void QueueCommandBuffer(const VkFence &fence) {
256 m_commandBuffer->QueueCommandBuffer(fence);
257 }
258 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
259 VkDeviceSize offset, uint32_t binding) {
260 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
261 }
262 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
263 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
264 }
265
266 protected:
267 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600268 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600269
270 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600271 std::vector<const char *> instance_layer_names;
272 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600273 std::vector<const char *> instance_extension_names;
274 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600275
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700276 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600277 /*
278 * Since CreateDbgMsgCallback is an instance level extension call
279 * any extension / layer that utilizes that feature also needs
280 * to be enabled at create instance time.
281 */
Karl Schultz6addd812016-02-02 17:17:23 -0700282 // Use Threading layer first to protect others from
283 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700284 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600285 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800286 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700287 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800288 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
289 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600290 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700291 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600292
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700293 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600294 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800295 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700296 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800297 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
298 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600299 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700300 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600301
Ian Elliott2c1daf52016-05-12 09:41:46 -0600302 if (m_enableWSI) {
303 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
304 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
305#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
306#if defined(VK_USE_PLATFORM_ANDROID_KHR)
307 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
308#endif // VK_USE_PLATFORM_ANDROID_KHR
309#if defined(VK_USE_PLATFORM_MIR_KHR)
310 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
311#endif // VK_USE_PLATFORM_MIR_KHR
312#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
313 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
314#endif // VK_USE_PLATFORM_WAYLAND_KHR
315#if defined(VK_USE_PLATFORM_WIN32_KHR)
316 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
317#endif // VK_USE_PLATFORM_WIN32_KHR
318#endif // NEED_TO_TEST_THIS_ON_PLATFORM
319#if defined(VK_USE_PLATFORM_XCB_KHR)
320 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
321#elif defined(VK_USE_PLATFORM_XLIB_KHR)
322 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
323#endif // VK_USE_PLATFORM_XLIB_KHR
324 }
325
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600327 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800328 this->app_info.pApplicationName = "layer_tests";
329 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600330 this->app_info.pEngineName = "unittest";
331 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600332 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600333
Tony Barbour15524c32015-04-29 17:34:29 -0600334 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600335 InitFramework(instance_layer_names, device_layer_names,
336 instance_extension_names, device_extension_names,
337 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600338 }
339
340 virtual void TearDown() {
341 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600342 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600343 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600344 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600345
346 VkLayerTest() {
347 m_enableWSI = false;
348 }
Tony Barbour300a6082015-04-07 13:44:53 -0600349};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500350
Karl Schultz6addd812016-02-02 17:17:23 -0700351VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600352 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600353
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800354 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600355
356 /*
357 * For render test all drawing happens in a single render pass
358 * on a single command buffer.
359 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200360 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600362 }
363
364 return result;
365}
366
Karl Schultz6addd812016-02-02 17:17:23 -0700367VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600368 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600369
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200370 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800371 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200372 }
Tony Barbour300a6082015-04-07 13:44:53 -0600373
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600375
376 return result;
377}
378
Karl Schultz6addd812016-02-02 17:17:23 -0700379void VkLayerTest::VKTriangleTest(const char *vertShaderText,
380 const char *fragShaderText,
381 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500382 // Create identity matrix
383 int i;
384 struct vktriangle_vs_uniform data;
385
386 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700387 glm::mat4 View = glm::mat4(1.0f);
388 glm::mat4 Model = glm::mat4(1.0f);
389 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500390 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700391 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
393 memcpy(&data.mvp, &MVP[0][0], matrixSize);
394
Karl Schultz6addd812016-02-02 17:17:23 -0700395 static const Vertex tri_data[] = {
396 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
397 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
398 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500399 };
400
Karl Schultz6addd812016-02-02 17:17:23 -0700401 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402 data.position[i][0] = tri_data[i].posX;
403 data.position[i][1] = tri_data[i].posY;
404 data.position[i][2] = tri_data[i].posZ;
405 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700406 data.color[i][0] = tri_data[i].r;
407 data.color[i][1] = tri_data[i].g;
408 data.color[i][2] = tri_data[i].b;
409 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500410 }
411
412 ASSERT_NO_FATAL_FAILURE(InitState());
413 ASSERT_NO_FATAL_FAILURE(InitViewport());
414
Karl Schultz6addd812016-02-02 17:17:23 -0700415 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
416 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500417
Karl Schultz6addd812016-02-02 17:17:23 -0700418 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
419 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
420 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500421
422 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800423 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424 pipelineobj.AddShader(&vs);
425 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600426 if (failMask & BsoFailLineWidth) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
429 ia_state.sType =
430 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
431 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
432 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600433 }
434 if (failMask & BsoFailDepthBias) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 VkPipelineRasterizationStateCreateInfo rs_state = {};
437 rs_state.sType =
438 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
439 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600440 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600441 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 }
Karl Schultz6addd812016-02-02 17:17:23 -0700443 // Viewport and scissors must stay in synch or other errors will occur than
444 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600445 if (failMask & BsoFailViewport) {
446 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600447 m_viewports.clear();
448 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 }
450 if (failMask & BsoFailScissor) {
451 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600452 m_scissors.clear();
453 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600454 }
455 if (failMask & BsoFailBlend) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineColorBlendAttachmentState att_state = {};
458 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
459 att_state.blendEnable = VK_TRUE;
460 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBounds) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
464 }
465 if (failMask & BsoFailStencilReadMask) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
467 }
468 if (failMask & BsoFailStencilWriteMask) {
469 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
470 }
471 if (failMask & BsoFailStencilReference) {
472 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
473 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474
475 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700476 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
477 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478
479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600480 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Tony Barbourfe3351b2015-07-28 10:17:20 -0600482 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483
484 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600485 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600488 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500489
Tony Barbourfe3351b2015-07-28 10:17:20 -0600490 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500491}
492
Karl Schultz6addd812016-02-02 17:17:23 -0700493void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
494 VkPipelineObj &pipelineobj,
495 VkDescriptorSetObj &descriptorSet,
496 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700498 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
499 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700501 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
502 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503 }
504
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800505 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700506 // Make sure depthWriteEnable is set so that Depth fail test will work
507 // correctly
508 // Make sure stencilTestEnable is set so that Stencil fail test will work
509 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600510 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800511 stencil.failOp = VK_STENCIL_OP_KEEP;
512 stencil.passOp = VK_STENCIL_OP_KEEP;
513 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
514 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600515
516 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
517 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 ds_ci.pNext = NULL;
519 ds_ci.depthTestEnable = VK_FALSE;
520 ds_ci.depthWriteEnable = VK_TRUE;
521 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
522 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600523 if (failMask & BsoFailDepthBounds) {
524 ds_ci.depthBoundsTestEnable = VK_TRUE;
525 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600526 ds_ci.stencilTestEnable = VK_TRUE;
527 ds_ci.front = stencil;
528 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600529
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600530 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600531 pipelineobj.SetViewport(m_viewports);
532 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800533 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700534 VkResult err = pipelineobj.CreateVKPipeline(
535 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600536 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->BindPipeline(pipelineobj);
538 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500539}
540
Ian Elliott2c1daf52016-05-12 09:41:46 -0600541class VkWsiEnabledLayerTest : public VkLayerTest {
542 public:
543protected:
544 VkWsiEnabledLayerTest() {
545 m_enableWSI = true;
546 }
547};
548
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500549// ********************************************************************************************************************
550// ********************************************************************************************************************
551// ********************************************************************************************************************
552// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600553#if PARAMETER_VALIDATION_TESTS
554TEST_F(VkLayerTest, RequiredParameter) {
555 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
556 "pointer, array, and array count parameters");
557
558 ASSERT_NO_FATAL_FAILURE(InitState());
559
560 m_errorMonitor->SetDesiredFailureMsg(
561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
562 "required parameter pFeatures specified as NULL");
563 // Specify NULL for a pointer to a handle
564 // Expected to trigger an error with
565 // parameter_validation::validate_required_pointer
566 vkGetPhysicalDeviceFeatures(gpu(), NULL);
567 m_errorMonitor->VerifyFound();
568
569 m_errorMonitor->SetDesiredFailureMsg(
570 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600571 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600572 // Specify NULL for pointer to array count
573 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600574 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600575 m_errorMonitor->VerifyFound();
576
577 m_errorMonitor->SetDesiredFailureMsg(
578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
579 "parameter viewportCount must be greater than 0");
580 // Specify 0 for a required array count
581 // Expected to trigger an error with parameter_validation::validate_array
582 VkViewport view_port = {};
583 m_commandBuffer->SetViewport(0, 0, &view_port);
584 m_errorMonitor->VerifyFound();
585
586 m_errorMonitor->SetDesiredFailureMsg(
587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
588 "required parameter pViewports specified as NULL");
589 // Specify NULL for a required array
590 // Expected to trigger an error with parameter_validation::validate_array
591 m_commandBuffer->SetViewport(0, 1, NULL);
592 m_errorMonitor->VerifyFound();
593
594 m_errorMonitor->SetDesiredFailureMsg(
595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
596 "required parameter memory specified as VK_NULL_HANDLE");
597 // Specify VK_NULL_HANDLE for a required handle
598 // Expected to trigger an error with
599 // parameter_validation::validate_required_handle
600 vkUnmapMemory(device(), VK_NULL_HANDLE);
601 m_errorMonitor->VerifyFound();
602
603 m_errorMonitor->SetDesiredFailureMsg(
604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
605 "required parameter pFences[0] specified as VK_NULL_HANDLE");
606 // Specify VK_NULL_HANDLE for a required handle array entry
607 // Expected to trigger an error with
608 // parameter_validation::validate_required_handle_array
609 VkFence fence = VK_NULL_HANDLE;
610 vkResetFences(device(), 1, &fence);
611 m_errorMonitor->VerifyFound();
612
613 m_errorMonitor->SetDesiredFailureMsg(
614 VK_DEBUG_REPORT_ERROR_BIT_EXT,
615 "required parameter pAllocateInfo specified as NULL");
616 // Specify NULL for a required struct pointer
617 // Expected to trigger an error with
618 // parameter_validation::validate_struct_type
619 VkDeviceMemory memory = VK_NULL_HANDLE;
620 vkAllocateMemory(device(), NULL, NULL, &memory);
621 m_errorMonitor->VerifyFound();
622
623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
624 "value of faceMask must not be 0");
625 // Specify 0 for a required VkFlags parameter
626 // Expected to trigger an error with parameter_validation::validate_flags
627 m_commandBuffer->SetStencilReference(0, 0);
628 m_errorMonitor->VerifyFound();
629
630 m_errorMonitor->SetDesiredFailureMsg(
631 VK_DEBUG_REPORT_ERROR_BIT_EXT,
632 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
633 // Specify 0 for a required VkFlags array entry
634 // Expected to trigger an error with
635 // parameter_validation::validate_flags_array
636 VkSemaphore semaphore = VK_NULL_HANDLE;
637 VkPipelineStageFlags stageFlags = 0;
638 VkSubmitInfo submitInfo = {};
639 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
640 submitInfo.waitSemaphoreCount = 1;
641 submitInfo.pWaitSemaphores = &semaphore;
642 submitInfo.pWaitDstStageMask = &stageFlags;
643 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
644 m_errorMonitor->VerifyFound();
645}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600646
Dustin Gravesfce74c02016-05-10 11:42:58 -0600647TEST_F(VkLayerTest, ReservedParameter) {
648 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
649
650 ASSERT_NO_FATAL_FAILURE(InitState());
651
652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
653 " must be 0");
654 // Specify 0 for a reserved VkFlags parameter
655 // Expected to trigger an error with
656 // parameter_validation::validate_reserved_flags
657 VkEvent event_handle = VK_NULL_HANDLE;
658 VkEventCreateInfo event_info = {};
659 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
660 event_info.flags = 1;
661 vkCreateEvent(device(), &event_info, NULL, &event_handle);
662 m_errorMonitor->VerifyFound();
663}
664
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600665TEST_F(VkLayerTest, InvalidStructSType) {
666 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
667 "structure's sType field");
668
669 ASSERT_NO_FATAL_FAILURE(InitState());
670
671 m_errorMonitor->SetDesiredFailureMsg(
672 VK_DEBUG_REPORT_ERROR_BIT_EXT,
673 "parameter pAllocateInfo->sType must be");
674 // Zero struct memory, effectively setting sType to
675 // VK_STRUCTURE_TYPE_APPLICATION_INFO
676 // Expected to trigger an error with
677 // parameter_validation::validate_struct_type
678 VkMemoryAllocateInfo alloc_info = {};
679 VkDeviceMemory memory = VK_NULL_HANDLE;
680 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
681 m_errorMonitor->VerifyFound();
682
683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
684 "parameter pSubmits[0].sType must be");
685 // Zero struct memory, effectively setting sType to
686 // VK_STRUCTURE_TYPE_APPLICATION_INFO
687 // Expected to trigger an error with
688 // parameter_validation::validate_struct_type_array
689 VkSubmitInfo submit_info = {};
690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
691 m_errorMonitor->VerifyFound();
692}
693
694TEST_F(VkLayerTest, InvalidStructPNext) {
695 TEST_DESCRIPTION(
696 "Specify an invalid value for a Vulkan structure's pNext field");
697
698 ASSERT_NO_FATAL_FAILURE(InitState());
699
700 m_errorMonitor->SetDesiredFailureMsg(
701 VK_DEBUG_REPORT_ERROR_BIT_EXT,
702 "value of pAllocateInfo->pNext must be NULL");
703 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
704 // NULL
705 // Expected to trigger an error with
706 // parameter_validation::validate_struct_pnext
707 VkDeviceMemory memory = VK_NULL_HANDLE;
708 // Zero-initialization will provide the correct sType
709 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600710 VkMemoryAllocateInfo memory_alloc_info = {};
711 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
712 memory_alloc_info.pNext = &app_info;
713 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600714 m_errorMonitor->VerifyFound();
715
Dustin Graves47b6cba2016-05-10 17:34:38 -0600716 m_errorMonitor->SetDesiredFailureMsg(
717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
718 " chain includes a structure with unexpected VkStructureType ");
719 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
720 // Expected to trigger an error with
721 // parameter_validation::validate_struct_pnext
722 VkDescriptorPoolSize ds_type_count = {};
723 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
724 ds_type_count.descriptorCount = 1;
725
726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
728 ds_pool_ci.pNext = NULL;
729 ds_pool_ci.maxSets = 1;
730 ds_pool_ci.poolSizeCount = 1;
731 ds_pool_ci.pPoolSizes = &ds_type_count;
732
733 VkDescriptorPool ds_pool;
734 VkResult err =
735 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
736 ASSERT_VK_SUCCESS(err);
737
738 VkDescriptorSetLayoutBinding dsl_binding = {};
739 dsl_binding.binding = 0;
740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
741 dsl_binding.descriptorCount = 1;
742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
743 dsl_binding.pImmutableSamplers = NULL;
744
745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
747 ds_layout_ci.pNext = NULL;
748 ds_layout_ci.bindingCount = 1;
749 ds_layout_ci.pBindings = &dsl_binding;
750
751 VkDescriptorSetLayout ds_layout;
752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
753 &ds_layout);
754 ASSERT_VK_SUCCESS(err);
755
756 VkDescriptorSet descriptorSet;
757 VkDescriptorSetAllocateInfo ds_alloc_info = {};
758 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
759 ds_alloc_info.descriptorSetCount = 1;
760 ds_alloc_info.descriptorPool = ds_pool;
761 ds_alloc_info.pSetLayouts = &ds_layout;
762 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
763 &descriptorSet);
764 ASSERT_VK_SUCCESS(err);
765
766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
768 pipeline_layout_ci.setLayoutCount = 1;
769 pipeline_layout_ci.pSetLayouts = &ds_layout;
770
771 VkPipelineLayout pipeline_layout;
772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
773 &pipeline_layout);
774 ASSERT_VK_SUCCESS(err);
775
776 VkViewport vp = {}; // Just need dummy vp to point to
777 VkRect2D sc = {}; // dummy scissor to point to
778
779 VkPipelineViewportStateCreateInfo vp_state_ci = {};
780 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
781 vp_state_ci.scissorCount = 1;
782 vp_state_ci.pScissors = &sc;
783 vp_state_ci.viewportCount = 1;
784 vp_state_ci.pViewports = &vp;
785
786 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
787 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
788 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
789 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
790 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
791 rs_state_ci.depthClampEnable = VK_FALSE;
792 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
793 rs_state_ci.depthBiasEnable = VK_FALSE;
794
795 VkGraphicsPipelineCreateInfo gp_ci = {};
796 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
797 gp_ci.pViewportState = &vp_state_ci;
798 gp_ci.pRasterizationState = &rs_state_ci;
799 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
800 gp_ci.layout = pipeline_layout;
801 gp_ci.renderPass = renderPass();
802
803 VkPipelineCacheCreateInfo pc_ci = {};
804 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
805 pc_ci.initialDataSize = 0;
806 pc_ci.pInitialData = 0;
807
808 VkPipeline pipeline;
809 VkPipelineCache pipelineCache;
810
811 err =
812 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
813 ASSERT_VK_SUCCESS(err);
814
815 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
816 VkApplicationInfo invalid_pnext_struct = {};
817 rs_state_ci.pNext = &invalid_pnext_struct;
818
819 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
820 &gp_ci, NULL, &pipeline);
821 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600822}
Dustin Graves5d33d532016-05-09 16:21:12 -0600823
824TEST_F(VkLayerTest, UnrecognizedValue) {
825 TEST_DESCRIPTION(
826 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
827
828 ASSERT_NO_FATAL_FAILURE(InitState());
829
830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
831 "does not fall within the begin..end "
832 "range of the core VkFormat "
833 "enumeration tokens");
834 // Specify an invalid VkFormat value
835 // Expected to trigger an error with
836 // parameter_validation::validate_ranged_enum
837 VkFormatProperties format_properties;
838 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
839 &format_properties);
840 m_errorMonitor->VerifyFound();
841
842 m_errorMonitor->SetDesiredFailureMsg(
843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "contains flag bits that are not recognized members of");
845 // Specify an invalid VkFlags bitmask value
846 // Expected to trigger an error with parameter_validation::validate_flags
847 VkImageFormatProperties image_format_properties;
848 vkGetPhysicalDeviceImageFormatProperties(
849 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
850 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
851 &image_format_properties);
852 m_errorMonitor->VerifyFound();
853
854 m_errorMonitor->SetDesiredFailureMsg(
855 VK_DEBUG_REPORT_ERROR_BIT_EXT,
856 "contains flag bits that are not recognized members of");
857 // Specify an invalid VkFlags array entry
858 // Expected to trigger an error with
859 // parameter_validation::validate_flags_array
860 VkSemaphore semaphore = VK_NULL_HANDLE;
861 VkPipelineStageFlags stage_flags =
862 static_cast<VkPipelineStageFlags>(1 << 25);
863 VkSubmitInfo submit_info = {};
864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
865 submit_info.waitSemaphoreCount = 1;
866 submit_info.pWaitSemaphores = &semaphore;
867 submit_info.pWaitDstStageMask = &stage_flags;
868 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
869 m_errorMonitor->VerifyFound();
870
871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
872 "is neither VK_TRUE nor VK_FALSE");
873 // Specify an invalid VkBool32 value
874 // Expected to trigger a warning with
875 // parameter_validation::validate_bool32
876 VkSampler sampler = VK_NULL_HANDLE;
877 VkSamplerCreateInfo sampler_info = {};
878 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
879 sampler_info.pNext = NULL;
880 sampler_info.magFilter = VK_FILTER_NEAREST;
881 sampler_info.minFilter = VK_FILTER_NEAREST;
882 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
883 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
884 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
885 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
886 sampler_info.mipLodBias = 1.0;
887 sampler_info.maxAnisotropy = 1;
888 sampler_info.compareEnable = VK_FALSE;
889 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
890 sampler_info.minLod = 1.0;
891 sampler_info.maxLod = 1.0;
892 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
893 sampler_info.unnormalizedCoordinates = VK_FALSE;
894 // Not VK_TRUE or VK_FALSE
895 sampler_info.anisotropyEnable = 3;
896 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
897 m_errorMonitor->VerifyFound();
898}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600899
900TEST_F(VkLayerTest, FailedReturnValue) {
901 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
902
903 ASSERT_NO_FATAL_FAILURE(InitState());
904
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600905 // Find an unsupported image format
906 VkFormat unsupported = VK_FORMAT_UNDEFINED;
907 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
908 VkFormat format = static_cast<VkFormat>(f);
909 VkFormatProperties fProps = m_device->format_properties(format);
910 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
911 fProps.optimalTilingFeatures == 0) {
912 unsupported = format;
913 break;
914 }
915 }
916
917 if (unsupported != VK_FORMAT_UNDEFINED) {
918 m_errorMonitor->SetDesiredFailureMsg(
919 VK_DEBUG_REPORT_WARNING_BIT_EXT,
920 "the requested format is not supported on this device");
921 // Specify an unsupported VkFormat value to generate a
922 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
923 // Expected to trigger a warning from
924 // parameter_validation::validate_result
925 VkImageFormatProperties image_format_properties;
926 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
927 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
928 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
929 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
930 m_errorMonitor->VerifyFound();
931 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600932}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600933#endif // PARAMETER_VALIDATION_TESTS
934
Tobin Ehlis0788f522015-05-26 16:11:58 -0600935#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700936#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800937TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500938{
939 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500940 VkFenceCreateInfo fenceInfo = {};
941 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
942 fenceInfo.pNext = NULL;
943 fenceInfo.flags = 0;
944
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600946
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500947 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600948
949 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
950 vk_testing::Buffer buffer;
951 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500952
Tony Barbourfe3351b2015-07-28 10:17:20 -0600953 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800954 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600955 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500956
957 testFence.init(*m_device, fenceInfo);
958
959 // Bypass framework since it does the waits automatically
960 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600961 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800962 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
963 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800964 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600965 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700966 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800967 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800968 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800969 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600970 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600971
972 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500973 ASSERT_VK_SUCCESS( err );
974
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500975 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800976 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500977
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200978 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500979}
980
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800981TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500982{
983 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500984 VkFenceCreateInfo fenceInfo = {};
985 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
986 fenceInfo.pNext = NULL;
987 fenceInfo.flags = 0;
988
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600990
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500991 ASSERT_NO_FATAL_FAILURE(InitState());
992 ASSERT_NO_FATAL_FAILURE(InitViewport());
993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
994
Tony Barbourfe3351b2015-07-28 10:17:20 -0600995 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800996 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600997 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500998
999 testFence.init(*m_device, fenceInfo);
1000
1001 // Bypass framework since it does the waits automatically
1002 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001003 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001004 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1005 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001006 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001007 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001008 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001009 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001010 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001011 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001012 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001013
1014 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001015 ASSERT_VK_SUCCESS( err );
1016
Jon Ashburnf19916e2016-01-11 13:12:43 -07001017 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001018 VkCommandBufferBeginInfo info = {};
1019 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1020 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001021 info.renderPass = VK_NULL_HANDLE;
1022 info.subpass = 0;
1023 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001024 info.occlusionQueryEnable = VK_FALSE;
1025 info.queryFlags = 0;
1026 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001027
1028 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001029 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001030
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001031 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001032}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001033#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001034
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001035// This is a positive test. No failures are expected.
1036TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1037 VkResult err;
1038 bool pass;
1039
1040 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1041 "the buffer, create an image, and bind the same memory to "
1042 "it");
1043
1044 m_errorMonitor->ExpectSuccess();
1045
1046 ASSERT_NO_FATAL_FAILURE(InitState());
1047
1048 VkBuffer buffer;
1049 VkImage image;
1050 VkDeviceMemory mem;
1051 VkMemoryRequirements mem_reqs;
1052
1053 VkBufferCreateInfo buf_info = {};
1054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1055 buf_info.pNext = NULL;
1056 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1057 buf_info.size = 256;
1058 buf_info.queueFamilyIndexCount = 0;
1059 buf_info.pQueueFamilyIndices = NULL;
1060 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1061 buf_info.flags = 0;
1062 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1063 ASSERT_VK_SUCCESS(err);
1064
1065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1066
1067 VkMemoryAllocateInfo alloc_info = {};
1068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1069 alloc_info.pNext = NULL;
1070 alloc_info.memoryTypeIndex = 0;
1071
1072 // Ensure memory is big enough for both bindings
1073 alloc_info.allocationSize = 0x10000;
1074
1075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1076 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1077 if (!pass) {
1078 vkDestroyBuffer(m_device->device(), buffer, NULL);
1079 return;
1080 }
1081
1082 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1083 ASSERT_VK_SUCCESS(err);
1084
1085 uint8_t *pData;
1086 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1087 (void **)&pData);
1088 ASSERT_VK_SUCCESS(err);
1089
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001090 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001091
1092 vkUnmapMemory(m_device->device(), mem);
1093
1094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1095 ASSERT_VK_SUCCESS(err);
1096
1097 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1098 // memory. In fact, it was never used by the GPU.
1099 // Just be be sure, wait for idle.
1100 vkDestroyBuffer(m_device->device(), buffer, NULL);
1101 vkDeviceWaitIdle(m_device->device());
1102
1103 VkImageCreateInfo image_create_info = {};
1104 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1105 image_create_info.pNext = NULL;
1106 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1107 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1108 image_create_info.extent.width = 64;
1109 image_create_info.extent.height = 64;
1110 image_create_info.extent.depth = 1;
1111 image_create_info.mipLevels = 1;
1112 image_create_info.arrayLayers = 1;
1113 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1114 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1115 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1116 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1117 image_create_info.queueFamilyIndexCount = 0;
1118 image_create_info.pQueueFamilyIndices = NULL;
1119 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1120 image_create_info.flags = 0;
1121
1122 VkMemoryAllocateInfo mem_alloc = {};
1123 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1124 mem_alloc.pNext = NULL;
1125 mem_alloc.allocationSize = 0;
1126 mem_alloc.memoryTypeIndex = 0;
1127
1128 /* Create a mappable image. It will be the texture if linear images are ok
1129 * to be textures or it will be the staging image if they are not.
1130 */
1131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1132 ASSERT_VK_SUCCESS(err);
1133
1134 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1135
1136 mem_alloc.allocationSize = mem_reqs.size;
1137
1138 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1139 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1140 if (!pass) {
1141 vkDestroyImage(m_device->device(), image, NULL);
1142 return;
1143 }
1144
Tobin Ehlis077ded32016-05-12 17:39:13 -06001145 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001146 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1147 ASSERT_VK_SUCCESS(err);
1148
1149 m_errorMonitor->VerifyNotFound();
1150
1151 vkDestroyBuffer(m_device->device(), buffer, NULL);
1152 vkDestroyImage(m_device->device(), image, NULL);
1153}
1154
Tobin Ehlisf11be982016-05-11 13:52:53 -06001155TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1156 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1157 "buffer and image to memory such that they will alias.");
1158 VkResult err;
1159 bool pass;
1160 ASSERT_NO_FATAL_FAILURE(InitState());
1161
Tobin Ehlis077ded32016-05-12 17:39:13 -06001162 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001163 VkImage image;
1164 VkDeviceMemory mem; // buffer will be bound first
1165 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001166 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001167
1168 VkBufferCreateInfo buf_info = {};
1169 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1170 buf_info.pNext = NULL;
1171 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1172 buf_info.size = 256;
1173 buf_info.queueFamilyIndexCount = 0;
1174 buf_info.pQueueFamilyIndices = NULL;
1175 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1176 buf_info.flags = 0;
1177 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1178 ASSERT_VK_SUCCESS(err);
1179
Tobin Ehlis077ded32016-05-12 17:39:13 -06001180 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001181
1182 VkImageCreateInfo image_create_info = {};
1183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1184 image_create_info.pNext = NULL;
1185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1186 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1187 image_create_info.extent.width = 64;
1188 image_create_info.extent.height = 64;
1189 image_create_info.extent.depth = 1;
1190 image_create_info.mipLevels = 1;
1191 image_create_info.arrayLayers = 1;
1192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1195 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1196 image_create_info.queueFamilyIndexCount = 0;
1197 image_create_info.pQueueFamilyIndices = NULL;
1198 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1199 image_create_info.flags = 0;
1200
Tobin Ehlisf11be982016-05-11 13:52:53 -06001201 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1202 ASSERT_VK_SUCCESS(err);
1203
Tobin Ehlis077ded32016-05-12 17:39:13 -06001204 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1205
1206 VkMemoryAllocateInfo alloc_info = {};
1207 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1208 alloc_info.pNext = NULL;
1209 alloc_info.memoryTypeIndex = 0;
1210 // Ensure memory is big enough for both bindings
1211 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1212 pass = m_device->phy().set_memory_type(
1213 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001215 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001216 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001217 vkDestroyImage(m_device->device(), image, NULL);
1218 return;
1219 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001220 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1221 ASSERT_VK_SUCCESS(err);
1222 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1223 ASSERT_VK_SUCCESS(err);
1224
Tobin Ehlisf11be982016-05-11 13:52:53 -06001225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1226 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001227 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001228 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1229 m_errorMonitor->VerifyFound();
1230
1231 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001232 // aliasing buffer2
1233 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1234 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001235 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1236 ASSERT_VK_SUCCESS(err);
1237 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1238 ASSERT_VK_SUCCESS(err);
1239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001241 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001242 m_errorMonitor->VerifyFound();
1243
1244 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001245 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001246 vkDestroyImage(m_device->device(), image, NULL);
1247 vkFreeMemory(m_device->device(), mem, NULL);
1248 vkFreeMemory(m_device->device(), mem_img, NULL);
1249}
1250
Tobin Ehlis35372522016-05-12 08:32:31 -06001251TEST_F(VkLayerTest, InvalidMemoryMapping) {
1252 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1253 VkResult err;
1254 bool pass;
1255 ASSERT_NO_FATAL_FAILURE(InitState());
1256
1257 VkBuffer buffer;
1258 VkDeviceMemory mem;
1259 VkMemoryRequirements mem_reqs;
1260
1261 VkBufferCreateInfo buf_info = {};
1262 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1263 buf_info.pNext = NULL;
1264 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1265 buf_info.size = 256;
1266 buf_info.queueFamilyIndexCount = 0;
1267 buf_info.pQueueFamilyIndices = NULL;
1268 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1269 buf_info.flags = 0;
1270 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1271 ASSERT_VK_SUCCESS(err);
1272
1273 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1274 VkMemoryAllocateInfo alloc_info = {};
1275 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1276 alloc_info.pNext = NULL;
1277 alloc_info.memoryTypeIndex = 0;
1278
1279 // Ensure memory is big enough for both bindings
1280 static const VkDeviceSize allocation_size = 0x10000;
1281 alloc_info.allocationSize = allocation_size;
1282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1283 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1284 if (!pass) {
1285 vkDestroyBuffer(m_device->device(), buffer, NULL);
1286 return;
1287 }
1288 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1289 ASSERT_VK_SUCCESS(err);
1290
1291 uint8_t *pData;
1292 // Attempt to map memory size 0 is invalid
1293 m_errorMonitor->SetDesiredFailureMsg(
1294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1295 "VkMapMemory: Attempting to map memory range of size zero");
1296 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1297 m_errorMonitor->VerifyFound();
1298 // Map memory twice
1299 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1300 (void **)&pData);
1301 ASSERT_VK_SUCCESS(err);
1302 m_errorMonitor->SetDesiredFailureMsg(
1303 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1304 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1305 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1306 (void **)&pData);
1307 m_errorMonitor->VerifyFound();
1308
1309 // Unmap the memory to avoid re-map error
1310 vkUnmapMemory(m_device->device(), mem);
1311 // overstep allocation with VK_WHOLE_SIZE
1312 m_errorMonitor->SetDesiredFailureMsg(
1313 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1314 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1315 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1316 VK_WHOLE_SIZE, 0, (void **)&pData);
1317 m_errorMonitor->VerifyFound();
1318 // overstep allocation w/o VK_WHOLE_SIZE
1319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1320 " oversteps total array size 0x");
1321 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1322 (void **)&pData);
1323 m_errorMonitor->VerifyFound();
1324 // Now error due to unmapping memory that's not mapped
1325 m_errorMonitor->SetDesiredFailureMsg(
1326 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1327 "Unmapping Memory without memory being mapped: ");
1328 vkUnmapMemory(m_device->device(), mem);
1329 m_errorMonitor->VerifyFound();
1330 // Now map memory and cause errors due to flushing invalid ranges
1331 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1332 (void **)&pData);
1333 ASSERT_VK_SUCCESS(err);
1334 VkMappedMemoryRange mmr = {};
1335 mmr.memory = mem;
1336 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1337 m_errorMonitor->SetDesiredFailureMsg(
1338 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1339 ") is less than Memory Object's offset (");
1340 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1341 m_errorMonitor->VerifyFound();
1342 // Now flush range that oversteps mapped range
1343 vkUnmapMemory(m_device->device(), mem);
1344 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1345 ASSERT_VK_SUCCESS(err);
1346 mmr.offset = 16;
1347 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1348 m_errorMonitor->SetDesiredFailureMsg(
1349 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1350 ") exceeds the Memory Object's upper-bound (");
1351 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1352 m_errorMonitor->VerifyFound();
1353
1354 pass =
1355 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1356 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1357 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1358 if (!pass) {
1359 vkFreeMemory(m_device->device(), mem, NULL);
1360 vkDestroyBuffer(m_device->device(), buffer, NULL);
1361 return;
1362 }
1363 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1364 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1365
1366 vkDestroyBuffer(m_device->device(), buffer, NULL);
1367 vkFreeMemory(m_device->device(), mem, NULL);
1368}
1369
Ian Elliott1c32c772016-04-28 14:47:13 -06001370TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1371 VkResult err;
1372 bool pass;
1373
Ian Elliott489eec02016-05-05 14:12:44 -06001374// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1375// following declaration (which is temporarily being moved below):
1376// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001377 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1378 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1379 uint32_t swapchain_image_count = 0;
1380// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1381 uint32_t image_index = 0;
1382// VkPresentInfoKHR present_info = {};
1383
1384 ASSERT_NO_FATAL_FAILURE(InitState());
1385
Ian Elliott3f06ce52016-04-29 14:46:21 -06001386#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1387#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1388 // Use the functions from the VK_KHR_android_surface extension without
1389 // enabling that extension:
1390
1391 // Create a surface:
1392 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001393 m_errorMonitor->SetDesiredFailureMsg(
1394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1395 "extension was not enabled for this");
1396 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1397 &surface);
1398 pass = (err != VK_SUCCESS);
1399 ASSERT_TRUE(pass);
1400 m_errorMonitor->VerifyFound();
1401#endif // VK_USE_PLATFORM_ANDROID_KHR
1402
1403
1404#if defined(VK_USE_PLATFORM_MIR_KHR)
1405 // Use the functions from the VK_KHR_mir_surface extension without enabling
1406 // that extension:
1407
1408 // Create a surface:
1409 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001410 m_errorMonitor->SetDesiredFailureMsg(
1411 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1412 "extension was not enabled for this");
1413 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1414 pass = (err != VK_SUCCESS);
1415 ASSERT_TRUE(pass);
1416 m_errorMonitor->VerifyFound();
1417
1418 // Tell whether an mir_connection supports presentation:
1419 MirConnection *mir_connection = NULL;
1420 m_errorMonitor->SetDesiredFailureMsg(
1421 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1422 "extension was not enabled for this");
1423 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1424 visual_id);
1425 m_errorMonitor->VerifyFound();
1426#endif // VK_USE_PLATFORM_MIR_KHR
1427
1428
1429#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1430 // Use the functions from the VK_KHR_wayland_surface extension without
1431 // enabling that extension:
1432
1433 // Create a surface:
1434 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001435 m_errorMonitor->SetDesiredFailureMsg(
1436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 "extension was not enabled for this");
1438 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1439 &surface);
1440 pass = (err != VK_SUCCESS);
1441 ASSERT_TRUE(pass);
1442 m_errorMonitor->VerifyFound();
1443
1444 // Tell whether an wayland_display supports presentation:
1445 struct wl_display wayland_display = {};
1446 m_errorMonitor->SetDesiredFailureMsg(
1447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1448 "extension was not enabled for this");
1449 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1450 &wayland_display);
1451 m_errorMonitor->VerifyFound();
1452#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001453#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001454
1455
1456#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001457// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1458// TO NON-LINUX PLATFORMS:
1459VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001460 // Use the functions from the VK_KHR_win32_surface extension without
1461 // enabling that extension:
1462
1463 // Create a surface:
1464 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001465 m_errorMonitor->SetDesiredFailureMsg(
1466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1467 "extension was not enabled for this");
1468 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1469 &surface);
1470 pass = (err != VK_SUCCESS);
1471 ASSERT_TRUE(pass);
1472 m_errorMonitor->VerifyFound();
1473
1474 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475 m_errorMonitor->SetDesiredFailureMsg(
1476 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1477 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001478 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001479 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001480// Set this (for now, until all platforms are supported and tested):
1481#define NEED_TO_TEST_THIS_ON_PLATFORM
1482#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001483
1484
Ian Elliott1c32c772016-04-28 14:47:13 -06001485#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001486// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1487// TO NON-LINUX PLATFORMS:
1488VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001489 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1490 // that extension:
1491
1492 // Create a surface:
1493 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 m_errorMonitor->SetDesiredFailureMsg(
1495 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1496 "extension was not enabled for this");
1497 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1498 pass = (err != VK_SUCCESS);
1499 ASSERT_TRUE(pass);
1500 m_errorMonitor->VerifyFound();
1501
1502 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001504 xcb_visualid_t visual_id = 0;
1505 m_errorMonitor->SetDesiredFailureMsg(
1506 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1507 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001508 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001509 visual_id);
1510 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001511// Set this (for now, until all platforms are supported and tested):
1512#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001513#endif // VK_USE_PLATFORM_XCB_KHR
1514
1515
Ian Elliott12630812016-04-29 14:35:43 -06001516#if defined(VK_USE_PLATFORM_XLIB_KHR)
1517 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1518 // that extension:
1519
1520 // Create a surface:
1521 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001522 m_errorMonitor->SetDesiredFailureMsg(
1523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1524 "extension was not enabled for this");
1525 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1526 pass = (err != VK_SUCCESS);
1527 ASSERT_TRUE(pass);
1528 m_errorMonitor->VerifyFound();
1529
1530 // Tell whether an Xlib VisualID supports presentation:
1531 Display *dpy = NULL;
1532 VisualID visual = 0;
1533 m_errorMonitor->SetDesiredFailureMsg(
1534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1535 "extension was not enabled for this");
1536 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1537 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001538// Set this (for now, until all platforms are supported and tested):
1539#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001540#endif // VK_USE_PLATFORM_XLIB_KHR
1541
1542
Ian Elliott1c32c772016-04-28 14:47:13 -06001543 // Use the functions from the VK_KHR_surface extension without enabling
1544 // that extension:
1545
Ian Elliott489eec02016-05-05 14:12:44 -06001546#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001547 // Destroy a surface:
1548 m_errorMonitor->SetDesiredFailureMsg(
1549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1550 "extension was not enabled for this");
1551 vkDestroySurfaceKHR(instance(), surface, NULL);
1552 m_errorMonitor->VerifyFound();
1553
1554 // Check if surface supports presentation:
1555 VkBool32 supported = false;
1556 m_errorMonitor->SetDesiredFailureMsg(
1557 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1558 "extension was not enabled for this");
1559 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1560 pass = (err != VK_SUCCESS);
1561 ASSERT_TRUE(pass);
1562 m_errorMonitor->VerifyFound();
1563
1564 // Check surface capabilities:
1565 VkSurfaceCapabilitiesKHR capabilities = {};
1566 m_errorMonitor->SetDesiredFailureMsg(
1567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1568 "extension was not enabled for this");
1569 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1570 &capabilities);
1571 pass = (err != VK_SUCCESS);
1572 ASSERT_TRUE(pass);
1573 m_errorMonitor->VerifyFound();
1574
1575 // Check surface formats:
1576 uint32_t format_count = 0;
1577 VkSurfaceFormatKHR *formats = NULL;
1578 m_errorMonitor->SetDesiredFailureMsg(
1579 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1580 "extension was not enabled for this");
1581 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1582 &format_count, formats);
1583 pass = (err != VK_SUCCESS);
1584 ASSERT_TRUE(pass);
1585 m_errorMonitor->VerifyFound();
1586
1587 // Check surface present modes:
1588 uint32_t present_mode_count = 0;
1589 VkSurfaceFormatKHR *present_modes = NULL;
1590 m_errorMonitor->SetDesiredFailureMsg(
1591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1592 "extension was not enabled for this");
1593 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1594 &present_mode_count, present_modes);
1595 pass = (err != VK_SUCCESS);
1596 ASSERT_TRUE(pass);
1597 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001598#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001599
1600
1601 // Use the functions from the VK_KHR_swapchain extension without enabling
1602 // that extension:
1603
1604 // Create a swapchain:
1605 m_errorMonitor->SetDesiredFailureMsg(
1606 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1607 "extension was not enabled for this");
1608 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1609 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001610 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1611 NULL, &swapchain);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Get the images from the swapchain:
1617 m_errorMonitor->SetDesiredFailureMsg(
1618 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1619 "extension was not enabled for this");
1620 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1621 &swapchain_image_count, NULL);
1622 pass = (err != VK_SUCCESS);
1623 ASSERT_TRUE(pass);
1624 m_errorMonitor->VerifyFound();
1625
1626 // Try to acquire an image:
1627 m_errorMonitor->SetDesiredFailureMsg(
1628 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1629 "extension was not enabled for this");
1630 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1631 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1632 pass = (err != VK_SUCCESS);
1633 ASSERT_TRUE(pass);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001637 //
1638 // NOTE: Currently can't test this because a real swapchain is needed (as
1639 // opposed to the fake one we created) in order for the layer to lookup the
1640 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001641
1642 // Destroy the swapchain:
1643 m_errorMonitor->SetDesiredFailureMsg(
1644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 "extension was not enabled for this");
1646 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1647 m_errorMonitor->VerifyFound();
1648}
1649
Ian Elliott2c1daf52016-05-12 09:41:46 -06001650TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001651
Dustin Graves6c6d8982016-05-17 10:09:21 -06001652#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001653 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001654
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001655 VkResult err;
1656 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001657 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1658 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001659 // uint32_t swapchain_image_count = 0;
1660 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1661 // uint32_t image_index = 0;
1662 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001663
1664 ASSERT_NO_FATAL_FAILURE(InitState());
1665
1666 // Use the create function from one of the VK_KHR_*_surface extension in
1667 // order to create a surface, testing all known errors in the process,
1668 // before successfully creating a surface:
1669 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1671 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001672 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Next, try to create a surface with the wrong
1678 // VkXcbSurfaceCreateInfoKHR::sType:
1679 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1680 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001683 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
1687
Ian Elliott2c1daf52016-05-12 09:41:46 -06001688 // Create a native window, and then correctly create a surface:
1689 xcb_connection_t *connection;
1690 xcb_screen_t *screen;
1691 xcb_window_t xcb_window;
1692 xcb_intern_atom_reply_t *atom_wm_delete_window;
1693
1694 const xcb_setup_t *setup;
1695 xcb_screen_iterator_t iter;
1696 int scr;
1697 uint32_t value_mask, value_list[32];
1698 int width = 1;
1699 int height = 1;
1700
1701 connection = xcb_connect(NULL, &scr);
1702 ASSERT_TRUE(connection != NULL);
1703 setup = xcb_get_setup(connection);
1704 iter = xcb_setup_roots_iterator(setup);
1705 while (scr-- > 0)
1706 xcb_screen_next(&iter);
1707 screen = iter.data;
1708
1709 xcb_window = xcb_generate_id(connection);
1710
1711 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1712 value_list[0] = screen->black_pixel;
1713 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1714 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1715
1716 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1717 screen->root, 0, 0, width, height, 0,
1718 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1719 value_mask, value_list);
1720
1721 /* Magic code that will send notification when window is destroyed */
1722 xcb_intern_atom_cookie_t cookie =
1723 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1724 xcb_intern_atom_reply_t *reply =
1725 xcb_intern_atom_reply(connection, cookie, 0);
1726
1727 xcb_intern_atom_cookie_t cookie2 =
1728 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001729 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001730 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1731 (*reply).atom, 4, 32, 1,
1732 &(*atom_wm_delete_window).atom);
1733 free(reply);
1734
1735 xcb_map_window(connection, xcb_window);
1736
1737 // Force the x/y coordinates to 100,100 results are identical in consecutive
1738 // runs
1739 const uint32_t coords[] = {100, 100};
1740 xcb_configure_window(connection, xcb_window,
1741 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1742
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 // Finally, try to correctly create a surface:
1744 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1745 xcb_create_info.pNext = NULL;
1746 xcb_create_info.flags = 0;
1747 xcb_create_info.connection = connection;
1748 xcb_create_info.window = xcb_window;
1749 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1750 pass = (err == VK_SUCCESS);
1751 ASSERT_TRUE(pass);
1752
Ian Elliott2c1daf52016-05-12 09:41:46 -06001753 // Check if surface supports presentation:
1754
1755 // 1st, do so without having queried the queue families:
1756 VkBool32 supported = false;
1757 // TODO: Get the following error to come out:
1758 m_errorMonitor->SetDesiredFailureMsg(
1759 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1761 "function");
1762 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1763 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001764 // ASSERT_TRUE(pass);
1765 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001766
1767 // Next, query a queue family index that's too large:
1768 m_errorMonitor->SetDesiredFailureMsg(
1769 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1770 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001771 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1772 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
1777 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001778 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1779 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001780 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1781 pass = (err == VK_SUCCESS);
1782 ASSERT_TRUE(pass);
1783
Ian Elliott2c1daf52016-05-12 09:41:46 -06001784 // Before proceeding, try to create a swapchain without having called
1785 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1786 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1787 swapchain_create_info.pNext = NULL;
1788 swapchain_create_info.flags = 0;
1789 m_errorMonitor->SetDesiredFailureMsg(
1790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1791 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001792 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1793 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001794 pass = (err != VK_SUCCESS);
1795 ASSERT_TRUE(pass);
1796 m_errorMonitor->VerifyFound();
1797
Ian Elliott2c1daf52016-05-12 09:41:46 -06001798 // Get the surface capabilities:
1799 VkSurfaceCapabilitiesKHR surface_capabilities;
1800
1801 // Do so correctly (only error logged by this entrypoint is if the
1802 // extension isn't enabled):
1803 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1804 &surface_capabilities);
1805 pass = (err == VK_SUCCESS);
1806 ASSERT_TRUE(pass);
1807
Ian Elliott2c1daf52016-05-12 09:41:46 -06001808 // Get the surface formats:
1809 uint32_t surface_format_count;
1810
1811 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1813 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001814 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1815 pass = (err == VK_SUCCESS);
1816 ASSERT_TRUE(pass);
1817 m_errorMonitor->VerifyFound();
1818
1819 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1820 // correctly done a 1st try (to get the count):
1821 m_errorMonitor->SetDesiredFailureMsg(
1822 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1823 "but no prior positive value has been seen for");
1824 surface_format_count = 0;
1825 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001826 gpu(), surface, &surface_format_count,
1827 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001828 pass = (err == VK_SUCCESS);
1829 ASSERT_TRUE(pass);
1830 m_errorMonitor->VerifyFound();
1831
1832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1834 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001835 pass = (err == VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837
1838 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001839 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1840 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001841
1842 // Next, do a 2nd try with surface_format_count being set too high:
1843 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1845 "that is greater than the value");
1846 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001847 surface_formats);
1848 pass = (err == VK_SUCCESS);
1849 ASSERT_TRUE(pass);
1850 m_errorMonitor->VerifyFound();
1851
1852 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1854 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855 pass = (err == VK_SUCCESS);
1856 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001857 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001858 surface_formats);
1859 pass = (err == VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 // Get the surface present modes:
1863 uint32_t surface_present_mode_count;
1864
1865 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1867 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001868 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1869 pass = (err == VK_SUCCESS);
1870 ASSERT_TRUE(pass);
1871 m_errorMonitor->VerifyFound();
1872
1873 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1874 // correctly done a 1st try (to get the count):
1875 m_errorMonitor->SetDesiredFailureMsg(
1876 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1877 "but no prior positive value has been seen for");
1878 surface_present_mode_count = 0;
1879 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001880 gpu(), surface, &surface_present_mode_count,
1881 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001882 pass = (err == VK_SUCCESS);
1883 ASSERT_TRUE(pass);
1884 m_errorMonitor->VerifyFound();
1885
1886 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001887 vkGetPhysicalDeviceSurfacePresentModesKHR(
1888 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001889 pass = (err == VK_SUCCESS);
1890 ASSERT_TRUE(pass);
1891
1892 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001893 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1894 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001895
1896 // Next, do a 2nd try with surface_format_count being set too high:
1897 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1899 "that is greater than the value");
1900 vkGetPhysicalDeviceSurfacePresentModesKHR(
1901 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001902 pass = (err == VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001907 vkGetPhysicalDeviceSurfacePresentModesKHR(
1908 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001909 pass = (err == VK_SUCCESS);
1910 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001911 vkGetPhysicalDeviceSurfacePresentModesKHR(
1912 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001913 pass = (err == VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915
Ian Elliott2c1daf52016-05-12 09:41:46 -06001916 // Create a swapchain:
1917
1918 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1920 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001921 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
1922 pass = (err != VK_SUCCESS);
1923 ASSERT_TRUE(pass);
1924 m_errorMonitor->VerifyFound();
1925
1926 // Next, call with a non-NULL swapchain_create_info, that has the wrong
1927 // sType:
1928 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1930 "called with the wrong value for");
1931 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1932 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Next, call with a NULL swapchain pointer:
1938 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1939 swapchain_create_info.pNext = NULL;
1940 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1942 "called with NULL pointer");
1943 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1944 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 pass = (err != VK_SUCCESS);
1946 ASSERT_TRUE(pass);
1947 m_errorMonitor->VerifyFound();
1948
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001949 // TODO: Enhance swapchain layer so that
1950 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951
1952 // Next, call with a queue family index that's too large:
1953 uint32_t queueFamilyIndex[2] = {100000, 0};
1954 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1955 swapchain_create_info.queueFamilyIndexCount = 2;
1956 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
1957 m_errorMonitor->SetDesiredFailureMsg(
1958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1959 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001960 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1961 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001962 pass = (err != VK_SUCCESS);
1963 ASSERT_TRUE(pass);
1964 m_errorMonitor->VerifyFound();
1965
1966 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
1967 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
1968 swapchain_create_info.queueFamilyIndexCount = 1;
1969 m_errorMonitor->SetDesiredFailureMsg(
1970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1971 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
1972 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001973 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1974 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001975 pass = (err != VK_SUCCESS);
1976 ASSERT_TRUE(pass);
1977 m_errorMonitor->VerifyFound();
1978
1979 // Next, call with an invalid imageSharingMode:
1980 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
1981 swapchain_create_info.queueFamilyIndexCount = 1;
1982 m_errorMonitor->SetDesiredFailureMsg(
1983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1984 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001985 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1986 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001987 pass = (err != VK_SUCCESS);
1988 ASSERT_TRUE(pass);
1989 m_errorMonitor->VerifyFound();
1990 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001991 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1992 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001993 swapchain_create_info.queueFamilyIndexCount = 0;
1994 queueFamilyIndex[0] = 0;
1995 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1996
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001997 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001999 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002000 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002001 // Destroy the swapchain:
2002
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002003 // TODOs:
2004 //
2005 // - Try destroying the device without first destroying the swapchain
2006 //
2007 // - Try destroying the device without first destroying the surface
2008 //
2009 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010
2011 // Destroy the surface:
2012 vkDestroySurfaceKHR(instance(), surface, NULL);
2013
Ian Elliott2c1daf52016-05-12 09:41:46 -06002014 // Tear down the window:
2015 xcb_destroy_window(connection, xcb_window);
2016 xcb_disconnect(connection);
2017
2018#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002019 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002020#endif // VK_USE_PLATFORM_XCB_KHR
2021}
2022
Karl Schultz6addd812016-02-02 17:17:23 -07002023TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2024 VkResult err;
2025 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 m_errorMonitor->SetDesiredFailureMsg(
2028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002029 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2030
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002031 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002032
2033 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002034 VkImage image;
2035 VkDeviceMemory mem;
2036 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002037
Karl Schultz6addd812016-02-02 17:17:23 -07002038 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2039 const int32_t tex_width = 32;
2040 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002041
Tony Barboureb254902015-07-15 12:50:33 -06002042 VkImageCreateInfo image_create_info = {};
2043 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002044 image_create_info.pNext = NULL;
2045 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2046 image_create_info.format = tex_format;
2047 image_create_info.extent.width = tex_width;
2048 image_create_info.extent.height = tex_height;
2049 image_create_info.extent.depth = 1;
2050 image_create_info.mipLevels = 1;
2051 image_create_info.arrayLayers = 1;
2052 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2053 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2054 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2055 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002056
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002057 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002058 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002059 mem_alloc.pNext = NULL;
2060 mem_alloc.allocationSize = 0;
2061 // Introduce failure, do NOT set memProps to
2062 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2063 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002064
Chia-I Wuf7458c52015-10-26 21:10:41 +08002065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066 ASSERT_VK_SUCCESS(err);
2067
Karl Schultz6addd812016-02-02 17:17:23 -07002068 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002069
Mark Lobodzinski23065352015-05-29 09:32:35 -05002070 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071
Karl Schultz6addd812016-02-02 17:17:23 -07002072 pass =
2073 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2074 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2075 if (!pass) { // If we can't find any unmappable memory this test doesn't
2076 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002077 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002078 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002079 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002080
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002081 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002087 ASSERT_VK_SUCCESS(err);
2088
2089 // Map memory as if to initialize the image
2090 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002091 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2092 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002093
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002094 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002095
Chia-I Wuf7458c52015-10-26 21:10:41 +08002096 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002097}
2098
Karl Schultz6addd812016-02-02 17:17:23 -07002099TEST_F(VkLayerTest, RebindMemory) {
2100 VkResult err;
2101 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 m_errorMonitor->SetDesiredFailureMsg(
2104 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002105 "which has already been bound to mem object");
2106
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002107 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002108
2109 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002110 VkImage image;
2111 VkDeviceMemory mem1;
2112 VkDeviceMemory mem2;
2113 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002114
Karl Schultz6addd812016-02-02 17:17:23 -07002115 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2116 const int32_t tex_width = 32;
2117 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002118
Tony Barboureb254902015-07-15 12:50:33 -06002119 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2121 image_create_info.pNext = NULL;
2122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2123 image_create_info.format = tex_format;
2124 image_create_info.extent.width = tex_width;
2125 image_create_info.extent.height = tex_height;
2126 image_create_info.extent.depth = 1;
2127 image_create_info.mipLevels = 1;
2128 image_create_info.arrayLayers = 1;
2129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2131 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2132 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002133
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002134 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002135 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2136 mem_alloc.pNext = NULL;
2137 mem_alloc.allocationSize = 0;
2138 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002139
Karl Schultz6addd812016-02-02 17:17:23 -07002140 // Introduce failure, do NOT set memProps to
2141 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002142 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002143 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002144 ASSERT_VK_SUCCESS(err);
2145
Karl Schultz6addd812016-02-02 17:17:23 -07002146 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002147
2148 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002149 pass =
2150 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002151 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002152
2153 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002154 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002155 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002156 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 ASSERT_VK_SUCCESS(err);
2158
2159 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002160 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002161 ASSERT_VK_SUCCESS(err);
2162
Karl Schultz6addd812016-02-02 17:17:23 -07002163 // Introduce validation failure, try to bind a different memory object to
2164 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002165 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002166
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002167 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168
Chia-I Wuf7458c52015-10-26 21:10:41 +08002169 vkDestroyImage(m_device->device(), image, NULL);
2170 vkFreeMemory(m_device->device(), mem1, NULL);
2171 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002172}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002173
Karl Schultz6addd812016-02-02 17:17:23 -07002174TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002175 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Karl Schultz6addd812016-02-02 17:17:23 -07002177 m_errorMonitor->SetDesiredFailureMsg(
2178 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2179 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002180
2181 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2183 fenceInfo.pNext = NULL;
2184 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002185
Tony Barbour300a6082015-04-07 13:44:53 -06002186 ASSERT_NO_FATAL_FAILURE(InitState());
2187 ASSERT_NO_FATAL_FAILURE(InitViewport());
2188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2189
Tony Barbourfe3351b2015-07-28 10:17:20 -06002190 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002191 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2192 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002193 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002194
2195 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002196
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002197 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002198 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2199 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002200 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002201 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002202 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002203 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002204 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002205 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002206 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002207
2208 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002209 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002211 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002212}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002213// This is a positive test. We used to expect error in this case but spec now
2214// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002215TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002216 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002217 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002218 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002219 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2220 fenceInfo.pNext = NULL;
2221
Tony Barbour0b4d9562015-04-09 10:48:04 -06002222 ASSERT_NO_FATAL_FAILURE(InitState());
2223 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002224 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002225 VkResult result = vkResetFences(m_device->device(), 1, fences);
2226 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002227
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002228 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002229}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002230
2231TEST_F(VkLayerTest, InvalidUsageBits)
2232{
Tony Barbourf92621a2016-05-02 14:28:12 -06002233 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002234 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002235 "Initialize buffer with wrong usage then perform copy expecting errors "
2236 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002238 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002239
2240 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 VkImageObj image(m_device);
2242 // Initialize image with USAGE_INPUT_ATTACHMENT
2243 image.init(128, 128, VK_FORMAT_D32_SFLOAT_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002244 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2245 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002246
Tony Barbourf92621a2016-05-02 14:28:12 -06002247 VkImageView dsv;
2248 VkImageViewCreateInfo dsvci = {};
2249 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2250 dsvci.image = image.handle();
2251 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2252 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2253 dsvci.subresourceRange.layerCount = 1;
2254 dsvci.subresourceRange.baseMipLevel = 0;
2255 dsvci.subresourceRange.levelCount = 1;
2256 dsvci.subresourceRange.aspectMask =
2257 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002258
Tony Barbourf92621a2016-05-02 14:28:12 -06002259 // Create a view with depth / stencil aspect for image with different usage
2260 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002262 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002263
2264 // Initialize buffer with TRANSFER_DST usage
2265 vk_testing::Buffer buffer;
2266 VkMemoryPropertyFlags reqs = 0;
2267 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2268 VkBufferImageCopy region = {};
2269 region.bufferRowLength = 128;
2270 region.bufferImageHeight = 128;
2271 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2272 region.imageSubresource.layerCount = 1;
2273 region.imageExtent.height = 16;
2274 region.imageExtent.width = 16;
2275 region.imageExtent.depth = 1;
2276
2277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2278 "Invalid usage flag for buffer ");
2279 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2280 // TRANSFER_DST
2281 BeginCommandBuffer();
2282 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2283 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2284 1, &region);
2285 m_errorMonitor->VerifyFound();
2286
2287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2288 "Invalid usage flag for image ");
2289 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2290 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2291 1, &region);
2292 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002293}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002294#endif // MEM_TRACKER_TESTS
2295
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002296#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
2298TEST_F(VkLayerTest, LeakAnObject) {
2299 VkResult err;
2300
2301 TEST_DESCRIPTION(
2302 "Create a fence and destroy its device without first destroying the fence.");
2303
2304 // Note that we have to create a new device since destroying the
2305 // framework's device causes Teardown() to fail and just calling Teardown
2306 // will destroy the errorMonitor.
2307
2308 m_errorMonitor->SetDesiredFailureMsg(
2309 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2310 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2311
2312 ASSERT_NO_FATAL_FAILURE(InitState());
2313
2314 const std::vector<VkQueueFamilyProperties> queue_props =
2315 m_device->queue_props;
2316 std::vector<VkDeviceQueueCreateInfo> queue_info;
2317 queue_info.reserve(queue_props.size());
2318 std::vector<std::vector<float>> queue_priorities;
2319 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2320 VkDeviceQueueCreateInfo qi = {};
2321 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2322 qi.pNext = NULL;
2323 qi.queueFamilyIndex = i;
2324 qi.queueCount = queue_props[i].queueCount;
2325 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2326 qi.pQueuePriorities = queue_priorities[i].data();
2327 queue_info.push_back(qi);
2328 }
2329
2330 std::vector<const char *> device_layer_names;
2331 std::vector<const char *> device_extension_names;
2332 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2333 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2334 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2335 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2336 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2337 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2338 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2339
2340 // The sacrificial device object
2341 VkDevice testDevice;
2342 VkDeviceCreateInfo device_create_info = {};
2343 auto features = m_device->phy().features();
2344 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2345 device_create_info.pNext = NULL;
2346 device_create_info.queueCreateInfoCount = queue_info.size();
2347 device_create_info.pQueueCreateInfos = queue_info.data();
2348 device_create_info.enabledLayerCount = device_layer_names.size();
2349 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2350 device_create_info.pEnabledFeatures = &features;
2351 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2352 ASSERT_VK_SUCCESS(err);
2353
2354 VkFence fence;
2355 VkFenceCreateInfo fence_create_info = {};
2356 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2357 fence_create_info.pNext = NULL;
2358 fence_create_info.flags = 0;
2359 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2360 ASSERT_VK_SUCCESS(err);
2361
2362 // Induce failure by not calling vkDestroyFence
2363 vkDestroyDevice(testDevice, NULL);
2364 m_errorMonitor->VerifyFound();
2365}
2366
2367TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2368
2369 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2370 "attempt to delete them from another.");
2371
2372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2373 "FreeCommandBuffers is attempting to free Command Buffer");
2374
2375 VkCommandPool command_pool_one;
2376 VkCommandPool command_pool_two;
2377
2378 VkCommandPoolCreateInfo pool_create_info{};
2379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2382
2383 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2384 &command_pool_one);
2385
2386 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2387 &command_pool_two);
2388
2389 VkCommandBuffer command_buffer[9];
2390 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2391 command_buffer_allocate_info.sType =
2392 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2393 command_buffer_allocate_info.commandPool = command_pool_one;
2394 command_buffer_allocate_info.commandBufferCount = 9;
2395 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2396 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2397 command_buffer);
2398
2399 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2400 &command_buffer[3]);
2401
2402 m_errorMonitor->VerifyFound();
2403
2404 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2405 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2406}
2407
2408TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2409 VkResult err;
2410
2411 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2412 "attempt to delete them from another.");
2413
2414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2415 "FreeDescriptorSets is attempting to free descriptorSet");
2416
2417 ASSERT_NO_FATAL_FAILURE(InitState());
2418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2419
2420 VkDescriptorPoolSize ds_type_count = {};
2421 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2422 ds_type_count.descriptorCount = 1;
2423
2424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2426 ds_pool_ci.pNext = NULL;
2427 ds_pool_ci.flags = 0;
2428 ds_pool_ci.maxSets = 1;
2429 ds_pool_ci.poolSizeCount = 1;
2430 ds_pool_ci.pPoolSizes = &ds_type_count;
2431
2432 VkDescriptorPool ds_pool_one;
2433 err =
2434 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2435 ASSERT_VK_SUCCESS(err);
2436
2437 // Create a second descriptor pool
2438 VkDescriptorPool ds_pool_two;
2439 err =
2440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2441 ASSERT_VK_SUCCESS(err);
2442
2443 VkDescriptorSetLayoutBinding dsl_binding = {};
2444 dsl_binding.binding = 0;
2445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2446 dsl_binding.descriptorCount = 1;
2447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2448 dsl_binding.pImmutableSamplers = NULL;
2449
2450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2452 ds_layout_ci.pNext = NULL;
2453 ds_layout_ci.bindingCount = 1;
2454 ds_layout_ci.pBindings = &dsl_binding;
2455
2456 VkDescriptorSetLayout ds_layout;
2457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2458 &ds_layout);
2459 ASSERT_VK_SUCCESS(err);
2460
2461 VkDescriptorSet descriptorSet;
2462 VkDescriptorSetAllocateInfo alloc_info = {};
2463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2464 alloc_info.descriptorSetCount = 1;
2465 alloc_info.descriptorPool = ds_pool_one;
2466 alloc_info.pSetLayouts = &ds_layout;
2467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2468 &descriptorSet);
2469 ASSERT_VK_SUCCESS(err);
2470
2471 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2472
2473 m_errorMonitor->VerifyFound();
2474
2475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2476 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2477 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2478}
2479
2480TEST_F(VkLayerTest, CreateUnknownObject) {
2481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2482 "Invalid VkImage Object ");
2483
2484 TEST_DESCRIPTION(
2485 "Pass an invalid image object handle into a Vulkan API call.");
2486
2487 ASSERT_NO_FATAL_FAILURE(InitState());
2488
2489 // Pass bogus handle into GetImageMemoryRequirements
2490 VkMemoryRequirements mem_reqs;
2491 uint64_t fakeImageHandle = 0xCADECADE;
2492 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2493
2494 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2495
2496 m_errorMonitor->VerifyFound();
2497}
2498
Karl Schultz6addd812016-02-02 17:17:23 -07002499TEST_F(VkLayerTest, PipelineNotBound) {
2500 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002502 TEST_DESCRIPTION(
2503 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2504
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002506 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002507
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002508 ASSERT_NO_FATAL_FAILURE(InitState());
2509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002511 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2513 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002514
2515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2517 ds_pool_ci.pNext = NULL;
2518 ds_pool_ci.maxSets = 1;
2519 ds_pool_ci.poolSizeCount = 1;
2520 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002521
2522 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002523 err =
2524 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002525 ASSERT_VK_SUCCESS(err);
2526
2527 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002528 dsl_binding.binding = 0;
2529 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2530 dsl_binding.descriptorCount = 1;
2531 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2532 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002533
2534 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002535 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2536 ds_layout_ci.pNext = NULL;
2537 ds_layout_ci.bindingCount = 1;
2538 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002539
2540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2542 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002543 ASSERT_VK_SUCCESS(err);
2544
2545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002548 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002549 alloc_info.descriptorPool = ds_pool;
2550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2552 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002553 ASSERT_VK_SUCCESS(err);
2554
2555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2557 pipeline_layout_ci.pNext = NULL;
2558 pipeline_layout_ci.setLayoutCount = 1;
2559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002560
2561 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2563 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002564 ASSERT_VK_SUCCESS(err);
2565
Mark Youngad779052016-01-06 14:26:04 -07002566 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002567
2568 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2570 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002572 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002573
Chia-I Wuf7458c52015-10-26 21:10:41 +08002574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002577}
2578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002584 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002585
Tobin Ehlisec598302015-09-15 15:02:17 -06002586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002589 VkImage image;
2590 VkDeviceMemory mem;
2591 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002592
Karl Schultz6addd812016-02-02 17:17:23 -07002593 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2594 const int32_t tex_width = 32;
2595 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
2597 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2599 image_create_info.pNext = NULL;
2600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2601 image_create_info.format = tex_format;
2602 image_create_info.extent.width = tex_width;
2603 image_create_info.extent.height = tex_height;
2604 image_create_info.extent.depth = 1;
2605 image_create_info.mipLevels = 1;
2606 image_create_info.arrayLayers = 1;
2607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2608 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2610 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002612 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2614 mem_alloc.pNext = NULL;
2615 mem_alloc.allocationSize = 0;
2616 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002617
Chia-I Wuf7458c52015-10-26 21:10:41 +08002618 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002619 ASSERT_VK_SUCCESS(err);
2620
Karl Schultz6addd812016-02-02 17:17:23 -07002621 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002622
2623 mem_alloc.allocationSize = mem_reqs.size;
2624
Karl Schultz6addd812016-02-02 17:17:23 -07002625 pass =
2626 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002627 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
2629 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002631 ASSERT_VK_SUCCESS(err);
2632
2633 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002634 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002635
2636 // Try to bind free memory that has been freed
2637 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2638 // This may very well return an error.
2639 (void)err;
2640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002642
Chia-I Wuf7458c52015-10-26 21:10:41 +08002643 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644}
2645
Karl Schultz6addd812016-02-02 17:17:23 -07002646TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2647 VkResult err;
2648 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002649
Karl Schultz6addd812016-02-02 17:17:23 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisec598302015-09-15 15:02:17 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Karl Schultz6addd812016-02-02 17:17:23 -07002655 // Create an image object, allocate memory, destroy the object and then try
2656 // to bind it
2657 VkImage image;
2658 VkDeviceMemory mem;
2659 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002660
Karl Schultz6addd812016-02-02 17:17:23 -07002661 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2662 const int32_t tex_width = 32;
2663 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
2665 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002666 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2667 image_create_info.pNext = NULL;
2668 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2669 image_create_info.format = tex_format;
2670 image_create_info.extent.width = tex_width;
2671 image_create_info.extent.height = tex_height;
2672 image_create_info.extent.depth = 1;
2673 image_create_info.mipLevels = 1;
2674 image_create_info.arrayLayers = 1;
2675 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2676 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2677 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2678 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002679
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002680 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002681 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2682 mem_alloc.pNext = NULL;
2683 mem_alloc.allocationSize = 0;
2684 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002685
Chia-I Wuf7458c52015-10-26 21:10:41 +08002686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002687 ASSERT_VK_SUCCESS(err);
2688
Karl Schultz6addd812016-02-02 17:17:23 -07002689 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002690
2691 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002692 pass =
2693 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002694 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002695
2696 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002701 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002702 ASSERT_VK_SUCCESS(err);
2703
2704 // Now Try to bind memory to this destroyed object
2705 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2706 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002707 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002709 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002710
Chia-I Wuf7458c52015-10-26 21:10:41 +08002711 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002713
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002714#endif // OBJ_TRACKER_TESTS
2715
Tobin Ehlis0788f522015-05-26 16:11:58 -06002716#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002717
2718// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05002719TEST_F(VkLayerTest, WaitEventThenSet) {
2720 TEST_DESCRIPTION(
2721 "Wait on a event then set it after the wait has been submitted.");
2722
2723 if ((m_device->queue_props.empty()) ||
2724 (m_device->queue_props[0].queueCount < 2))
2725 return;
2726
2727 m_errorMonitor->ExpectSuccess();
2728
2729 VkEvent event;
2730 VkEventCreateInfo event_create_info{};
2731 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2732 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2733
2734 VkCommandPool command_pool;
2735 VkCommandPoolCreateInfo pool_create_info{};
2736 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2737 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2738 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2739 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2740 &command_pool);
2741
2742 VkCommandBuffer command_buffer;
2743 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2744 command_buffer_allocate_info.sType =
2745 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2746 command_buffer_allocate_info.commandPool = command_pool;
2747 command_buffer_allocate_info.commandBufferCount = 1;
2748 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2749 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2750 &command_buffer);
2751
2752 VkQueue queue = VK_NULL_HANDLE;
2753 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2754 1, &queue);
2755
2756 {
2757 VkCommandBufferBeginInfo begin_info{};
2758 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2759 vkBeginCommandBuffer(command_buffer, &begin_info);
2760
2761 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
2762 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2763 nullptr, 0, nullptr);
2764 vkCmdResetEvent(command_buffer, event,
2765 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2766 vkEndCommandBuffer(command_buffer);
2767 }
2768 {
2769 VkSubmitInfo submit_info{};
2770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2771 submit_info.commandBufferCount = 1;
2772 submit_info.pCommandBuffers = &command_buffer;
2773 submit_info.signalSemaphoreCount = 0;
2774 submit_info.pSignalSemaphores = nullptr;
2775 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2776 }
2777 { vkSetEvent(m_device->device(), event); }
2778
2779 vkQueueWaitIdle(queue);
2780
2781 vkDestroyEvent(m_device->device(), event, nullptr);
2782 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2783 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2784
2785 m_errorMonitor->VerifyNotFound();
2786}
Michael Lentine5627e692016-05-20 17:45:02 -05002787// This is a positive test. No errors should be generated.
2788TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
2789 TEST_DESCRIPTION(
2790 "Issue a query and copy from it on a second command buffer.");
2791
2792 if ((m_device->queue_props.empty()) ||
2793 (m_device->queue_props[0].queueCount < 2))
2794 return;
2795
2796 m_errorMonitor->ExpectSuccess();
2797
2798 VkQueryPool query_pool;
2799 VkQueryPoolCreateInfo query_pool_create_info{};
2800 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
2801 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
2802 query_pool_create_info.queryCount = 1;
2803 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
2804 &query_pool);
2805
2806 VkCommandPool command_pool;
2807 VkCommandPoolCreateInfo pool_create_info{};
2808 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2809 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2810 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2811 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2812 &command_pool);
2813
2814 VkCommandBuffer command_buffer[2];
2815 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2816 command_buffer_allocate_info.sType =
2817 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2818 command_buffer_allocate_info.commandPool = command_pool;
2819 command_buffer_allocate_info.commandBufferCount = 2;
2820 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2821 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2822 command_buffer);
2823
2824 VkQueue queue = VK_NULL_HANDLE;
2825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2826 1, &queue);
2827
2828 uint32_t qfi = 0;
2829 VkBufferCreateInfo buff_create_info = {};
2830 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2831 buff_create_info.size = 1024;
2832 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
2833 buff_create_info.queueFamilyIndexCount = 1;
2834 buff_create_info.pQueueFamilyIndices = &qfi;
2835
2836 VkResult err;
2837 VkBuffer buffer;
2838 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
2839 ASSERT_VK_SUCCESS(err);
2840 VkMemoryAllocateInfo mem_alloc = {};
2841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2842 mem_alloc.pNext = NULL;
2843 mem_alloc.allocationSize = 1024;
2844 mem_alloc.memoryTypeIndex = 0;
2845
2846 VkMemoryRequirements memReqs;
2847 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
2848 bool pass =
2849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
2850 if (!pass) {
2851 vkDestroyBuffer(m_device->device(), buffer, NULL);
2852 return;
2853 }
2854
2855 VkDeviceMemory mem;
2856 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2857 ASSERT_VK_SUCCESS(err);
2858 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
2859 ASSERT_VK_SUCCESS(err);
2860
2861 {
2862 VkCommandBufferBeginInfo begin_info{};
2863 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2864 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2865
2866 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
2867 vkCmdWriteTimestamp(command_buffer[0],
2868 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
2869
2870 vkEndCommandBuffer(command_buffer[0]);
2871
2872 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2873
2874 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
2875 0, 0, 0);
2876
2877 vkEndCommandBuffer(command_buffer[1]);
2878 }
2879 {
2880 VkSubmitInfo submit_info{};
2881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2882 submit_info.commandBufferCount = 2;
2883 submit_info.pCommandBuffers = command_buffer;
2884 submit_info.signalSemaphoreCount = 0;
2885 submit_info.pSignalSemaphores = nullptr;
2886 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2887 }
2888
2889 vkQueueWaitIdle(queue);
2890
2891 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
2892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
2893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2894
2895 m_errorMonitor->VerifyNotFound();
2896}
Michael Lentine860b0fe2016-05-20 10:14:00 -05002897
2898TEST_F(VkLayerTest, ResetEventThenSet) {
2899 TEST_DESCRIPTION(
2900 "Reset an event then set it after the reset has been submitted.");
2901
2902 if ((m_device->queue_props.empty()) ||
2903 (m_device->queue_props[0].queueCount < 2))
2904 return;
2905
2906 m_errorMonitor->ExpectSuccess();
2907
2908 VkEvent event;
2909 VkEventCreateInfo event_create_info{};
2910 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
2911 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
2912
2913 VkCommandPool command_pool;
2914 VkCommandPoolCreateInfo pool_create_info{};
2915 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2916 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2917 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2918 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2919 &command_pool);
2920
2921 VkCommandBuffer command_buffer;
2922 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2923 command_buffer_allocate_info.sType =
2924 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2925 command_buffer_allocate_info.commandPool = command_pool;
2926 command_buffer_allocate_info.commandBufferCount = 1;
2927 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2928 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2929 &command_buffer);
2930
2931 VkQueue queue = VK_NULL_HANDLE;
2932 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2933 1, &queue);
2934
2935 {
2936 VkCommandBufferBeginInfo begin_info{};
2937 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2938 vkBeginCommandBuffer(command_buffer, &begin_info);
2939
2940 vkCmdResetEvent(command_buffer, event,
2941 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
2942 vkCmdWaitEvents(command_buffer, 1, &event,
2943 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2944 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
2945 nullptr, 0, nullptr);
2946 vkEndCommandBuffer(command_buffer);
2947 }
2948 {
2949 VkSubmitInfo submit_info{};
2950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2951 submit_info.commandBufferCount = 1;
2952 submit_info.pCommandBuffers = &command_buffer;
2953 submit_info.signalSemaphoreCount = 0;
2954 submit_info.pSignalSemaphores = nullptr;
2955 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2956 }
2957 {
2958 m_errorMonitor->SetDesiredFailureMsg(
2959 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
2960 "0x1 that is already in use by a "
2961 "command buffer.");
2962 vkSetEvent(m_device->device(), event);
2963 m_errorMonitor->VerifyFound();
2964 }
2965
2966 vkQueueWaitIdle(queue);
2967
2968 vkDestroyEvent(m_device->device(), event, nullptr);
2969 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
2970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2971}
2972
2973// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06002974TEST_F(VkLayerTest, TwoFencesThreeFrames) {
2975 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
2976 "run through a Submit & WaitForFences cycle 3 times. This "
2977 "previously revealed a bug so running this positive test "
2978 "to prevent a regression.");
2979 m_errorMonitor->ExpectSuccess();
2980
2981 ASSERT_NO_FATAL_FAILURE(InitState());
2982 VkQueue queue = VK_NULL_HANDLE;
2983 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2984 0, &queue);
2985
2986 static const uint32_t NUM_OBJECTS = 2;
2987 static const uint32_t NUM_FRAMES = 3;
2988 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
2989 VkFence fences[NUM_OBJECTS] = {};
2990
2991 VkCommandPool cmd_pool;
2992 VkCommandPoolCreateInfo cmd_pool_ci = {};
2993 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2994 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
2995 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2996 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
2997 nullptr, &cmd_pool);
2998 ASSERT_VK_SUCCESS(err);
2999
3000 VkCommandBufferAllocateInfo cmd_buf_info = {};
3001 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3002 cmd_buf_info.commandPool = cmd_pool;
3003 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3004 cmd_buf_info.commandBufferCount = 1;
3005
3006 VkFenceCreateInfo fence_ci = {};
3007 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3008 fence_ci.pNext = nullptr;
3009 fence_ci.flags = 0;
3010
3011 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3012 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3013 &cmd_buffers[i]);
3014 ASSERT_VK_SUCCESS(err);
3015 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3016 ASSERT_VK_SUCCESS(err);
3017 }
3018
3019 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
3020 // Create empty cmd buffer
3021 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3022 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3023
3024 err = vkBeginCommandBuffer(cmd_buffers[0], &cmdBufBeginDesc);
3025 ASSERT_VK_SUCCESS(err);
3026 err = vkEndCommandBuffer(cmd_buffers[0]);
3027 ASSERT_VK_SUCCESS(err);
3028
3029 VkSubmitInfo submit_info = {};
3030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3031 submit_info.commandBufferCount = 1;
3032 submit_info.pCommandBuffers = &cmd_buffers[0];
3033 // Submit cmd buffer and wait for fence
3034 err = vkQueueSubmit(queue, 1, &submit_info, fences[0]);
3035 ASSERT_VK_SUCCESS(err);
3036 err = vkWaitForFences(m_device->device(), 1, &fences[0], VK_TRUE,
3037 UINT64_MAX);
3038 ASSERT_VK_SUCCESS(err);
3039 err = vkResetFences(m_device->device(), 1, &fences[0]);
3040 ASSERT_VK_SUCCESS(err);
3041
3042 // 2nd cmd buffer with separate fence
3043 err = vkBeginCommandBuffer(cmd_buffers[1], &cmdBufBeginDesc);
3044 ASSERT_VK_SUCCESS(err);
3045 err = vkEndCommandBuffer(cmd_buffers[1]);
3046 ASSERT_VK_SUCCESS(err);
3047 // Update submit info to refer to 2nd cmd buffer
3048 submit_info.pCommandBuffers = &cmd_buffers[1];
3049 // Submit 2nd cmd buffer and wait for its fence
3050 err = vkQueueSubmit(queue, 1, &submit_info, fences[1]);
3051 ASSERT_VK_SUCCESS(err);
3052 err = vkWaitForFences(m_device->device(), 1, &fences[1], VK_TRUE,
3053 UINT64_MAX);
3054 ASSERT_VK_SUCCESS(err);
3055 err = vkResetFences(m_device->device(), 1, &fences[1]);
3056 ASSERT_VK_SUCCESS(err);
3057 }
3058 m_errorMonitor->VerifyNotFound();
3059}
3060// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003061TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3062
3063 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3064 "submitted on separate queues followed by a QueueWaitIdle.");
3065
Dustin Graves48458142016-04-29 16:11:55 -06003066 if ((m_device->queue_props.empty()) ||
3067 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003068 return;
3069
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003070 m_errorMonitor->ExpectSuccess();
3071
3072 VkSemaphore semaphore;
3073 VkSemaphoreCreateInfo semaphore_create_info{};
3074 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3075 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3076 &semaphore);
3077
3078 VkCommandPool command_pool;
3079 VkCommandPoolCreateInfo pool_create_info{};
3080 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3081 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3082 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3083 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3084 &command_pool);
3085
3086 VkCommandBuffer command_buffer[2];
3087 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3088 command_buffer_allocate_info.sType =
3089 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3090 command_buffer_allocate_info.commandPool = command_pool;
3091 command_buffer_allocate_info.commandBufferCount = 2;
3092 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3093 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3094 command_buffer);
3095
3096 VkQueue queue = VK_NULL_HANDLE;
3097 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3098 1, &queue);
3099
3100 {
3101 VkCommandBufferBeginInfo begin_info{};
3102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3103 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3104
3105 vkCmdPipelineBarrier(command_buffer[0],
3106 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3107 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3108 0, nullptr, 0, nullptr);
3109
3110 VkViewport viewport{};
3111 viewport.maxDepth = 1.0f;
3112 viewport.minDepth = 0.0f;
3113 viewport.width = 512;
3114 viewport.height = 512;
3115 viewport.x = 0;
3116 viewport.y = 0;
3117 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3118 vkEndCommandBuffer(command_buffer[0]);
3119 }
3120 {
3121 VkCommandBufferBeginInfo begin_info{};
3122 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3123 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3124
3125 VkViewport viewport{};
3126 viewport.maxDepth = 1.0f;
3127 viewport.minDepth = 0.0f;
3128 viewport.width = 512;
3129 viewport.height = 512;
3130 viewport.x = 0;
3131 viewport.y = 0;
3132 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3133 vkEndCommandBuffer(command_buffer[1]);
3134 }
3135 {
3136 VkSubmitInfo submit_info{};
3137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3138 submit_info.commandBufferCount = 1;
3139 submit_info.pCommandBuffers = &command_buffer[0];
3140 submit_info.signalSemaphoreCount = 1;
3141 submit_info.pSignalSemaphores = &semaphore;
3142 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3143 }
3144 {
3145 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3146 VkSubmitInfo submit_info{};
3147 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3148 submit_info.commandBufferCount = 1;
3149 submit_info.pCommandBuffers = &command_buffer[1];
3150 submit_info.waitSemaphoreCount = 1;
3151 submit_info.pWaitSemaphores = &semaphore;
3152 submit_info.pWaitDstStageMask = flags;
3153 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3154 }
3155
3156 vkQueueWaitIdle(m_device->m_queue);
3157
3158 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3159 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3160 &command_buffer[0]);
3161 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3162
3163 m_errorMonitor->VerifyNotFound();
3164}
3165
3166// This is a positive test. No errors should be generated.
3167TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3168
3169 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3170 "submitted on separate queues, the second having a fence"
3171 "followed by a QueueWaitIdle.");
3172
Dustin Graves48458142016-04-29 16:11:55 -06003173 if ((m_device->queue_props.empty()) ||
3174 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003175 return;
3176
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003177 m_errorMonitor->ExpectSuccess();
3178
3179 VkFence fence;
3180 VkFenceCreateInfo fence_create_info{};
3181 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3182 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3183
3184 VkSemaphore semaphore;
3185 VkSemaphoreCreateInfo semaphore_create_info{};
3186 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3187 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3188 &semaphore);
3189
3190 VkCommandPool command_pool;
3191 VkCommandPoolCreateInfo pool_create_info{};
3192 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3193 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3194 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3195 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3196 &command_pool);
3197
3198 VkCommandBuffer command_buffer[2];
3199 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3200 command_buffer_allocate_info.sType =
3201 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3202 command_buffer_allocate_info.commandPool = command_pool;
3203 command_buffer_allocate_info.commandBufferCount = 2;
3204 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3205 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3206 command_buffer);
3207
3208 VkQueue queue = VK_NULL_HANDLE;
3209 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3210 1, &queue);
3211
3212 {
3213 VkCommandBufferBeginInfo begin_info{};
3214 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3215 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3216
3217 vkCmdPipelineBarrier(command_buffer[0],
3218 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3219 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3220 0, nullptr, 0, nullptr);
3221
3222 VkViewport viewport{};
3223 viewport.maxDepth = 1.0f;
3224 viewport.minDepth = 0.0f;
3225 viewport.width = 512;
3226 viewport.height = 512;
3227 viewport.x = 0;
3228 viewport.y = 0;
3229 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3230 vkEndCommandBuffer(command_buffer[0]);
3231 }
3232 {
3233 VkCommandBufferBeginInfo begin_info{};
3234 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3235 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3236
3237 VkViewport viewport{};
3238 viewport.maxDepth = 1.0f;
3239 viewport.minDepth = 0.0f;
3240 viewport.width = 512;
3241 viewport.height = 512;
3242 viewport.x = 0;
3243 viewport.y = 0;
3244 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3245 vkEndCommandBuffer(command_buffer[1]);
3246 }
3247 {
3248 VkSubmitInfo submit_info{};
3249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3250 submit_info.commandBufferCount = 1;
3251 submit_info.pCommandBuffers = &command_buffer[0];
3252 submit_info.signalSemaphoreCount = 1;
3253 submit_info.pSignalSemaphores = &semaphore;
3254 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3255 }
3256 {
3257 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3258 VkSubmitInfo submit_info{};
3259 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3260 submit_info.commandBufferCount = 1;
3261 submit_info.pCommandBuffers = &command_buffer[1];
3262 submit_info.waitSemaphoreCount = 1;
3263 submit_info.pWaitSemaphores = &semaphore;
3264 submit_info.pWaitDstStageMask = flags;
3265 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3266 }
3267
3268 vkQueueWaitIdle(m_device->m_queue);
3269
3270 vkDestroyFence(m_device->device(), fence, nullptr);
3271 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3272 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3273 &command_buffer[0]);
3274 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3275
3276 m_errorMonitor->VerifyNotFound();
3277}
3278
3279// This is a positive test. No errors should be generated.
3280TEST_F(VkLayerTest,
3281 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3282
3283 TEST_DESCRIPTION(
3284 "Two command buffers, each in a separate QueueSubmit call "
3285 "submitted on separate queues, the second having a fence"
3286 "followed by two consecutive WaitForFences calls on the same fence.");
3287
Dustin Graves48458142016-04-29 16:11:55 -06003288 if ((m_device->queue_props.empty()) ||
3289 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003290 return;
3291
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003292 m_errorMonitor->ExpectSuccess();
3293
3294 VkFence fence;
3295 VkFenceCreateInfo fence_create_info{};
3296 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3297 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3298
3299 VkSemaphore semaphore;
3300 VkSemaphoreCreateInfo semaphore_create_info{};
3301 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3302 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3303 &semaphore);
3304
3305 VkCommandPool command_pool;
3306 VkCommandPoolCreateInfo pool_create_info{};
3307 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3308 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3309 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3310 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3311 &command_pool);
3312
3313 VkCommandBuffer command_buffer[2];
3314 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3315 command_buffer_allocate_info.sType =
3316 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3317 command_buffer_allocate_info.commandPool = command_pool;
3318 command_buffer_allocate_info.commandBufferCount = 2;
3319 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3320 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3321 command_buffer);
3322
3323 VkQueue queue = VK_NULL_HANDLE;
3324 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3325 1, &queue);
3326
3327 {
3328 VkCommandBufferBeginInfo begin_info{};
3329 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3330 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3331
3332 vkCmdPipelineBarrier(command_buffer[0],
3333 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3334 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3335 0, nullptr, 0, nullptr);
3336
3337 VkViewport viewport{};
3338 viewport.maxDepth = 1.0f;
3339 viewport.minDepth = 0.0f;
3340 viewport.width = 512;
3341 viewport.height = 512;
3342 viewport.x = 0;
3343 viewport.y = 0;
3344 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3345 vkEndCommandBuffer(command_buffer[0]);
3346 }
3347 {
3348 VkCommandBufferBeginInfo begin_info{};
3349 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3350 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3351
3352 VkViewport viewport{};
3353 viewport.maxDepth = 1.0f;
3354 viewport.minDepth = 0.0f;
3355 viewport.width = 512;
3356 viewport.height = 512;
3357 viewport.x = 0;
3358 viewport.y = 0;
3359 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3360 vkEndCommandBuffer(command_buffer[1]);
3361 }
3362 {
3363 VkSubmitInfo submit_info{};
3364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3365 submit_info.commandBufferCount = 1;
3366 submit_info.pCommandBuffers = &command_buffer[0];
3367 submit_info.signalSemaphoreCount = 1;
3368 submit_info.pSignalSemaphores = &semaphore;
3369 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3370 }
3371 {
3372 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3373 VkSubmitInfo submit_info{};
3374 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3375 submit_info.commandBufferCount = 1;
3376 submit_info.pCommandBuffers = &command_buffer[1];
3377 submit_info.waitSemaphoreCount = 1;
3378 submit_info.pWaitSemaphores = &semaphore;
3379 submit_info.pWaitDstStageMask = flags;
3380 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3381 }
3382
3383 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3384 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3385
3386 vkDestroyFence(m_device->device(), fence, nullptr);
3387 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3388 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3389 &command_buffer[0]);
3390 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3391
3392 m_errorMonitor->VerifyNotFound();
3393}
3394
3395// This is a positive test. No errors should be generated.
3396TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3397
3398 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3399 "submitted on separate queues, the second having a fence, "
3400 "followed by a WaitForFences call.");
3401
Dustin Graves48458142016-04-29 16:11:55 -06003402 if ((m_device->queue_props.empty()) ||
3403 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003404 return;
3405
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003406 m_errorMonitor->ExpectSuccess();
3407
3408 VkFence fence;
3409 VkFenceCreateInfo fence_create_info{};
3410 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3411 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3412
3413 VkSemaphore semaphore;
3414 VkSemaphoreCreateInfo semaphore_create_info{};
3415 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3416 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3417 &semaphore);
3418
3419 VkCommandPool command_pool;
3420 VkCommandPoolCreateInfo pool_create_info{};
3421 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3422 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3423 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3424 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3425 &command_pool);
3426
3427 VkCommandBuffer command_buffer[2];
3428 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3429 command_buffer_allocate_info.sType =
3430 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3431 command_buffer_allocate_info.commandPool = command_pool;
3432 command_buffer_allocate_info.commandBufferCount = 2;
3433 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3434 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3435 command_buffer);
3436
3437 VkQueue queue = VK_NULL_HANDLE;
3438 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3439 1, &queue);
3440
3441
3442 {
3443 VkCommandBufferBeginInfo begin_info{};
3444 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3445 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3446
3447 vkCmdPipelineBarrier(command_buffer[0],
3448 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3449 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3450 0, nullptr, 0, nullptr);
3451
3452 VkViewport viewport{};
3453 viewport.maxDepth = 1.0f;
3454 viewport.minDepth = 0.0f;
3455 viewport.width = 512;
3456 viewport.height = 512;
3457 viewport.x = 0;
3458 viewport.y = 0;
3459 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3460 vkEndCommandBuffer(command_buffer[0]);
3461 }
3462 {
3463 VkCommandBufferBeginInfo begin_info{};
3464 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3465 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3466
3467 VkViewport viewport{};
3468 viewport.maxDepth = 1.0f;
3469 viewport.minDepth = 0.0f;
3470 viewport.width = 512;
3471 viewport.height = 512;
3472 viewport.x = 0;
3473 viewport.y = 0;
3474 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3475 vkEndCommandBuffer(command_buffer[1]);
3476 }
3477 {
3478 VkSubmitInfo submit_info{};
3479 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3480 submit_info.commandBufferCount = 1;
3481 submit_info.pCommandBuffers = &command_buffer[0];
3482 submit_info.signalSemaphoreCount = 1;
3483 submit_info.pSignalSemaphores = &semaphore;
3484 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3485 }
3486 {
3487 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3488 VkSubmitInfo submit_info{};
3489 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3490 submit_info.commandBufferCount = 1;
3491 submit_info.pCommandBuffers = &command_buffer[1];
3492 submit_info.waitSemaphoreCount = 1;
3493 submit_info.pWaitSemaphores = &semaphore;
3494 submit_info.pWaitDstStageMask = flags;
3495 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3496 }
3497
3498 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3499
3500 vkDestroyFence(m_device->device(), fence, nullptr);
3501 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3502 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3503 &command_buffer[0]);
3504 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3505
3506 m_errorMonitor->VerifyNotFound();
3507}
3508
3509// This is a positive test. No errors should be generated.
3510TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3511
3512 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3513 "on the same queue, sharing a signal/wait semaphore, the "
3514 "second having a fence, "
3515 "followed by a WaitForFences call.");
3516
3517 m_errorMonitor->ExpectSuccess();
3518
3519 VkFence fence;
3520 VkFenceCreateInfo fence_create_info{};
3521 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3522 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3523
3524 VkSemaphore semaphore;
3525 VkSemaphoreCreateInfo semaphore_create_info{};
3526 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3527 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3528 &semaphore);
3529
3530 VkCommandPool command_pool;
3531 VkCommandPoolCreateInfo pool_create_info{};
3532 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3533 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3534 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3535 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3536 &command_pool);
3537
3538 VkCommandBuffer command_buffer[2];
3539 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3540 command_buffer_allocate_info.sType =
3541 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3542 command_buffer_allocate_info.commandPool = command_pool;
3543 command_buffer_allocate_info.commandBufferCount = 2;
3544 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3545 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3546 command_buffer);
3547
3548 {
3549 VkCommandBufferBeginInfo begin_info{};
3550 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3551 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3552
3553 vkCmdPipelineBarrier(command_buffer[0],
3554 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3555 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3556 0, nullptr, 0, nullptr);
3557
3558 VkViewport viewport{};
3559 viewport.maxDepth = 1.0f;
3560 viewport.minDepth = 0.0f;
3561 viewport.width = 512;
3562 viewport.height = 512;
3563 viewport.x = 0;
3564 viewport.y = 0;
3565 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3566 vkEndCommandBuffer(command_buffer[0]);
3567 }
3568 {
3569 VkCommandBufferBeginInfo begin_info{};
3570 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3571 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3572
3573 VkViewport viewport{};
3574 viewport.maxDepth = 1.0f;
3575 viewport.minDepth = 0.0f;
3576 viewport.width = 512;
3577 viewport.height = 512;
3578 viewport.x = 0;
3579 viewport.y = 0;
3580 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3581 vkEndCommandBuffer(command_buffer[1]);
3582 }
3583 {
3584 VkSubmitInfo submit_info{};
3585 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3586 submit_info.commandBufferCount = 1;
3587 submit_info.pCommandBuffers = &command_buffer[0];
3588 submit_info.signalSemaphoreCount = 1;
3589 submit_info.pSignalSemaphores = &semaphore;
3590 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3591 }
3592 {
3593 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3594 VkSubmitInfo submit_info{};
3595 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3596 submit_info.commandBufferCount = 1;
3597 submit_info.pCommandBuffers = &command_buffer[1];
3598 submit_info.waitSemaphoreCount = 1;
3599 submit_info.pWaitSemaphores = &semaphore;
3600 submit_info.pWaitDstStageMask = flags;
3601 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3602 }
3603
3604 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3605
3606 vkDestroyFence(m_device->device(), fence, nullptr);
3607 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3608 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3609 &command_buffer[0]);
3610 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3611
3612 m_errorMonitor->VerifyNotFound();
3613}
3614
3615// This is a positive test. No errors should be generated.
3616TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
3617
3618 TEST_DESCRIPTION(
3619 "Two command buffers, each in a separate QueueSubmit call "
3620 "on the same queue, no fences, followed by a third QueueSubmit with NO "
3621 "SubmitInfos but with a fence, followed by a WaitForFences call.");
3622
3623 m_errorMonitor->ExpectSuccess();
3624
3625 VkFence fence;
3626 VkFenceCreateInfo fence_create_info{};
3627 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3628 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3629
3630 VkCommandPool command_pool;
3631 VkCommandPoolCreateInfo pool_create_info{};
3632 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3633 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3634 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3635 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3636 &command_pool);
3637
3638 VkCommandBuffer command_buffer[2];
3639 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3640 command_buffer_allocate_info.sType =
3641 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3642 command_buffer_allocate_info.commandPool = command_pool;
3643 command_buffer_allocate_info.commandBufferCount = 2;
3644 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3645 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3646 command_buffer);
3647
3648 {
3649 VkCommandBufferBeginInfo begin_info{};
3650 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3651 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3652
3653 vkCmdPipelineBarrier(command_buffer[0],
3654 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3655 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3656 0, nullptr, 0, nullptr);
3657
3658 VkViewport viewport{};
3659 viewport.maxDepth = 1.0f;
3660 viewport.minDepth = 0.0f;
3661 viewport.width = 512;
3662 viewport.height = 512;
3663 viewport.x = 0;
3664 viewport.y = 0;
3665 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3666 vkEndCommandBuffer(command_buffer[0]);
3667 }
3668 {
3669 VkCommandBufferBeginInfo begin_info{};
3670 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3671 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3672
3673 VkViewport viewport{};
3674 viewport.maxDepth = 1.0f;
3675 viewport.minDepth = 0.0f;
3676 viewport.width = 512;
3677 viewport.height = 512;
3678 viewport.x = 0;
3679 viewport.y = 0;
3680 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3681 vkEndCommandBuffer(command_buffer[1]);
3682 }
3683 {
3684 VkSubmitInfo submit_info{};
3685 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3686 submit_info.commandBufferCount = 1;
3687 submit_info.pCommandBuffers = &command_buffer[0];
3688 submit_info.signalSemaphoreCount = 0;
3689 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3690 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3691 }
3692 {
3693 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3694 VkSubmitInfo submit_info{};
3695 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3696 submit_info.commandBufferCount = 1;
3697 submit_info.pCommandBuffers = &command_buffer[1];
3698 submit_info.waitSemaphoreCount = 0;
3699 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3700 submit_info.pWaitDstStageMask = flags;
3701 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3702 }
3703
3704 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
3705
3706 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3707
3708 vkDestroyFence(m_device->device(), fence, nullptr);
3709 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3710 &command_buffer[0]);
3711 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3712
3713 m_errorMonitor->VerifyNotFound();
3714}
3715
3716// This is a positive test. No errors should be generated.
3717TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
3718
3719 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3720 "on the same queue, the second having a fence, followed "
3721 "by a WaitForFences call.");
3722
3723 m_errorMonitor->ExpectSuccess();
3724
3725 VkFence fence;
3726 VkFenceCreateInfo fence_create_info{};
3727 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3728 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3729
3730 VkCommandPool command_pool;
3731 VkCommandPoolCreateInfo pool_create_info{};
3732 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3733 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3734 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3735 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3736 &command_pool);
3737
3738 VkCommandBuffer command_buffer[2];
3739 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3740 command_buffer_allocate_info.sType =
3741 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3742 command_buffer_allocate_info.commandPool = command_pool;
3743 command_buffer_allocate_info.commandBufferCount = 2;
3744 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3745 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3746 command_buffer);
3747
3748 {
3749 VkCommandBufferBeginInfo begin_info{};
3750 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3751 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3752
3753 vkCmdPipelineBarrier(command_buffer[0],
3754 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3755 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3756 0, nullptr, 0, nullptr);
3757
3758 VkViewport viewport{};
3759 viewport.maxDepth = 1.0f;
3760 viewport.minDepth = 0.0f;
3761 viewport.width = 512;
3762 viewport.height = 512;
3763 viewport.x = 0;
3764 viewport.y = 0;
3765 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3766 vkEndCommandBuffer(command_buffer[0]);
3767 }
3768 {
3769 VkCommandBufferBeginInfo begin_info{};
3770 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3771 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3772
3773 VkViewport viewport{};
3774 viewport.maxDepth = 1.0f;
3775 viewport.minDepth = 0.0f;
3776 viewport.width = 512;
3777 viewport.height = 512;
3778 viewport.x = 0;
3779 viewport.y = 0;
3780 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3781 vkEndCommandBuffer(command_buffer[1]);
3782 }
3783 {
3784 VkSubmitInfo submit_info{};
3785 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3786 submit_info.commandBufferCount = 1;
3787 submit_info.pCommandBuffers = &command_buffer[0];
3788 submit_info.signalSemaphoreCount = 0;
3789 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
3790 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3791 }
3792 {
3793 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3794 VkSubmitInfo submit_info{};
3795 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3796 submit_info.commandBufferCount = 1;
3797 submit_info.pCommandBuffers = &command_buffer[1];
3798 submit_info.waitSemaphoreCount = 0;
3799 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
3800 submit_info.pWaitDstStageMask = flags;
3801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3802 }
3803
3804 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3805
3806 vkDestroyFence(m_device->device(), fence, nullptr);
3807 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3808 &command_buffer[0]);
3809 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3810
3811 m_errorMonitor->VerifyNotFound();
3812}
3813
3814// This is a positive test. No errors should be generated.
3815TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
3816
3817 TEST_DESCRIPTION(
3818 "Two command buffers each in a separate SubmitInfo sent in a single "
3819 "QueueSubmit call followed by a WaitForFences call.");
3820
3821 m_errorMonitor->ExpectSuccess();
3822
3823 VkFence fence;
3824 VkFenceCreateInfo fence_create_info{};
3825 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3826 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3827
3828 VkSemaphore semaphore;
3829 VkSemaphoreCreateInfo semaphore_create_info{};
3830 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3831 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3832 &semaphore);
3833
3834 VkCommandPool command_pool;
3835 VkCommandPoolCreateInfo pool_create_info{};
3836 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3837 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3838 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3839 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3840 &command_pool);
3841
3842 VkCommandBuffer command_buffer[2];
3843 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3844 command_buffer_allocate_info.sType =
3845 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3846 command_buffer_allocate_info.commandPool = command_pool;
3847 command_buffer_allocate_info.commandBufferCount = 2;
3848 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3849 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3850 command_buffer);
3851
3852 {
3853 VkCommandBufferBeginInfo begin_info{};
3854 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3855 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3856
3857 vkCmdPipelineBarrier(command_buffer[0],
3858 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3859 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3860 0, nullptr, 0, nullptr);
3861
3862 VkViewport viewport{};
3863 viewport.maxDepth = 1.0f;
3864 viewport.minDepth = 0.0f;
3865 viewport.width = 512;
3866 viewport.height = 512;
3867 viewport.x = 0;
3868 viewport.y = 0;
3869 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3870 vkEndCommandBuffer(command_buffer[0]);
3871 }
3872 {
3873 VkCommandBufferBeginInfo begin_info{};
3874 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3875 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3876
3877 VkViewport viewport{};
3878 viewport.maxDepth = 1.0f;
3879 viewport.minDepth = 0.0f;
3880 viewport.width = 512;
3881 viewport.height = 512;
3882 viewport.x = 0;
3883 viewport.y = 0;
3884 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3885 vkEndCommandBuffer(command_buffer[1]);
3886 }
3887 {
3888 VkSubmitInfo submit_info[2];
3889 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3890
3891 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3892 submit_info[0].pNext = NULL;
3893 submit_info[0].commandBufferCount = 1;
3894 submit_info[0].pCommandBuffers = &command_buffer[0];
3895 submit_info[0].signalSemaphoreCount = 1;
3896 submit_info[0].pSignalSemaphores = &semaphore;
3897 submit_info[0].waitSemaphoreCount = 0;
3898 submit_info[0].pWaitSemaphores = NULL;
3899 submit_info[0].pWaitDstStageMask = 0;
3900
3901 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3902 submit_info[1].pNext = NULL;
3903 submit_info[1].commandBufferCount = 1;
3904 submit_info[1].pCommandBuffers = &command_buffer[1];
3905 submit_info[1].waitSemaphoreCount = 1;
3906 submit_info[1].pWaitSemaphores = &semaphore;
3907 submit_info[1].pWaitDstStageMask = flags;
3908 submit_info[1].signalSemaphoreCount = 0;
3909 submit_info[1].pSignalSemaphores = NULL;
3910 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
3911 }
3912
3913 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3914
3915 vkDestroyFence(m_device->device(), fence, nullptr);
3916 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3917 &command_buffer[0]);
3918 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3919
3920 m_errorMonitor->VerifyNotFound();
3921}
3922
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003923TEST_F(VkLayerTest, DynamicStatesNotBound) {
3924 TEST_DESCRIPTION(
3925 "Run a series of simple draw calls to validate all the different "
3926 "failure cases that can occur when dynamic state is required but not "
3927 "correctly bound."
3928 "Here are the different dynamic state cases verified by this test:\n"
3929 "-Line Width\n-Depth Bias\n-Viewport State\n-Scissor State\n-Blend "
3930 "State\n-Depth Bounds\n-Stencil Read Mask\n-Stencil Write "
3931 "Mask\n-Stencil Reference");
3932
3933 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07003934 m_errorMonitor->SetDesiredFailureMsg(
3935 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003936 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003937 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3938 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003939 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003940 // Dynamic depth bias
Karl Schultz6addd812016-02-02 17:17:23 -07003941 m_errorMonitor->SetDesiredFailureMsg(
3942 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003943 "Dynamic depth bias state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003944 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3945 BsoFailDepthBias);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003946 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003947 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07003948 m_errorMonitor->SetDesiredFailureMsg(
3949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003950 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003951 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3952 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003953 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003954 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07003955 m_errorMonitor->SetDesiredFailureMsg(
3956 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003957 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003958 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3959 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003960 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003961 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07003962 m_errorMonitor->SetDesiredFailureMsg(
3963 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003964 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003965 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3966 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003967 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003968 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07003969 m_errorMonitor->SetDesiredFailureMsg(
3970 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003971 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003972 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3973 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003974 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003975 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07003976 m_errorMonitor->SetDesiredFailureMsg(
3977 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003978 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003979 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3980 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003981 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003982 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07003983 m_errorMonitor->SetDesiredFailureMsg(
3984 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003985 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07003986 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
3987 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003988 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003989}
3990
Karl Schultz6addd812016-02-02 17:17:23 -07003991TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003992 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003993
Karl Schultz6addd812016-02-02 17:17:23 -07003994 m_errorMonitor->SetDesiredFailureMsg(
3995 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3996 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3997 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003998
3999 VkFenceCreateInfo fenceInfo = {};
4000 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4001 fenceInfo.pNext = NULL;
4002 fenceInfo.flags = 0;
4003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005 ASSERT_NO_FATAL_FAILURE(InitViewport());
4006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4007
Karl Schultz6addd812016-02-02 17:17:23 -07004008 // We luck out b/c by default the framework creates CB w/ the
4009 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004010 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004011 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4012 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004013 EndCommandBuffer();
4014
4015 testFence.init(*m_device, fenceInfo);
4016
4017 // Bypass framework since it does the waits automatically
4018 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004019 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4021 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004022 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004023 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004024 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004025 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004027 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004028 submit_info.pSignalSemaphores = NULL;
4029
Karl Schultz6addd812016-02-02 17:17:23 -07004030 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
4031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004032
Karl Schultz6addd812016-02-02 17:17:23 -07004033 // Cause validation error by re-submitting cmd buffer that should only be
4034 // submitted once
4035 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004036
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004037 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004038}
4039
Karl Schultz6addd812016-02-02 17:17:23 -07004040TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004041 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004042 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004043
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004045 "Unable to allocate 1 descriptors of "
4046 "type "
4047 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004048
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004049 ASSERT_NO_FATAL_FAILURE(InitState());
4050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004051
Karl Schultz6addd812016-02-02 17:17:23 -07004052 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4053 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004054 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004055 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4056 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004057
4058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4060 ds_pool_ci.pNext = NULL;
4061 ds_pool_ci.flags = 0;
4062 ds_pool_ci.maxSets = 1;
4063 ds_pool_ci.poolSizeCount = 1;
4064 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004065
4066 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004067 err =
4068 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004069 ASSERT_VK_SUCCESS(err);
4070
4071 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004072 dsl_binding.binding = 0;
4073 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4074 dsl_binding.descriptorCount = 1;
4075 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4076 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004077
4078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4080 ds_layout_ci.pNext = NULL;
4081 ds_layout_ci.bindingCount = 1;
4082 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004083
4084 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004085 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4086 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004087 ASSERT_VK_SUCCESS(err);
4088
4089 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004090 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004091 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004092 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004093 alloc_info.descriptorPool = ds_pool;
4094 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004095 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4096 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004097
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004098 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004099
Chia-I Wuf7458c52015-10-26 21:10:41 +08004100 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004102}
4103
Karl Schultz6addd812016-02-02 17:17:23 -07004104TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4105 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004106
Karl Schultz6addd812016-02-02 17:17:23 -07004107 m_errorMonitor->SetDesiredFailureMsg(
4108 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4109 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4110 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004111
Tobin Ehlise735c692015-10-08 13:13:50 -06004112 ASSERT_NO_FATAL_FAILURE(InitState());
4113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004114
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004115 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004116 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4117 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004118
4119 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004120 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4121 ds_pool_ci.pNext = NULL;
4122 ds_pool_ci.maxSets = 1;
4123 ds_pool_ci.poolSizeCount = 1;
4124 ds_pool_ci.flags = 0;
4125 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4126 // app can only call vkResetDescriptorPool on this pool.;
4127 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004128
4129 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004130 err =
4131 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004132 ASSERT_VK_SUCCESS(err);
4133
4134 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004135 dsl_binding.binding = 0;
4136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4137 dsl_binding.descriptorCount = 1;
4138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4139 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004140
4141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4143 ds_layout_ci.pNext = NULL;
4144 ds_layout_ci.bindingCount = 1;
4145 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004146
4147 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4149 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004150 ASSERT_VK_SUCCESS(err);
4151
4152 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004153 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004154 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004155 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004156 alloc_info.descriptorPool = ds_pool;
4157 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004158 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4159 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004160 ASSERT_VK_SUCCESS(err);
4161
4162 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004164
Chia-I Wuf7458c52015-10-26 21:10:41 +08004165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4166 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004167}
4168
Karl Schultz6addd812016-02-02 17:17:23 -07004169TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004170 // Attempt to clear Descriptor Pool with bad object.
4171 // ObjectTracker should catch this.
4172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4173 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004174 uint64_t fake_pool_handle = 0xbaad6001;
4175 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4176 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004177 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004178}
4179
Karl Schultz6addd812016-02-02 17:17:23 -07004180TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004181 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4182 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004183 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004184 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004185
4186 uint64_t fake_set_handle = 0xbaad6001;
4187 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004188 VkResult err;
4189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4190 "Invalid VkDescriptorSet Object 0xbaad6001");
4191
4192 ASSERT_NO_FATAL_FAILURE(InitState());
4193
4194 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4195 layout_bindings[0].binding = 0;
4196 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4197 layout_bindings[0].descriptorCount = 1;
4198 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4199 layout_bindings[0].pImmutableSamplers = NULL;
4200
4201 VkDescriptorSetLayout descriptor_set_layout;
4202 VkDescriptorSetLayoutCreateInfo dslci = {};
4203 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4204 dslci.pNext = NULL;
4205 dslci.bindingCount = 1;
4206 dslci.pBindings = layout_bindings;
4207 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004208 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004209
4210 VkPipelineLayout pipeline_layout;
4211 VkPipelineLayoutCreateInfo plci = {};
4212 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4213 plci.pNext = NULL;
4214 plci.setLayoutCount = 1;
4215 plci.pSetLayouts = &descriptor_set_layout;
4216 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004217 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004218
4219 BeginCommandBuffer();
4220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004221 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004222 m_errorMonitor->VerifyFound();
4223 EndCommandBuffer();
4224 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4225 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004226}
4227
Karl Schultz6addd812016-02-02 17:17:23 -07004228TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004229 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4230 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004231 uint64_t fake_layout_handle = 0xbaad6001;
4232 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4234 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4235
4236 VkPipelineLayout pipeline_layout;
4237 VkPipelineLayoutCreateInfo plci = {};
4238 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4239 plci.pNext = NULL;
4240 plci.setLayoutCount = 1;
4241 plci.pSetLayouts = &bad_layout;
4242 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4243
4244 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004245}
4246
Karl Schultz6addd812016-02-02 17:17:23 -07004247TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004248 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4249 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004250 // Create a valid cmd buffer
4251 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004252 uint64_t fake_pipeline_handle = 0xbaad6001;
4253 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4255 "Invalid VkPipeline Object 0xbaad6001");
4256 ASSERT_NO_FATAL_FAILURE(InitState());
4257 BeginCommandBuffer();
4258 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4259 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4260 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004261
4262 // Now issue a draw call with no pipeline bound
4263 m_errorMonitor->SetDesiredFailureMsg(
4264 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4265 "At Draw/Dispatch time no valid VkPipeline is bound!");
4266 ASSERT_NO_FATAL_FAILURE(InitState());
4267 BeginCommandBuffer();
4268 Draw(1, 0, 0, 0);
4269 m_errorMonitor->VerifyFound();
4270 // Finally same check once more but with Dispatch/Compute
4271 m_errorMonitor->SetDesiredFailureMsg(
4272 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4273 "At Draw/Dispatch time no valid VkPipeline is bound!");
4274 ASSERT_NO_FATAL_FAILURE(InitState());
4275 BeginCommandBuffer();
4276 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4277 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004278}
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4281 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4282 // CommandBuffer
4283 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004284
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004286 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004287
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004288 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004289 ASSERT_NO_FATAL_FAILURE(InitViewport());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004291 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004292 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4293 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004294
4295 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004296 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4297 ds_pool_ci.pNext = NULL;
4298 ds_pool_ci.maxSets = 1;
4299 ds_pool_ci.poolSizeCount = 1;
4300 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004301
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004302 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004303 err =
4304 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004305 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004306
Tony Barboureb254902015-07-15 12:50:33 -06004307 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004308 dsl_binding.binding = 0;
4309 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4310 dsl_binding.descriptorCount = 1;
4311 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4312 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004313
Tony Barboureb254902015-07-15 12:50:33 -06004314 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004315 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4316 ds_layout_ci.pNext = NULL;
4317 ds_layout_ci.bindingCount = 1;
4318 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004319 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4321 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004322 ASSERT_VK_SUCCESS(err);
4323
4324 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004325 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004327 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004328 alloc_info.descriptorPool = ds_pool;
4329 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004330 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4331 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004332 ASSERT_VK_SUCCESS(err);
4333
Tony Barboureb254902015-07-15 12:50:33 -06004334 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004335 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4336 pipeline_layout_ci.pNext = NULL;
4337 pipeline_layout_ci.setLayoutCount = 1;
4338 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004339
4340 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004341 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4342 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004343 ASSERT_VK_SUCCESS(err);
4344
Karl Schultz6addd812016-02-02 17:17:23 -07004345 VkShaderObj vs(m_device, bindStateVertShaderText,
4346 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06004347 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07004348 // on more devices
4349 VkShaderObj fs(m_device, bindStateFragShaderText,
4350 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004351
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004352 VkPipelineObj pipe(m_device);
4353 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06004354 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06004355 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06004356 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06004357
4358 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004359 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4360 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4361 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4362 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4363 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004364
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004365 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004366
Chia-I Wuf7458c52015-10-26 21:10:41 +08004367 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4368 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4369 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004370}
4371
Karl Schultz6addd812016-02-02 17:17:23 -07004372TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004373 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07004374 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004375
Karl Schultz6addd812016-02-02 17:17:23 -07004376 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004377 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
4378 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004379
4380 ASSERT_NO_FATAL_FAILURE(InitState());
4381 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4383 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004384
4385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4387 ds_pool_ci.pNext = NULL;
4388 ds_pool_ci.maxSets = 1;
4389 ds_pool_ci.poolSizeCount = 1;
4390 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004391
4392 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004393 err =
4394 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004395 ASSERT_VK_SUCCESS(err);
4396
4397 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004398 dsl_binding.binding = 0;
4399 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4400 dsl_binding.descriptorCount = 1;
4401 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4402 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004403
4404 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004405 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4406 ds_layout_ci.pNext = NULL;
4407 ds_layout_ci.bindingCount = 1;
4408 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004409 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4411 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004412 ASSERT_VK_SUCCESS(err);
4413
4414 VkDescriptorSet descriptorSet;
4415 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004416 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004417 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004418 alloc_info.descriptorPool = ds_pool;
4419 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004420 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4421 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004422 ASSERT_VK_SUCCESS(err);
4423
Karl Schultz6addd812016-02-02 17:17:23 -07004424 VkBufferView view =
4425 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004426 VkWriteDescriptorSet descriptor_write;
4427 memset(&descriptor_write, 0, sizeof(descriptor_write));
4428 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4429 descriptor_write.dstSet = descriptorSet;
4430 descriptor_write.dstBinding = 0;
4431 descriptor_write.descriptorCount = 1;
4432 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
4433 descriptor_write.pTexelBufferView = &view;
4434
4435 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4436
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004437 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07004438
4439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4441}
4442
Karl Schultz6addd812016-02-02 17:17:23 -07004443TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
4444 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
4445 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07004446 // 1. No dynamicOffset supplied
4447 // 2. Too many dynamicOffsets supplied
4448 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07004449 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004451 " requires 1 dynamicOffsets, but only "
4452 "0 dynamicOffsets are left in "
4453 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004454
4455 ASSERT_NO_FATAL_FAILURE(InitState());
4456 ASSERT_NO_FATAL_FAILURE(InitViewport());
4457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4458
4459 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004460 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4461 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004462
4463 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004464 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4465 ds_pool_ci.pNext = NULL;
4466 ds_pool_ci.maxSets = 1;
4467 ds_pool_ci.poolSizeCount = 1;
4468 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004469
4470 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004471 err =
4472 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004473 ASSERT_VK_SUCCESS(err);
4474
4475 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004476 dsl_binding.binding = 0;
4477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4478 dsl_binding.descriptorCount = 1;
4479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4480 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004481
4482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4484 ds_layout_ci.pNext = NULL;
4485 ds_layout_ci.bindingCount = 1;
4486 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004487 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004488 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4489 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004490 ASSERT_VK_SUCCESS(err);
4491
4492 VkDescriptorSet descriptorSet;
4493 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004494 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004495 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004496 alloc_info.descriptorPool = ds_pool;
4497 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004498 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4499 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004500 ASSERT_VK_SUCCESS(err);
4501
4502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4504 pipeline_layout_ci.pNext = NULL;
4505 pipeline_layout_ci.setLayoutCount = 1;
4506 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004507
4508 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004509 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4510 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004511 ASSERT_VK_SUCCESS(err);
4512
4513 // Create a buffer to update the descriptor with
4514 uint32_t qfi = 0;
4515 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004516 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4517 buffCI.size = 1024;
4518 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4519 buffCI.queueFamilyIndexCount = 1;
4520 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004521
4522 VkBuffer dyub;
4523 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4524 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004525 // Allocate memory and bind to buffer so we can make it to the appropriate
4526 // error
4527 VkMemoryAllocateInfo mem_alloc = {};
4528 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4529 mem_alloc.pNext = NULL;
4530 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12004531 mem_alloc.memoryTypeIndex = 0;
4532
4533 VkMemoryRequirements memReqs;
4534 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
4535 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
4536 0);
4537 if (!pass) {
4538 vkDestroyBuffer(m_device->device(), dyub, NULL);
4539 return;
4540 }
4541
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004542 VkDeviceMemory mem;
4543 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4544 ASSERT_VK_SUCCESS(err);
4545 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4546 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004547 // Correctly update descriptor to avoid "NOT_UPDATED" error
4548 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004549 buffInfo.buffer = dyub;
4550 buffInfo.offset = 0;
4551 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004552
4553 VkWriteDescriptorSet descriptor_write;
4554 memset(&descriptor_write, 0, sizeof(descriptor_write));
4555 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4556 descriptor_write.dstSet = descriptorSet;
4557 descriptor_write.dstBinding = 0;
4558 descriptor_write.descriptorCount = 1;
4559 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
4560 descriptor_write.pBufferInfo = &buffInfo;
4561
4562 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4563
4564 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004565 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4566 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4567 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004568 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004569 uint32_t pDynOff[2] = {512, 756};
4570 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07004571 m_errorMonitor->SetDesiredFailureMsg(
4572 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07004573 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07004574 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4575 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4576 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12004577 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07004578 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4580 " dynamic offset 512 combined with "
4581 "offset 0 and range 1024 that "
4582 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07004583 // Create PSO to be used for draw-time errors below
4584 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004585 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004586 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07004587 "out gl_PerVertex { \n"
4588 " vec4 gl_Position;\n"
4589 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004590 "void main(){\n"
4591 " gl_Position = vec4(1);\n"
4592 "}\n";
4593 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12004594 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07004595 "\n"
4596 "layout(location=0) out vec4 x;\n"
4597 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4598 "void main(){\n"
4599 " x = vec4(bar.y);\n"
4600 "}\n";
4601 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4602 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4603 VkPipelineObj pipe(m_device);
4604 pipe.AddShader(&vs);
4605 pipe.AddShader(&fs);
4606 pipe.AddColorAttachment();
4607 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4608
Karl Schultz6addd812016-02-02 17:17:23 -07004609 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4610 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4611 // This update should succeed, but offset size of 512 will overstep buffer
4612 // /w range 1024 & size 1024
4613 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4614 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4615 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004616 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004617 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004618
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004619 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06004620 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06004621
Tobin Ehlis49f903e2015-11-04 13:30:34 -07004622 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4623 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4624}
4625
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004626TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004627 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004628 ASSERT_NO_FATAL_FAILURE(InitState());
4629 ASSERT_NO_FATAL_FAILURE(InitViewport());
4630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4631
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004632 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004633 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004634 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4635 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4636 pipeline_layout_ci.pushConstantRangeCount = 1;
4637 pipeline_layout_ci.pPushConstantRanges = &pc_range;
4638
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004639 //
4640 // Check for invalid push constant ranges in pipeline layouts.
4641 //
4642 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004643 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004644 char const *msg;
4645 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004646
Karl Schultzc81037d2016-05-12 08:11:23 -06004647 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
4648 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
4649 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4650 "vkCreatePipelineLayout() call has push constants index 0 with "
4651 "size 0."},
4652 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4653 "vkCreatePipelineLayout() call has push constants index 0 with "
4654 "size 1."},
4655 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4656 "vkCreatePipelineLayout() call has push constants index 0 with "
4657 "size 1."},
4658 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4659 "vkCreatePipelineLayout() call has push constants index 0 with "
4660 "size 0."},
4661 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4662 "vkCreatePipelineLayout() call has push constants index 0 with "
4663 "offset 1. Offset must"},
4664 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
4665 "vkCreatePipelineLayout() call has push constants index 0 "
4666 "with offset "},
4667 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
4668 "vkCreatePipelineLayout() call has push constants "
4669 "index 0 with offset "},
4670 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
4671 "vkCreatePipelineLayout() call has push constants index 0 "
4672 "with offset "},
4673 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
4674 "vkCreatePipelineLayout() call has push "
4675 "constants index 0 with offset "},
4676 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
4677 "vkCreatePipelineLayout() call has push "
4678 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004679 }};
4680
4681 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06004682 for (const auto &iter : range_tests) {
4683 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4685 iter.msg);
4686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4687 NULL, &pipeline_layout);
4688 m_errorMonitor->VerifyFound();
4689 if (VK_SUCCESS == err) {
4690 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4691 }
4692 }
4693
4694 // Check for invalid stage flag
4695 pc_range.offset = 0;
4696 pc_range.size = 16;
4697 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004698 m_errorMonitor->SetDesiredFailureMsg(
4699 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004700 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004701 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4702 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004703 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004704 if (VK_SUCCESS == err) {
4705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4706 }
4707
4708 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06004709 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004710 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06004711 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004712 char const *msg;
4713 };
4714
Karl Schultzc81037d2016-05-12 08:11:23 -06004715 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004716 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4717 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4718 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4719 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4720 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4721 "vkCreatePipelineLayout() call has push constants with overlapping "
4722 "ranges: 0:[0, 4), 1:[0, 4)"},
4723 {
4724 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4725 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4726 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4727 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4728 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4729 "vkCreatePipelineLayout() call has push constants with "
4730 "overlapping "
4731 "ranges: 3:[12, 20), 4:[16, 20)",
4732 },
4733 {
4734 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4735 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4736 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4737 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4738 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4739 "vkCreatePipelineLayout() call has push constants with "
4740 "overlapping "
4741 "ranges: 0:[16, 20), 1:[12, 20)",
4742 },
4743 {
4744 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4745 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4746 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4747 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
4748 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4749 "vkCreatePipelineLayout() call has push constants with "
4750 "overlapping "
4751 "ranges: 0:[16, 20), 3:[12, 20)",
4752 },
4753 {
4754 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4755 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
4756 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
4757 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
4758 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
4759 "vkCreatePipelineLayout() call has push constants with "
4760 "overlapping "
4761 "ranges: 0:[16, 20), 2:[4, 100)",
4762 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004763
Karl Schultzc81037d2016-05-12 08:11:23 -06004764 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004765 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06004766 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
4767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004768 iter.msg);
4769 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4770 NULL, &pipeline_layout);
4771 m_errorMonitor->VerifyFound();
4772 if (VK_SUCCESS == err) {
4773 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4774 }
4775 }
4776
4777 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06004778 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
4779 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4780 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
4781 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
4782 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
4783 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
4784 ""},
4785 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
4786 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
4787 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
4788 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
4789 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
4790 ""}}};
4791 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004792 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
4793 m_errorMonitor->ExpectSuccess();
4794 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
4795 NULL, &pipeline_layout);
4796 m_errorMonitor->VerifyNotFound();
4797 if (VK_SUCCESS == err) {
4798 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4799 }
4800 }
4801
4802 //
4803 // CmdPushConstants tests
4804 //
Karl Schultzc81037d2016-05-12 08:11:23 -06004805 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004806
4807 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06004808 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
4809 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
4810 "vkCmdPushConstants() call has push constants with size 0. Size "
4811 "must be greater than zero and a multiple of 4."},
4812 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
4813 "vkCmdPushConstants() call has push constants with size 1. Size "
4814 "must be greater than zero and a multiple of 4."},
4815 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
4816 "vkCmdPushConstants() call has push constants with size 1. Size "
4817 "must be greater than zero and a multiple of 4."},
4818 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
4819 "vkCmdPushConstants() call has push constants with offset 1. "
4820 "Offset must be a multiple of 4."},
4821 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
4822 "vkCmdPushConstants() call has push constants with offset 1. "
4823 "Offset must be a multiple of 4."},
4824 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4825 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4826 "0x1 not within flag-matching ranges in pipeline layout"},
4827 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
4828 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
4829 "0x1 not within flag-matching ranges in pipeline layout"},
4830 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
4831 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
4832 "0x1 not within flag-matching ranges in pipeline layout"},
4833 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
4834 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
4835 "0x1 not within flag-matching ranges in pipeline layout"},
4836 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
4837 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
4838 "any of the ranges in pipeline layout"},
4839 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4840 0, 16},
4841 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
4842 "any of the ranges in pipeline layout"},
4843 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004844 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004845 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004846 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004847 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004848 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004849 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004850 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06004851 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004852 "vkCmdPushConstants() call has push constants with offset "},
4853 }};
4854
4855 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06004856 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004857 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06004858 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004859 };
Karl Schultzc81037d2016-05-12 08:11:23 -06004860 pipeline_layout_ci.pushConstantRangeCount =
4861 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004862 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004863 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4864 &pipeline_layout);
4865 ASSERT_VK_SUCCESS(err);
4866 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06004867 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4869 iter.msg);
4870 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06004871 iter.range.stageFlags, iter.range.offset,
4872 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004873 m_errorMonitor->VerifyFound();
4874 }
4875
4876 // Check for invalid stage flag
4877 m_errorMonitor->SetDesiredFailureMsg(
4878 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4879 "vkCmdPushConstants() call has no stageFlags set.");
4880 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06004881 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004882 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06004883 EndCommandBuffer();
4884 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4885 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06004886
Karl Schultzc81037d2016-05-12 08:11:23 -06004887 // overlapping range tests with cmd
4888 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
4889 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
4890 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
4891 "0x1 not within flag-matching ranges in pipeline layout"},
4892 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
4893 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
4894 "0x1 not within flag-matching ranges in pipeline layout"},
4895 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
4896 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
4897 "0x1 not within flag-matching ranges in pipeline layout"},
4898 }};
4899 const VkPushConstantRange pc_range3[] = {
4900 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4901 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4902 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4903 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4904 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4905 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4906 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4907 };
4908 pipeline_layout_ci.pushConstantRangeCount =
4909 sizeof(pc_range3) / sizeof(VkPushConstantRange);
4910 pipeline_layout_ci.pPushConstantRanges = pc_range3;
4911 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4912 &pipeline_layout);
4913 ASSERT_VK_SUCCESS(err);
4914 BeginCommandBuffer();
4915 for (const auto &iter : cmd_overlap_tests) {
4916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4917 iter.msg);
4918 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4919 iter.range.stageFlags, iter.range.offset,
4920 iter.range.size, dummy_values);
4921 m_errorMonitor->VerifyFound();
4922 }
4923 EndCommandBuffer();
4924 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
4925 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4926
4927 // positive overlapping range tests with cmd
4928 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
4929 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
4930 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
4931 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
4932 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
4933 }};
4934 const VkPushConstantRange pc_range4[] = {
4935 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
4936 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
4937 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
4938 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
4939 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
4940 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
4941 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
4942 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
4943 };
4944 pipeline_layout_ci.pushConstantRangeCount =
4945 sizeof(pc_range4) / sizeof(VkPushConstantRange);
4946 pipeline_layout_ci.pPushConstantRanges = pc_range4;
4947 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4948 &pipeline_layout);
4949 ASSERT_VK_SUCCESS(err);
4950 BeginCommandBuffer();
4951 for (const auto &iter : cmd_overlap_tests_pos) {
4952 m_errorMonitor->ExpectSuccess();
4953 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
4954 iter.range.stageFlags, iter.range.offset,
4955 iter.range.size, dummy_values);
4956 m_errorMonitor->VerifyNotFound();
4957 }
4958 EndCommandBuffer();
4959 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07004960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4961}
4962
Karl Schultz6addd812016-02-02 17:17:23 -07004963TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07004964 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07004965 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004966
4967 ASSERT_NO_FATAL_FAILURE(InitState());
4968 ASSERT_NO_FATAL_FAILURE(InitViewport());
4969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4970
4971 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
4972 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004973 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4974 ds_type_count[0].descriptorCount = 10;
4975 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
4976 ds_type_count[1].descriptorCount = 2;
4977 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
4978 ds_type_count[2].descriptorCount = 2;
4979 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
4980 ds_type_count[3].descriptorCount = 5;
4981 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
4982 // type
4983 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4984 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4985 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004986
4987 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004988 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4989 ds_pool_ci.pNext = NULL;
4990 ds_pool_ci.maxSets = 5;
4991 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
4992 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07004993
4994 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004995 err =
4996 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004997 ASSERT_VK_SUCCESS(err);
4998
4999 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5000 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005001 dsl_binding[0].binding = 0;
5002 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5003 dsl_binding[0].descriptorCount = 5;
5004 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5005 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005006
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005007 // Create layout identical to set0 layout but w/ different stageFlags
5008 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005009 dsl_fs_stage_only.binding = 0;
5010 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5011 dsl_fs_stage_only.descriptorCount = 5;
5012 dsl_fs_stage_only.stageFlags =
5013 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5014 // bind time
5015 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005017 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5018 ds_layout_ci.pNext = NULL;
5019 ds_layout_ci.bindingCount = 1;
5020 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005021 static const uint32_t NUM_LAYOUTS = 4;
5022 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005023 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005024 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5025 // layout for error case
5026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5027 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005028 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005029 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5031 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005032 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005033 dsl_binding[0].binding = 0;
5034 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005035 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005036 dsl_binding[1].binding = 1;
5037 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5038 dsl_binding[1].descriptorCount = 2;
5039 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5040 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005041 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005042 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5044 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005045 ASSERT_VK_SUCCESS(err);
5046 dsl_binding[0].binding = 0;
5047 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005048 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005049 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005050 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5051 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005052 ASSERT_VK_SUCCESS(err);
5053 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005054 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5056 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005057 ASSERT_VK_SUCCESS(err);
5058
5059 static const uint32_t NUM_SETS = 4;
5060 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5061 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005062 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005063 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005064 alloc_info.descriptorPool = ds_pool;
5065 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005066 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5067 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005068 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005069 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005070 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005071 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005072 err =
5073 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005074 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005075
5076 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005077 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5078 pipeline_layout_ci.pNext = NULL;
5079 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5080 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005081
5082 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005083 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5084 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005086 // Create pipelineLayout with only one setLayout
5087 pipeline_layout_ci.setLayoutCount = 1;
5088 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005089 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5090 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005091 ASSERT_VK_SUCCESS(err);
5092 // Create pipelineLayout with 2 descriptor setLayout at index 0
5093 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5094 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5096 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005097 ASSERT_VK_SUCCESS(err);
5098 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5099 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5100 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5102 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005103 ASSERT_VK_SUCCESS(err);
5104 // Create pipelineLayout with UB type, but stageFlags for FS only
5105 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5106 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005107 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5108 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005109 ASSERT_VK_SUCCESS(err);
5110 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5111 VkDescriptorSetLayout pl_bad_s0[2] = {};
5112 pl_bad_s0[0] = ds_layout_fs_only;
5113 pl_bad_s0[1] = ds_layout[1];
5114 pipeline_layout_ci.setLayoutCount = 2;
5115 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5116 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005117 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5118 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005120
5121 // Create a buffer to update the descriptor with
5122 uint32_t qfi = 0;
5123 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005124 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5125 buffCI.size = 1024;
5126 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5127 buffCI.queueFamilyIndexCount = 1;
5128 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005129
5130 VkBuffer dyub;
5131 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5132 ASSERT_VK_SUCCESS(err);
5133 // Correctly update descriptor to avoid "NOT_UPDATED" error
5134 static const uint32_t NUM_BUFFS = 5;
5135 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005136 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005137 buffInfo[i].buffer = dyub;
5138 buffInfo[i].offset = 0;
5139 buffInfo[i].range = 1024;
5140 }
Karl Schultz6addd812016-02-02 17:17:23 -07005141 VkImage image;
5142 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5143 const int32_t tex_width = 32;
5144 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005145 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005146 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5147 image_create_info.pNext = NULL;
5148 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5149 image_create_info.format = tex_format;
5150 image_create_info.extent.width = tex_width;
5151 image_create_info.extent.height = tex_height;
5152 image_create_info.extent.depth = 1;
5153 image_create_info.mipLevels = 1;
5154 image_create_info.arrayLayers = 1;
5155 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5156 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5157 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5158 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005159 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5160 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005161
Karl Schultz6addd812016-02-02 17:17:23 -07005162 VkMemoryRequirements memReqs;
5163 VkDeviceMemory imageMem;
5164 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005165 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005166 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5167 memAlloc.pNext = NULL;
5168 memAlloc.allocationSize = 0;
5169 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005170 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5171 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005172 pass =
5173 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005174 ASSERT_TRUE(pass);
5175 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5176 ASSERT_VK_SUCCESS(err);
5177 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5178 ASSERT_VK_SUCCESS(err);
5179
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005180 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005181 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5182 image_view_create_info.image = image;
5183 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5184 image_view_create_info.format = tex_format;
5185 image_view_create_info.subresourceRange.layerCount = 1;
5186 image_view_create_info.subresourceRange.baseMipLevel = 0;
5187 image_view_create_info.subresourceRange.levelCount = 1;
5188 image_view_create_info.subresourceRange.aspectMask =
5189 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005190
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005191 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005192 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5193 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005194 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005195 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005196 imageInfo[0].imageView = view;
5197 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5198 imageInfo[1].imageView = view;
5199 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005200 imageInfo[2].imageView = view;
5201 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5202 imageInfo[3].imageView = view;
5203 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005204
5205 static const uint32_t NUM_SET_UPDATES = 3;
5206 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5207 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5208 descriptor_write[0].dstSet = descriptorSet[0];
5209 descriptor_write[0].dstBinding = 0;
5210 descriptor_write[0].descriptorCount = 5;
5211 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5212 descriptor_write[0].pBufferInfo = buffInfo;
5213 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5214 descriptor_write[1].dstSet = descriptorSet[1];
5215 descriptor_write[1].dstBinding = 0;
5216 descriptor_write[1].descriptorCount = 2;
5217 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5218 descriptor_write[1].pImageInfo = imageInfo;
5219 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5220 descriptor_write[2].dstSet = descriptorSet[1];
5221 descriptor_write[2].dstBinding = 1;
5222 descriptor_write[2].descriptorCount = 2;
5223 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005224 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005225
5226 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005227
Tobin Ehlis88452832015-12-03 09:40:56 -07005228 // Create PSO to be used for draw-time errors below
5229 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005230 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005231 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005232 "out gl_PerVertex {\n"
5233 " vec4 gl_Position;\n"
5234 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005235 "void main(){\n"
5236 " gl_Position = vec4(1);\n"
5237 "}\n";
5238 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005239 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005240 "\n"
5241 "layout(location=0) out vec4 x;\n"
5242 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5243 "void main(){\n"
5244 " x = vec4(bar.y);\n"
5245 "}\n";
5246 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5247 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005248 VkPipelineObj pipe(m_device);
5249 pipe.AddShader(&vs);
5250 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005251 pipe.AddColorAttachment();
5252 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005253
5254 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005255
Karl Schultz6addd812016-02-02 17:17:23 -07005256 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5257 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5258 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5259 // of PSO
5260 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5261 // cmd_pipeline.c
5262 // due to the fact that cmd_alloc_dset_data() has not been called in
5263 // cmd_bind_graphics_pipeline()
5264 // TODO : Want to cause various binding incompatibility issues here to test
5265 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005266 // First cause various verify_layout_compatibility() fails
5267 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005268 // verify_set_layout_compatibility fail cases:
5269 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5271 " due to: invalid VkPipelineLayout ");
5272 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5273 VK_PIPELINE_BIND_POINT_GRAPHICS,
5274 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5275 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005276 m_errorMonitor->VerifyFound();
5277
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005278 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5280 " attempting to bind set to index 1");
5281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5282 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5283 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005284 m_errorMonitor->VerifyFound();
5285
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005286 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005287 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5288 // descriptors
5289 m_errorMonitor->SetDesiredFailureMsg(
5290 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005291 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005292 vkCmdBindDescriptorSets(
5293 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5294 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005295 m_errorMonitor->VerifyFound();
5296
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005297 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5298 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005299 m_errorMonitor->SetDesiredFailureMsg(
5300 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005301 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005302 vkCmdBindDescriptorSets(
5303 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5304 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005305 m_errorMonitor->VerifyFound();
5306
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005307 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5308 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005309 m_errorMonitor->SetDesiredFailureMsg(
5310 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005311 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005312 vkCmdBindDescriptorSets(
5313 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5314 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005315 m_errorMonitor->VerifyFound();
5316
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005317 // Cause INFO messages due to disturbing previously bound Sets
5318 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07005319 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5320 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5321 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005322 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07005323 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005324 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005325 " previously bound as set #0 was disturbed ");
5326 vkCmdBindDescriptorSets(
5327 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5328 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005329 m_errorMonitor->VerifyFound();
5330
Karl Schultz6addd812016-02-02 17:17:23 -07005331 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5332 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5333 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005334 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07005335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005336 " newly bound as set #0 so set #1 and "
5337 "any subsequent sets were disturbed ");
5338 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5339 VK_PIPELINE_BIND_POINT_GRAPHICS,
5340 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005341 m_errorMonitor->VerifyFound();
5342
Tobin Ehlis88452832015-12-03 09:40:56 -07005343 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07005344 // 1. Error due to not binding required set (we actually use same code as
5345 // above to disturb set0)
5346 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5347 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5348 2, &descriptorSet[0], 0, NULL);
5349 vkCmdBindDescriptorSets(
5350 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5351 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
5352 m_errorMonitor->SetDesiredFailureMsg(
5353 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5354 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07005355 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005356 m_errorMonitor->VerifyFound();
5357
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005358 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005359 // 2. Error due to bound set not being compatible with PSO's
5360 // VkPipelineLayout (diff stageFlags in this case)
5361 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5362 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5363 2, &descriptorSet[0], 0, NULL);
5364 m_errorMonitor->SetDesiredFailureMsg(
5365 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5366 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07005367 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005368 m_errorMonitor->VerifyFound();
5369
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005370 // Remaining clean-up
5371 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005372 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005373 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
5374 }
5375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06005376 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
5377 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005378 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005379 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5381}
Tobin Ehlis559c6382015-11-05 09:52:49 -07005382
Karl Schultz6addd812016-02-02 17:17:23 -07005383TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005384
Karl Schultz6addd812016-02-02 17:17:23 -07005385 m_errorMonitor->SetDesiredFailureMsg(
5386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005387 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005388
5389 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005390 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005391 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005392 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005393
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005394 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005395}
5396
Karl Schultz6addd812016-02-02 17:17:23 -07005397TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
5398 VkResult err;
5399 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005400
Karl Schultz6addd812016-02-02 17:17:23 -07005401 m_errorMonitor->SetDesiredFailureMsg(
5402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005403 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005404
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005405 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005406
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005407 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005408 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005409 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005410 cmd.commandPool = m_commandPool;
5411 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005412 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06005413
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005414 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06005415 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005416
5417 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005418 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005419 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005420 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06005421 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07005422 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
5423 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005424 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005425
5426 // The error should be caught by validation of the BeginCommandBuffer call
5427 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
5428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005429 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005430 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06005431}
5432
Karl Schultz6addd812016-02-02 17:17:23 -07005433TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005434 // Cause error due to Begin while recording CB
5435 // Then cause 2 errors for attempting to reset CB w/o having
5436 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
5437 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005439 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005440
5441 ASSERT_NO_FATAL_FAILURE(InitState());
5442
5443 // Calls AllocateCommandBuffers
5444 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
5445
Karl Schultz6addd812016-02-02 17:17:23 -07005446 // Force the failure by setting the Renderpass and Framebuffer fields with
5447 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005448 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005449 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005450 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5451 cmd_buf_info.pNext = NULL;
5452 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005453 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005454
5455 // Begin CB to transition to recording state
5456 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
5457 // Can't re-begin. This should trigger error
5458 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005459 m_errorMonitor->VerifyFound();
5460
Karl Schultz6addd812016-02-02 17:17:23 -07005461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5462 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005463 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
5464 // Reset attempt will trigger error due to incorrect CommandPool state
5465 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005466 m_errorMonitor->VerifyFound();
5467
Karl Schultz6addd812016-02-02 17:17:23 -07005468 m_errorMonitor->SetDesiredFailureMsg(
5469 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5470 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005471 // Transition CB to RECORDED state
5472 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
5473 // Now attempting to Begin will implicitly reset, which triggers error
5474 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005475 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07005476}
5477
Karl Schultz6addd812016-02-02 17:17:23 -07005478TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005479 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005480 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005481
Karl Schultz6addd812016-02-02 17:17:23 -07005482 m_errorMonitor->SetDesiredFailureMsg(
5483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005484 "Invalid Pipeline CreateInfo State: Vtx Shader required");
5485
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005486 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06005487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005488
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005489 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005490 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5491 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005492
5493 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005494 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5495 ds_pool_ci.pNext = NULL;
5496 ds_pool_ci.maxSets = 1;
5497 ds_pool_ci.poolSizeCount = 1;
5498 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005499
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005500 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005501 err =
5502 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005503 ASSERT_VK_SUCCESS(err);
5504
Tony Barboureb254902015-07-15 12:50:33 -06005505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005506 dsl_binding.binding = 0;
5507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5508 dsl_binding.descriptorCount = 1;
5509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5510 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005511
Tony Barboureb254902015-07-15 12:50:33 -06005512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5514 ds_layout_ci.pNext = NULL;
5515 ds_layout_ci.bindingCount = 1;
5516 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005517
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005518 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005519 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5520 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005521 ASSERT_VK_SUCCESS(err);
5522
5523 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005524 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005525 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005526 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005527 alloc_info.descriptorPool = ds_pool;
5528 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005529 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5530 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005531 ASSERT_VK_SUCCESS(err);
5532
Tony Barboureb254902015-07-15 12:50:33 -06005533 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005534 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5535 pipeline_layout_ci.setLayoutCount = 1;
5536 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005537
5538 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005539 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5540 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005541 ASSERT_VK_SUCCESS(err);
5542
Tobin Ehlise68360f2015-10-01 11:15:13 -06005543 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07005544 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06005545
5546 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005547 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5548 vp_state_ci.scissorCount = 1;
5549 vp_state_ci.pScissors = &sc;
5550 vp_state_ci.viewportCount = 1;
5551 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005552
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005553 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5554 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5555 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5556 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5557 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5558 rs_state_ci.depthClampEnable = VK_FALSE;
5559 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5560 rs_state_ci.depthBiasEnable = VK_FALSE;
5561
Tony Barboureb254902015-07-15 12:50:33 -06005562 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005563 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5564 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005565 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005566 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5567 gp_ci.layout = pipeline_layout;
5568 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06005569
5570 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005571 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5572 pc_ci.initialDataSize = 0;
5573 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005574
5575 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06005576 VkPipelineCache pipelineCache;
5577
Karl Schultz6addd812016-02-02 17:17:23 -07005578 err =
5579 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06005580 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005581 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5582 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005583
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005584 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005585
Chia-I Wuf7458c52015-10-26 21:10:41 +08005586 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5587 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5588 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5589 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005590}
Tobin Ehlis912df022015-09-17 08:46:18 -06005591/*// TODO : This test should be good, but needs Tess support in compiler to run
5592TEST_F(VkLayerTest, InvalidPatchControlPoints)
5593{
5594 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06005595 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005596
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005598 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
5599primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005600
Tobin Ehlis912df022015-09-17 08:46:18 -06005601 ASSERT_NO_FATAL_FAILURE(InitState());
5602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06005603
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005604 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06005605 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005606 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005607
5608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5610 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005611 ds_pool_ci.poolSizeCount = 1;
5612 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06005613
5614 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005615 err = vkCreateDescriptorPool(m_device->device(),
5616VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06005617 ASSERT_VK_SUCCESS(err);
5618
5619 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08005620 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06005621 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08005622 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005623 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5624 dsl_binding.pImmutableSamplers = NULL;
5625
5626 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005627 ds_layout_ci.sType =
5628VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005629 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005630 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005631 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06005632
5633 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5635&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005636 ASSERT_VK_SUCCESS(err);
5637
5638 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005639 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
5640VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06005641 ASSERT_VK_SUCCESS(err);
5642
5643 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005644 pipeline_layout_ci.sType =
5645VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06005646 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005647 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06005648 pipeline_layout_ci.pSetLayouts = &ds_layout;
5649
5650 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5652&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06005653 ASSERT_VK_SUCCESS(err);
5654
5655 VkPipelineShaderStageCreateInfo shaderStages[3];
5656 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
5657
Karl Schultz6addd812016-02-02 17:17:23 -07005658 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
5659this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005660 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07005661 VkShaderObj
5662tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5663this);
5664 VkShaderObj
5665te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
5666this);
Tobin Ehlis912df022015-09-17 08:46:18 -06005667
Karl Schultz6addd812016-02-02 17:17:23 -07005668 shaderStages[0].sType =
5669VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005670 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005671 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005672 shaderStages[1].sType =
5673VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005674 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005675 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07005676 shaderStages[2].sType =
5677VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06005678 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06005679 shaderStages[2].shader = te.handle();
5680
5681 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005682 iaCI.sType =
5683VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08005684 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06005685
5686 VkPipelineTessellationStateCreateInfo tsCI = {};
5687 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
5688 tsCI.patchControlPoints = 0; // This will cause an error
5689
5690 VkGraphicsPipelineCreateInfo gp_ci = {};
5691 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5692 gp_ci.pNext = NULL;
5693 gp_ci.stageCount = 3;
5694 gp_ci.pStages = shaderStages;
5695 gp_ci.pVertexInputState = NULL;
5696 gp_ci.pInputAssemblyState = &iaCI;
5697 gp_ci.pTessellationState = &tsCI;
5698 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005699 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06005700 gp_ci.pMultisampleState = NULL;
5701 gp_ci.pDepthStencilState = NULL;
5702 gp_ci.pColorBlendState = NULL;
5703 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5704 gp_ci.layout = pipeline_layout;
5705 gp_ci.renderPass = renderPass();
5706
5707 VkPipelineCacheCreateInfo pc_ci = {};
5708 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5709 pc_ci.pNext = NULL;
5710 pc_ci.initialSize = 0;
5711 pc_ci.initialData = 0;
5712 pc_ci.maxSize = 0;
5713
5714 VkPipeline pipeline;
5715 VkPipelineCache pipelineCache;
5716
Karl Schultz6addd812016-02-02 17:17:23 -07005717 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
5718&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06005719 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005720 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5721&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06005722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005723 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005724
Chia-I Wuf7458c52015-10-26 21:10:41 +08005725 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5726 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5727 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5728 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06005729}
5730*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06005731// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07005732TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07005733 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005734
Karl Schultz6addd812016-02-02 17:17:23 -07005735 m_errorMonitor->SetDesiredFailureMsg(
5736 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005737 "Gfx Pipeline viewport count (1) must match scissor count (0).");
5738
Tobin Ehlise68360f2015-10-01 11:15:13 -06005739 ASSERT_NO_FATAL_FAILURE(InitState());
5740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005741
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005742 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005743 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5744 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005745
5746 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005747 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5748 ds_pool_ci.maxSets = 1;
5749 ds_pool_ci.poolSizeCount = 1;
5750 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005751
5752 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005753 err =
5754 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005755 ASSERT_VK_SUCCESS(err);
5756
5757 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005758 dsl_binding.binding = 0;
5759 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5760 dsl_binding.descriptorCount = 1;
5761 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005762
5763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5765 ds_layout_ci.bindingCount = 1;
5766 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005767
5768 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5770 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005771 ASSERT_VK_SUCCESS(err);
5772
5773 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005774 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005775 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005776 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005777 alloc_info.descriptorPool = ds_pool;
5778 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005779 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5780 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005781 ASSERT_VK_SUCCESS(err);
5782
5783 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005784 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5785 pipeline_layout_ci.setLayoutCount = 1;
5786 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005787
5788 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005789 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5790 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005791 ASSERT_VK_SUCCESS(err);
5792
5793 VkViewport vp = {}; // Just need dummy vp to point to
5794
5795 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005796 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5797 vp_state_ci.scissorCount = 0;
5798 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
5799 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005800
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005801 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5802 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5803 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5804 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5805 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5806 rs_state_ci.depthClampEnable = VK_FALSE;
5807 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5808 rs_state_ci.depthBiasEnable = VK_FALSE;
5809
Cody Northropeb3a6c12015-10-05 14:44:45 -06005810 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005811 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005812
Karl Schultz6addd812016-02-02 17:17:23 -07005813 VkShaderObj vs(m_device, bindStateVertShaderText,
5814 VK_SHADER_STAGE_VERTEX_BIT, this);
5815 VkShaderObj fs(m_device, bindStateFragShaderText,
5816 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005817 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005818 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005819 shaderStages[0] = vs.GetStageCreateInfo();
5820 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005821
5822 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005823 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5824 gp_ci.stageCount = 2;
5825 gp_ci.pStages = shaderStages;
5826 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005827 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005828 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5829 gp_ci.layout = pipeline_layout;
5830 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005831
5832 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005834
5835 VkPipeline pipeline;
5836 VkPipelineCache pipelineCache;
5837
Karl Schultz6addd812016-02-02 17:17:23 -07005838 err =
5839 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005840 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005841 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5842 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005843
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005844 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005845
Chia-I Wuf7458c52015-10-26 21:10:41 +08005846 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5847 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5848 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5849 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005850}
Karl Schultz6addd812016-02-02 17:17:23 -07005851// Don't set viewport state in PSO. This is an error b/c we always need this
5852// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06005853// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07005854TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06005855 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07005856 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005857
Karl Schultz6addd812016-02-02 17:17:23 -07005858 m_errorMonitor->SetDesiredFailureMsg(
5859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005860 "Gfx Pipeline pViewportState is null. Even if ");
5861
Tobin Ehlise68360f2015-10-01 11:15:13 -06005862 ASSERT_NO_FATAL_FAILURE(InitState());
5863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005864
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005865 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005866 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5867 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005868
5869 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005870 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5871 ds_pool_ci.maxSets = 1;
5872 ds_pool_ci.poolSizeCount = 1;
5873 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005874
5875 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005876 err =
5877 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005878 ASSERT_VK_SUCCESS(err);
5879
5880 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005881 dsl_binding.binding = 0;
5882 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5883 dsl_binding.descriptorCount = 1;
5884 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005885
5886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005887 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5888 ds_layout_ci.bindingCount = 1;
5889 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005890
5891 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005892 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5893 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005894 ASSERT_VK_SUCCESS(err);
5895
5896 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005897 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005898 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005899 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005900 alloc_info.descriptorPool = ds_pool;
5901 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005902 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5903 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005904 ASSERT_VK_SUCCESS(err);
5905
5906 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005907 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5908 pipeline_layout_ci.setLayoutCount = 1;
5909 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005910
5911 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005912 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5913 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005914 ASSERT_VK_SUCCESS(err);
5915
5916 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
5917 // Set scissor as dynamic to avoid second error
5918 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005919 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5920 dyn_state_ci.dynamicStateCount = 1;
5921 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005922
Cody Northropeb3a6c12015-10-05 14:44:45 -06005923 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07005924 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06005925
Karl Schultz6addd812016-02-02 17:17:23 -07005926 VkShaderObj vs(m_device, bindStateVertShaderText,
5927 VK_SHADER_STAGE_VERTEX_BIT, this);
5928 VkShaderObj fs(m_device, bindStateFragShaderText,
5929 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06005930 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07005931 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08005932 shaderStages[0] = vs.GetStageCreateInfo();
5933 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005934
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005935
5936 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
5937 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5938 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
5939 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
5940 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
5941 rs_state_ci.depthClampEnable = VK_FALSE;
5942 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
5943 rs_state_ci.depthBiasEnable = VK_FALSE;
5944
Tobin Ehlise68360f2015-10-01 11:15:13 -06005945 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005946 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5947 gp_ci.stageCount = 2;
5948 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07005949 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07005950 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
5951 // should cause validation error
5952 gp_ci.pDynamicState = &dyn_state_ci;
5953 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5954 gp_ci.layout = pipeline_layout;
5955 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005956
5957 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005958 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005959
5960 VkPipeline pipeline;
5961 VkPipelineCache pipelineCache;
5962
Karl Schultz6addd812016-02-02 17:17:23 -07005963 err =
5964 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005965 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005966 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5967 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005968
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005969 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06005970
Chia-I Wuf7458c52015-10-26 21:10:41 +08005971 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5972 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06005975}
5976// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07005977// Then run second test where dynamic scissor count doesn't match PSO scissor
5978// count
5979TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
5980 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005981
Karl Schultz6addd812016-02-02 17:17:23 -07005982 m_errorMonitor->SetDesiredFailureMsg(
5983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005984 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
5985
Tobin Ehlise68360f2015-10-01 11:15:13 -06005986 ASSERT_NO_FATAL_FAILURE(InitState());
5987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06005988
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005989 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005990 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5991 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005992
5993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5995 ds_pool_ci.maxSets = 1;
5996 ds_pool_ci.poolSizeCount = 1;
5997 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06005998
5999 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006000 err =
6001 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006002 ASSERT_VK_SUCCESS(err);
6003
6004 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006005 dsl_binding.binding = 0;
6006 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6007 dsl_binding.descriptorCount = 1;
6008 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006009
6010 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006011 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6012 ds_layout_ci.bindingCount = 1;
6013 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006014
6015 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6017 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006018 ASSERT_VK_SUCCESS(err);
6019
6020 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006021 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006023 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006024 alloc_info.descriptorPool = ds_pool;
6025 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6027 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006028 ASSERT_VK_SUCCESS(err);
6029
6030 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006031 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6032 pipeline_layout_ci.setLayoutCount = 1;
6033 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006034
6035 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6037 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006041 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6042 vp_state_ci.viewportCount = 1;
6043 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6044 vp_state_ci.scissorCount = 1;
6045 vp_state_ci.pScissors =
6046 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006047
6048 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6049 // Set scissor as dynamic to avoid that error
6050 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006051 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6052 dyn_state_ci.dynamicStateCount = 1;
6053 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006054
Cody Northropeb3a6c12015-10-05 14:44:45 -06006055 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006056 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006057
Karl Schultz6addd812016-02-02 17:17:23 -07006058 VkShaderObj vs(m_device, bindStateVertShaderText,
6059 VK_SHADER_STAGE_VERTEX_BIT, this);
6060 VkShaderObj fs(m_device, bindStateFragShaderText,
6061 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006062 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006063 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006064 shaderStages[0] = vs.GetStageCreateInfo();
6065 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006066
Cody Northropf6622dc2015-10-06 10:33:21 -06006067 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6068 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6069 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006070 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006071 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006072 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006073 vi_ci.pVertexAttributeDescriptions = nullptr;
6074
6075 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6076 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6077 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006079 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006080 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006081 rs_ci.pNext = nullptr;
6082
Mark Youngc89c6312016-03-31 16:03:20 -06006083 VkPipelineColorBlendAttachmentState att = {};
6084 att.blendEnable = VK_FALSE;
6085 att.colorWriteMask = 0xf;
6086
Cody Northropf6622dc2015-10-06 10:33:21 -06006087 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6088 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6089 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006090 cb_ci.attachmentCount = 1;
6091 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006092
Tobin Ehlise68360f2015-10-01 11:15:13 -06006093 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006094 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6095 gp_ci.stageCount = 2;
6096 gp_ci.pStages = shaderStages;
6097 gp_ci.pVertexInputState = &vi_ci;
6098 gp_ci.pInputAssemblyState = &ia_ci;
6099 gp_ci.pViewportState = &vp_state_ci;
6100 gp_ci.pRasterizationState = &rs_ci;
6101 gp_ci.pColorBlendState = &cb_ci;
6102 gp_ci.pDynamicState = &dyn_state_ci;
6103 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6104 gp_ci.layout = pipeline_layout;
6105 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006106
6107 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006108 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006109
6110 VkPipeline pipeline;
6111 VkPipelineCache pipelineCache;
6112
Karl Schultz6addd812016-02-02 17:17:23 -07006113 err =
6114 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006115 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006116 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6117 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006119 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006120
Tobin Ehlisd332f282015-10-02 11:00:56 -06006121 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006122 // First need to successfully create the PSO from above by setting
6123 // pViewports
6124 m_errorMonitor->SetDesiredFailureMsg(
6125 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6126 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6127 "scissorCount is 1. These counts must match.");
6128
6129 VkViewport vp = {}; // Just need dummy vp to point to
6130 vp_state_ci.pViewports = &vp;
6131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6132 &gp_ci, NULL, &pipeline);
6133 ASSERT_VK_SUCCESS(err);
6134 BeginCommandBuffer();
6135 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6136 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6137 VkRect2D scissors[2] = {}; // don't care about data
6138 // Count of 2 doesn't match PSO count of 1
6139 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6140 Draw(1, 0, 0, 0);
6141
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006142 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006143
6144 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6145 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6147 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6148}
6149// Create PSO w/o non-zero scissorCount but no scissor data
6150// Then run second test where dynamic viewportCount doesn't match PSO
6151// viewportCount
6152TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6153 VkResult err;
6154
6155 m_errorMonitor->SetDesiredFailureMsg(
6156 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6157 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6158
6159 ASSERT_NO_FATAL_FAILURE(InitState());
6160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6161
6162 VkDescriptorPoolSize ds_type_count = {};
6163 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6164 ds_type_count.descriptorCount = 1;
6165
6166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6168 ds_pool_ci.maxSets = 1;
6169 ds_pool_ci.poolSizeCount = 1;
6170 ds_pool_ci.pPoolSizes = &ds_type_count;
6171
6172 VkDescriptorPool ds_pool;
6173 err =
6174 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6175 ASSERT_VK_SUCCESS(err);
6176
6177 VkDescriptorSetLayoutBinding dsl_binding = {};
6178 dsl_binding.binding = 0;
6179 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6180 dsl_binding.descriptorCount = 1;
6181 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6182
6183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6185 ds_layout_ci.bindingCount = 1;
6186 ds_layout_ci.pBindings = &dsl_binding;
6187
6188 VkDescriptorSetLayout ds_layout;
6189 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6190 &ds_layout);
6191 ASSERT_VK_SUCCESS(err);
6192
6193 VkDescriptorSet descriptorSet;
6194 VkDescriptorSetAllocateInfo alloc_info = {};
6195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6196 alloc_info.descriptorSetCount = 1;
6197 alloc_info.descriptorPool = ds_pool;
6198 alloc_info.pSetLayouts = &ds_layout;
6199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6200 &descriptorSet);
6201 ASSERT_VK_SUCCESS(err);
6202
6203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6205 pipeline_layout_ci.setLayoutCount = 1;
6206 pipeline_layout_ci.pSetLayouts = &ds_layout;
6207
6208 VkPipelineLayout pipeline_layout;
6209 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6210 &pipeline_layout);
6211 ASSERT_VK_SUCCESS(err);
6212
6213 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6214 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6215 vp_state_ci.scissorCount = 1;
6216 vp_state_ci.pScissors =
6217 NULL; // Null scissor w/ count of 1 should cause error
6218 vp_state_ci.viewportCount = 1;
6219 vp_state_ci.pViewports =
6220 NULL; // vp is dynamic (below) so this won't cause error
6221
6222 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6223 // Set scissor as dynamic to avoid that error
6224 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6225 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6226 dyn_state_ci.dynamicStateCount = 1;
6227 dyn_state_ci.pDynamicStates = &vp_state;
6228
6229 VkPipelineShaderStageCreateInfo shaderStages[2];
6230 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6231
6232 VkShaderObj vs(m_device, bindStateVertShaderText,
6233 VK_SHADER_STAGE_VERTEX_BIT, this);
6234 VkShaderObj fs(m_device, bindStateFragShaderText,
6235 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006236 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006237 // but add it to be able to run on more devices
6238 shaderStages[0] = vs.GetStageCreateInfo();
6239 shaderStages[1] = fs.GetStageCreateInfo();
6240
6241 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6242 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6243 vi_ci.pNext = nullptr;
6244 vi_ci.vertexBindingDescriptionCount = 0;
6245 vi_ci.pVertexBindingDescriptions = nullptr;
6246 vi_ci.vertexAttributeDescriptionCount = 0;
6247 vi_ci.pVertexAttributeDescriptions = nullptr;
6248
6249 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6250 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6251 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6252
6253 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6254 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6255 rs_ci.pNext = nullptr;
6256
Mark Youngc89c6312016-03-31 16:03:20 -06006257 VkPipelineColorBlendAttachmentState att = {};
6258 att.blendEnable = VK_FALSE;
6259 att.colorWriteMask = 0xf;
6260
Karl Schultz6addd812016-02-02 17:17:23 -07006261 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6262 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6263 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006264 cb_ci.attachmentCount = 1;
6265 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006266
6267 VkGraphicsPipelineCreateInfo gp_ci = {};
6268 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6269 gp_ci.stageCount = 2;
6270 gp_ci.pStages = shaderStages;
6271 gp_ci.pVertexInputState = &vi_ci;
6272 gp_ci.pInputAssemblyState = &ia_ci;
6273 gp_ci.pViewportState = &vp_state_ci;
6274 gp_ci.pRasterizationState = &rs_ci;
6275 gp_ci.pColorBlendState = &cb_ci;
6276 gp_ci.pDynamicState = &dyn_state_ci;
6277 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6278 gp_ci.layout = pipeline_layout;
6279 gp_ci.renderPass = renderPass();
6280
6281 VkPipelineCacheCreateInfo pc_ci = {};
6282 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6283
6284 VkPipeline pipeline;
6285 VkPipelineCache pipelineCache;
6286
6287 err =
6288 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6289 ASSERT_VK_SUCCESS(err);
6290 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6291 &gp_ci, NULL, &pipeline);
6292
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006293 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006294
6295 // Now hit second fail case where we set scissor w/ different count than PSO
6296 // First need to successfully create the PSO from above by setting
6297 // pViewports
6298 m_errorMonitor->SetDesiredFailureMsg(
6299 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6300 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6301 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006302
Tobin Ehlisd332f282015-10-02 11:00:56 -06006303 VkRect2D sc = {}; // Just need dummy vp to point to
6304 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6306 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006307 ASSERT_VK_SUCCESS(err);
6308 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006309 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6310 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006311 VkViewport viewports[2] = {}; // don't care about data
6312 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07006313 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006314 Draw(1, 0, 0, 0);
6315
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006316 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006317
Chia-I Wuf7458c52015-10-26 21:10:41 +08006318 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6320 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6321 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006322}
6323
Mark Young7394fdd2016-03-31 14:56:43 -06006324TEST_F(VkLayerTest, PSOLineWidthInvalid) {
6325 VkResult err;
6326
6327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006328 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006329
6330 ASSERT_NO_FATAL_FAILURE(InitState());
6331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6332
6333 VkDescriptorPoolSize ds_type_count = {};
6334 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6335 ds_type_count.descriptorCount = 1;
6336
6337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6339 ds_pool_ci.maxSets = 1;
6340 ds_pool_ci.poolSizeCount = 1;
6341 ds_pool_ci.pPoolSizes = &ds_type_count;
6342
6343 VkDescriptorPool ds_pool;
6344 err =
6345 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6346 ASSERT_VK_SUCCESS(err);
6347
6348 VkDescriptorSetLayoutBinding dsl_binding = {};
6349 dsl_binding.binding = 0;
6350 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6351 dsl_binding.descriptorCount = 1;
6352 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6353
6354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6356 ds_layout_ci.bindingCount = 1;
6357 ds_layout_ci.pBindings = &dsl_binding;
6358
6359 VkDescriptorSetLayout ds_layout;
6360 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6361 &ds_layout);
6362 ASSERT_VK_SUCCESS(err);
6363
6364 VkDescriptorSet descriptorSet;
6365 VkDescriptorSetAllocateInfo alloc_info = {};
6366 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6367 alloc_info.descriptorSetCount = 1;
6368 alloc_info.descriptorPool = ds_pool;
6369 alloc_info.pSetLayouts = &ds_layout;
6370 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6371 &descriptorSet);
6372 ASSERT_VK_SUCCESS(err);
6373
6374 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6375 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6376 pipeline_layout_ci.setLayoutCount = 1;
6377 pipeline_layout_ci.pSetLayouts = &ds_layout;
6378
6379 VkPipelineLayout pipeline_layout;
6380 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6381 &pipeline_layout);
6382 ASSERT_VK_SUCCESS(err);
6383
6384 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6385 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6386 vp_state_ci.scissorCount = 1;
6387 vp_state_ci.pScissors = NULL;
6388 vp_state_ci.viewportCount = 1;
6389 vp_state_ci.pViewports = NULL;
6390
6391 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
6392 VK_DYNAMIC_STATE_SCISSOR,
6393 VK_DYNAMIC_STATE_LINE_WIDTH};
6394 // Set scissor as dynamic to avoid that error
6395 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6396 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6397 dyn_state_ci.dynamicStateCount = 2;
6398 dyn_state_ci.pDynamicStates = dynamic_states;
6399
6400 VkPipelineShaderStageCreateInfo shaderStages[2];
6401 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6402
6403 VkShaderObj vs(m_device, bindStateVertShaderText,
6404 VK_SHADER_STAGE_VERTEX_BIT, this);
6405 VkShaderObj fs(m_device, bindStateFragShaderText,
6406 VK_SHADER_STAGE_FRAGMENT_BIT,
6407 this); // TODO - We shouldn't need a fragment shader
6408 // but add it to be able to run on more devices
6409 shaderStages[0] = vs.GetStageCreateInfo();
6410 shaderStages[1] = fs.GetStageCreateInfo();
6411
6412 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6413 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6414 vi_ci.pNext = nullptr;
6415 vi_ci.vertexBindingDescriptionCount = 0;
6416 vi_ci.pVertexBindingDescriptions = nullptr;
6417 vi_ci.vertexAttributeDescriptionCount = 0;
6418 vi_ci.pVertexAttributeDescriptions = nullptr;
6419
6420 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6421 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6422 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6423
6424 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6425 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6426 rs_ci.pNext = nullptr;
6427
Mark Young47107952016-05-02 15:59:55 -06006428 // Check too low (line width of -1.0f).
6429 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06006430
6431 VkPipelineColorBlendAttachmentState att = {};
6432 att.blendEnable = VK_FALSE;
6433 att.colorWriteMask = 0xf;
6434
6435 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6436 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6437 cb_ci.pNext = nullptr;
6438 cb_ci.attachmentCount = 1;
6439 cb_ci.pAttachments = &att;
6440
6441 VkGraphicsPipelineCreateInfo gp_ci = {};
6442 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6443 gp_ci.stageCount = 2;
6444 gp_ci.pStages = shaderStages;
6445 gp_ci.pVertexInputState = &vi_ci;
6446 gp_ci.pInputAssemblyState = &ia_ci;
6447 gp_ci.pViewportState = &vp_state_ci;
6448 gp_ci.pRasterizationState = &rs_ci;
6449 gp_ci.pColorBlendState = &cb_ci;
6450 gp_ci.pDynamicState = &dyn_state_ci;
6451 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6452 gp_ci.layout = pipeline_layout;
6453 gp_ci.renderPass = renderPass();
6454
6455 VkPipelineCacheCreateInfo pc_ci = {};
6456 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6457
6458 VkPipeline pipeline;
6459 VkPipelineCache pipelineCache;
6460
6461 err =
6462 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6463 ASSERT_VK_SUCCESS(err);
6464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6465 &gp_ci, NULL, &pipeline);
6466
6467 m_errorMonitor->VerifyFound();
6468
6469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6470 "Attempt to set lineWidth to 65536");
6471
6472 // Check too high (line width of 65536.0f).
6473 rs_ci.lineWidth = 65536.0f;
6474
6475 err =
6476 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6477 ASSERT_VK_SUCCESS(err);
6478 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6479 &gp_ci, NULL, &pipeline);
6480
6481 m_errorMonitor->VerifyFound();
6482
6483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06006484 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06006485
6486 dyn_state_ci.dynamicStateCount = 3;
6487
6488 rs_ci.lineWidth = 1.0f;
6489
6490 err =
6491 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6492 ASSERT_VK_SUCCESS(err);
6493 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6494 &gp_ci, NULL, &pipeline);
6495 BeginCommandBuffer();
6496 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6497 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6498
6499 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06006500 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06006501 m_errorMonitor->VerifyFound();
6502
6503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6504 "Attempt to set lineWidth to 65536");
6505
6506 // Check too high with dynamic setting.
6507 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
6508 m_errorMonitor->VerifyFound();
6509 EndCommandBuffer();
6510
6511 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6513 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6514 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6515}
6516
Karl Schultz6addd812016-02-02 17:17:23 -07006517TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006518 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006519 m_errorMonitor->SetDesiredFailureMsg(
6520 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006521 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006522
6523 ASSERT_NO_FATAL_FAILURE(InitState());
6524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006525
Tony Barbourfe3351b2015-07-28 10:17:20 -06006526 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006527 // Don't care about RenderPass handle b/c error should be flagged before
6528 // that
6529 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
6530 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006531
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006532 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06006533}
6534
Karl Schultz6addd812016-02-02 17:17:23 -07006535TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006536 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006537 m_errorMonitor->SetDesiredFailureMsg(
6538 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006539 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006540
6541 ASSERT_NO_FATAL_FAILURE(InitState());
6542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006543
Tony Barbourfe3351b2015-07-28 10:17:20 -06006544 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006545 // Just create a dummy Renderpass that's non-NULL so we can get to the
6546 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06006547 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006548 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
6549 rp_begin.pNext = NULL;
6550 rp_begin.renderPass = renderPass();
6551 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006552
Karl Schultz6addd812016-02-02 17:17:23 -07006553 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
6554 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006555
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006556 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006557}
6558
Cody Northrop3bb4d962016-05-09 16:15:57 -06006559TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
6560
6561 TEST_DESCRIPTION("End a command buffer with an active render pass");
6562
6563 m_errorMonitor->SetDesiredFailureMsg(
6564 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6565 "It is invalid to issue this call inside an active render pass");
6566
6567 ASSERT_NO_FATAL_FAILURE(InitState());
6568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6569
6570 // The framework's BeginCommandBuffer calls CreateRenderPass
6571 BeginCommandBuffer();
6572
6573 // Call directly into vkEndCommandBuffer instead of the
6574 // the framework's EndCommandBuffer, which inserts a
6575 // vkEndRenderPass
6576 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
6577
6578 m_errorMonitor->VerifyFound();
6579
6580 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
6581 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
6582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006585 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006586 m_errorMonitor->SetDesiredFailureMsg(
6587 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006588 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006589
6590 ASSERT_NO_FATAL_FAILURE(InitState());
6591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006592
6593 // Renderpass is started here
6594 BeginCommandBuffer();
6595
6596 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006597 vk_testing::Buffer dstBuffer;
6598 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006599
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006600 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006601
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006602 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006603}
6604
Karl Schultz6addd812016-02-02 17:17:23 -07006605TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006606 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07006607 m_errorMonitor->SetDesiredFailureMsg(
6608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006609 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006610
6611 ASSERT_NO_FATAL_FAILURE(InitState());
6612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006613
6614 // Renderpass is started here
6615 BeginCommandBuffer();
6616
6617 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006618 vk_testing::Buffer dstBuffer;
6619 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006620
Karl Schultz6addd812016-02-02 17:17:23 -07006621 VkDeviceSize dstOffset = 0;
6622 VkDeviceSize dataSize = 1024;
6623 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006624
Karl Schultz6addd812016-02-02 17:17:23 -07006625 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
6626 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006627
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006628 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006629}
6630
Karl Schultz6addd812016-02-02 17:17:23 -07006631TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006632 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006633 m_errorMonitor->SetDesiredFailureMsg(
6634 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006635 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006636
6637 ASSERT_NO_FATAL_FAILURE(InitState());
6638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006639
6640 // Renderpass is started here
6641 BeginCommandBuffer();
6642
Michael Lentine0a369f62016-02-03 16:51:46 -06006643 VkClearColorValue clear_color;
6644 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07006645 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
6646 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6647 const int32_t tex_width = 32;
6648 const int32_t tex_height = 32;
6649 VkImageCreateInfo image_create_info = {};
6650 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6651 image_create_info.pNext = NULL;
6652 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6653 image_create_info.format = tex_format;
6654 image_create_info.extent.width = tex_width;
6655 image_create_info.extent.height = tex_height;
6656 image_create_info.extent.depth = 1;
6657 image_create_info.mipLevels = 1;
6658 image_create_info.arrayLayers = 1;
6659 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6660 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
6661 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006662
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006663 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006664 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6665 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006666
Karl Schultz6addd812016-02-02 17:17:23 -07006667 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6668 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006669
Karl Schultz6addd812016-02-02 17:17:23 -07006670 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6671 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006672
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006673 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006674}
6675
Karl Schultz6addd812016-02-02 17:17:23 -07006676TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006677 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006678 m_errorMonitor->SetDesiredFailureMsg(
6679 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006680 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006681
6682 ASSERT_NO_FATAL_FAILURE(InitState());
6683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006684
6685 // Renderpass is started here
6686 BeginCommandBuffer();
6687
6688 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07006689 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006690 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
6691 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6692 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
6693 image_create_info.extent.width = 64;
6694 image_create_info.extent.height = 64;
6695 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6696 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006697
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006698 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07006699 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
6700 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006701
Karl Schultz6addd812016-02-02 17:17:23 -07006702 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
6703 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006704
Karl Schultz6addd812016-02-02 17:17:23 -07006705 vkCmdClearDepthStencilImage(
6706 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
6707 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
6708 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006710 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006711}
6712
Karl Schultz6addd812016-02-02 17:17:23 -07006713TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006714 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006715 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006716
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006718 "vkCmdClearAttachments: This call "
6719 "must be issued inside an active "
6720 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006721
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006722 ASSERT_NO_FATAL_FAILURE(InitState());
6723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006724
6725 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006727 ASSERT_VK_SUCCESS(err);
6728
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006729 VkClearAttachment color_attachment;
6730 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6731 color_attachment.clearValue.color.float32[0] = 0;
6732 color_attachment.clearValue.color.float32[1] = 0;
6733 color_attachment.clearValue.color.float32[2] = 0;
6734 color_attachment.clearValue.color.float32[3] = 0;
6735 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006736 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
6737 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6738 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06006741}
6742
Karl Schultz9e66a292016-04-21 15:57:51 -06006743TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
6744 // Try to add a buffer memory barrier with no buffer.
6745 m_errorMonitor->SetDesiredFailureMsg(
6746 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6747 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
6748
6749 ASSERT_NO_FATAL_FAILURE(InitState());
6750 BeginCommandBuffer();
6751
6752 VkBufferMemoryBarrier buf_barrier = {};
6753 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6754 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6755 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6756 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6757 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6758 buf_barrier.buffer = VK_NULL_HANDLE;
6759 buf_barrier.offset = 0;
6760 buf_barrier.size = VK_WHOLE_SIZE;
6761 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6762 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
6763 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
6764
6765 m_errorMonitor->VerifyFound();
6766}
6767
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06006768TEST_F(VkLayerTest, InvalidBarriers) {
6769 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
6770
6771 m_errorMonitor->SetDesiredFailureMsg(
6772 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
6773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
6775 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6776
6777 VkMemoryBarrier mem_barrier = {};
6778 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
6779 mem_barrier.pNext = NULL;
6780 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6781 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6782 BeginCommandBuffer();
6783 // BeginCommandBuffer() starts a render pass
6784 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6785 VK_PIPELINE_STAGE_HOST_BIT,
6786 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
6787 &mem_barrier, 0, nullptr, 0, nullptr);
6788 m_errorMonitor->VerifyFound();
6789
6790 m_errorMonitor->SetDesiredFailureMsg(
6791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6792 "Image Layout cannot be transitioned to UNDEFINED");
6793 VkImageObj image(m_device);
6794 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
6795 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6796 ASSERT_TRUE(image.initialized());
6797 VkImageMemoryBarrier img_barrier = {};
6798 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
6799 img_barrier.pNext = NULL;
6800 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6801 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6802 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6803 // New layout can't be UNDEFINED
6804 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6805 img_barrier.image = image.handle();
6806 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6807 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6808 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6809 img_barrier.subresourceRange.baseArrayLayer = 0;
6810 img_barrier.subresourceRange.baseMipLevel = 0;
6811 img_barrier.subresourceRange.layerCount = 1;
6812 img_barrier.subresourceRange.levelCount = 1;
6813 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6814 VK_PIPELINE_STAGE_HOST_BIT,
6815 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6816 nullptr, 1, &img_barrier);
6817 m_errorMonitor->VerifyFound();
6818 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6819
6820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6821 "Subresource must have the sum of the "
6822 "baseArrayLayer");
6823 // baseArrayLayer + layerCount must be <= image's arrayLayers
6824 img_barrier.subresourceRange.baseArrayLayer = 1;
6825 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6826 VK_PIPELINE_STAGE_HOST_BIT,
6827 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6828 nullptr, 1, &img_barrier);
6829 m_errorMonitor->VerifyFound();
6830 img_barrier.subresourceRange.baseArrayLayer = 0;
6831
6832 m_errorMonitor->SetDesiredFailureMsg(
6833 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6834 "Subresource must have the sum of the baseMipLevel");
6835 // baseMipLevel + levelCount must be <= image's mipLevels
6836 img_barrier.subresourceRange.baseMipLevel = 1;
6837 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6838 VK_PIPELINE_STAGE_HOST_BIT,
6839 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6840 nullptr, 1, &img_barrier);
6841 m_errorMonitor->VerifyFound();
6842 img_barrier.subresourceRange.baseMipLevel = 0;
6843
6844 m_errorMonitor->SetDesiredFailureMsg(
6845 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6846 "Buffer Barriers cannot be used during a render pass");
6847 vk_testing::Buffer buffer;
6848 buffer.init(*m_device, 256);
6849 VkBufferMemoryBarrier buf_barrier = {};
6850 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
6851 buf_barrier.pNext = NULL;
6852 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
6853 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
6854 buf_barrier.buffer = buffer.handle();
6855 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6856 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
6857 buf_barrier.offset = 0;
6858 buf_barrier.size = VK_WHOLE_SIZE;
6859 // Can't send buffer barrier during a render pass
6860 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6861 VK_PIPELINE_STAGE_HOST_BIT,
6862 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6863 &buf_barrier, 0, nullptr);
6864 m_errorMonitor->VerifyFound();
6865 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
6866
6867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6868 "which is not less than total size");
6869 buf_barrier.offset = 257;
6870 // Offset greater than total size
6871 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6872 VK_PIPELINE_STAGE_HOST_BIT,
6873 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6874 &buf_barrier, 0, nullptr);
6875 m_errorMonitor->VerifyFound();
6876 buf_barrier.offset = 0;
6877
6878 m_errorMonitor->SetDesiredFailureMsg(
6879 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
6880 buf_barrier.size = 257;
6881 // Size greater than total size
6882 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6883 VK_PIPELINE_STAGE_HOST_BIT,
6884 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
6885 &buf_barrier, 0, nullptr);
6886 m_errorMonitor->VerifyFound();
6887 buf_barrier.size = VK_WHOLE_SIZE;
6888
6889 m_errorMonitor->SetDesiredFailureMsg(
6890 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6891 "Image is a depth and stencil format and thus must "
6892 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
6893 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
6894 VkDepthStencilObj ds_image(m_device);
6895 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
6896 ASSERT_TRUE(ds_image.initialized());
6897 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6898 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
6899 img_barrier.image = ds_image.handle();
6900 // Leave aspectMask at COLOR on purpose
6901 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
6902 VK_PIPELINE_STAGE_HOST_BIT,
6903 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
6904 nullptr, 1, &img_barrier);
6905 m_errorMonitor->VerifyFound();
6906}
6907
Karl Schultz6addd812016-02-02 17:17:23 -07006908TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006909 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07006910 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006911
Karl Schultz6addd812016-02-02 17:17:23 -07006912 m_errorMonitor->SetDesiredFailureMsg(
6913 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006914 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
6915
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006916 ASSERT_NO_FATAL_FAILURE(InitState());
6917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006918 uint32_t qfi = 0;
6919 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6921 buffCI.size = 1024;
6922 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6923 buffCI.queueFamilyIndexCount = 1;
6924 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006925
6926 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006927 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006928 ASSERT_VK_SUCCESS(err);
6929
6930 BeginCommandBuffer();
6931 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006932 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6933 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006934 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07006935 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
6936 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006937
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006938 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006939
Chia-I Wuf7458c52015-10-26 21:10:41 +08006940 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06006941}
6942
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006943TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
6944 // Create an out-of-range queueFamilyIndex
6945 m_errorMonitor->SetDesiredFailureMsg(
6946 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06006947 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
6948 "of the indices specified when the device was created, via the "
6949 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006950
6951 ASSERT_NO_FATAL_FAILURE(InitState());
6952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6953 VkBufferCreateInfo buffCI = {};
6954 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6955 buffCI.size = 1024;
6956 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
6957 buffCI.queueFamilyIndexCount = 1;
6958 // Introduce failure by specifying invalid queue_family_index
6959 uint32_t qfi = 777;
6960 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06006961 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006962
6963 VkBuffer ib;
6964 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
6965
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006966 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07006967}
6968
Karl Schultz6addd812016-02-02 17:17:23 -07006969TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
6970 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
6971 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006972
Karl Schultz6addd812016-02-02 17:17:23 -07006973 m_errorMonitor->SetDesiredFailureMsg(
6974 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006975 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006976
6977 ASSERT_NO_FATAL_FAILURE(InitState());
6978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006979
6980 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006981 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006982 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
6983 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006985 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006986}
6987
Karl Schultz6addd812016-02-02 17:17:23 -07006988TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006989 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07006990 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006991
Karl Schultz6addd812016-02-02 17:17:23 -07006992 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6994 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
6995 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006996
Tobin Ehlis3b780662015-05-28 12:11:26 -06006997 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07006998 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006999 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7001 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007002
7003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7005 ds_pool_ci.pNext = NULL;
7006 ds_pool_ci.maxSets = 1;
7007 ds_pool_ci.poolSizeCount = 1;
7008 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007009
Tobin Ehlis3b780662015-05-28 12:11:26 -06007010 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007011 err =
7012 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007013 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007015 dsl_binding.binding = 0;
7016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7017 dsl_binding.descriptorCount = 1;
7018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7019 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007020
Tony Barboureb254902015-07-15 12:50:33 -06007021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7023 ds_layout_ci.pNext = NULL;
7024 ds_layout_ci.bindingCount = 1;
7025 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007026
Tobin Ehlis3b780662015-05-28 12:11:26 -06007027 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7029 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007030 ASSERT_VK_SUCCESS(err);
7031
7032 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007033 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007034 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007035 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007036 alloc_info.descriptorPool = ds_pool;
7037 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007038 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7039 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007040 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007041
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007042 VkSamplerCreateInfo sampler_ci = {};
7043 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7044 sampler_ci.pNext = NULL;
7045 sampler_ci.magFilter = VK_FILTER_NEAREST;
7046 sampler_ci.minFilter = VK_FILTER_NEAREST;
7047 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7048 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7049 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7050 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7051 sampler_ci.mipLodBias = 1.0;
7052 sampler_ci.anisotropyEnable = VK_FALSE;
7053 sampler_ci.maxAnisotropy = 1;
7054 sampler_ci.compareEnable = VK_FALSE;
7055 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7056 sampler_ci.minLod = 1.0;
7057 sampler_ci.maxLod = 1.0;
7058 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7059 sampler_ci.unnormalizedCoordinates = VK_FALSE;
7060 VkSampler sampler;
7061 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
7062 ASSERT_VK_SUCCESS(err);
7063
7064 VkDescriptorImageInfo info = {};
7065 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007066
7067 VkWriteDescriptorSet descriptor_write;
7068 memset(&descriptor_write, 0, sizeof(descriptor_write));
7069 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007070 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007071 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007072 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007074 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007075
7076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7077
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007078 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007079
Chia-I Wuf7458c52015-10-26 21:10:41 +08007080 vkDestroySampler(m_device->device(), sampler, NULL);
7081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7082 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007083}
7084
Karl Schultz6addd812016-02-02 17:17:23 -07007085TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007086 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07007087 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007088
Karl Schultz6addd812016-02-02 17:17:23 -07007089 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007090 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7091 " binding #0 with 1 total descriptors but update of 1 descriptors "
7092 "starting at binding offset of 0 combined with update array element "
7093 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007094
Tobin Ehlis3b780662015-05-28 12:11:26 -06007095 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007096 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007097 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007098 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7099 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007100
7101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7103 ds_pool_ci.pNext = NULL;
7104 ds_pool_ci.maxSets = 1;
7105 ds_pool_ci.poolSizeCount = 1;
7106 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007107
Tobin Ehlis3b780662015-05-28 12:11:26 -06007108 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007109 err =
7110 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007111 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007112
Tony Barboureb254902015-07-15 12:50:33 -06007113 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 dsl_binding.binding = 0;
7115 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7116 dsl_binding.descriptorCount = 1;
7117 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7118 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007119
7120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7122 ds_layout_ci.pNext = NULL;
7123 ds_layout_ci.bindingCount = 1;
7124 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007125
Tobin Ehlis3b780662015-05-28 12:11:26 -06007126 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007127 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7128 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007129 ASSERT_VK_SUCCESS(err);
7130
7131 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007132 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007133 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007134 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007135 alloc_info.descriptorPool = ds_pool;
7136 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007137 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7138 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007139 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007140
Tobin Ehlis30db8f82016-05-05 08:19:48 -06007141 // Correctly update descriptor to avoid "NOT_UPDATED" error
7142 VkDescriptorBufferInfo buff_info = {};
7143 buff_info.buffer =
7144 VkBuffer(0); // Don't care about buffer handle for this test
7145 buff_info.offset = 0;
7146 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007147
7148 VkWriteDescriptorSet descriptor_write;
7149 memset(&descriptor_write, 0, sizeof(descriptor_write));
7150 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007151 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007152 descriptor_write.dstArrayElement =
7153 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08007154 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007155 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7156 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007157
7158 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7159
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007160 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007161
Chia-I Wuf7458c52015-10-26 21:10:41 +08007162 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7163 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007164}
7165
Karl Schultz6addd812016-02-02 17:17:23 -07007166TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
7167 // Create layout w/ count of 1 and attempt update to that layout w/ binding
7168 // index 2
7169 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007170
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7172 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007173
Tobin Ehlis3b780662015-05-28 12:11:26 -06007174 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007175 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007176 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007177 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7178 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007179
7180 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007181 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7182 ds_pool_ci.pNext = NULL;
7183 ds_pool_ci.maxSets = 1;
7184 ds_pool_ci.poolSizeCount = 1;
7185 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007186
Tobin Ehlis3b780662015-05-28 12:11:26 -06007187 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007188 err =
7189 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007191
Tony Barboureb254902015-07-15 12:50:33 -06007192 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007193 dsl_binding.binding = 0;
7194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7195 dsl_binding.descriptorCount = 1;
7196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7197 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06007198
7199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7201 ds_layout_ci.pNext = NULL;
7202 ds_layout_ci.bindingCount = 1;
7203 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007204 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7206 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007207 ASSERT_VK_SUCCESS(err);
7208
7209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007212 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007213 alloc_info.descriptorPool = ds_pool;
7214 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7216 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007217 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007218
Tony Barboureb254902015-07-15 12:50:33 -06007219 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007220 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7221 sampler_ci.pNext = NULL;
7222 sampler_ci.magFilter = VK_FILTER_NEAREST;
7223 sampler_ci.minFilter = VK_FILTER_NEAREST;
7224 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7225 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7226 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7227 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7228 sampler_ci.mipLodBias = 1.0;
7229 sampler_ci.anisotropyEnable = VK_FALSE;
7230 sampler_ci.maxAnisotropy = 1;
7231 sampler_ci.compareEnable = VK_FALSE;
7232 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7233 sampler_ci.minLod = 1.0;
7234 sampler_ci.maxLod = 1.0;
7235 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7236 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06007237
Tobin Ehlis3b780662015-05-28 12:11:26 -06007238 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007239 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007240 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007241
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007242 VkDescriptorImageInfo info = {};
7243 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007244
7245 VkWriteDescriptorSet descriptor_write;
7246 memset(&descriptor_write, 0, sizeof(descriptor_write));
7247 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007248 descriptor_write.dstSet = descriptorSet;
7249 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007250 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007251 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007252 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007253 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007254
7255 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007258
Chia-I Wuf7458c52015-10-26 21:10:41 +08007259 vkDestroySampler(m_device->device(), sampler, NULL);
7260 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7261 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007262}
7263
Karl Schultz6addd812016-02-02 17:17:23 -07007264TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
7265 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
7266 // types
7267 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007268
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06007270 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007271
Tobin Ehlis3b780662015-05-28 12:11:26 -06007272 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007273
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007274 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007275 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7276 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007277
7278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7280 ds_pool_ci.pNext = NULL;
7281 ds_pool_ci.maxSets = 1;
7282 ds_pool_ci.poolSizeCount = 1;
7283 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007284
Tobin Ehlis3b780662015-05-28 12:11:26 -06007285 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007286 err =
7287 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007288 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06007289 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007290 dsl_binding.binding = 0;
7291 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7292 dsl_binding.descriptorCount = 1;
7293 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7294 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007295
Tony Barboureb254902015-07-15 12:50:33 -06007296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7298 ds_layout_ci.pNext = NULL;
7299 ds_layout_ci.bindingCount = 1;
7300 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007301
Tobin Ehlis3b780662015-05-28 12:11:26 -06007302 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007303 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7304 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007305 ASSERT_VK_SUCCESS(err);
7306
7307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007310 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007311 alloc_info.descriptorPool = ds_pool;
7312 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7314 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007315 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007316
Tony Barboureb254902015-07-15 12:50:33 -06007317 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007318 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7319 sampler_ci.pNext = NULL;
7320 sampler_ci.magFilter = VK_FILTER_NEAREST;
7321 sampler_ci.minFilter = VK_FILTER_NEAREST;
7322 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7323 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7324 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7325 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7326 sampler_ci.mipLodBias = 1.0;
7327 sampler_ci.anisotropyEnable = VK_FALSE;
7328 sampler_ci.maxAnisotropy = 1;
7329 sampler_ci.compareEnable = VK_FALSE;
7330 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7331 sampler_ci.minLod = 1.0;
7332 sampler_ci.maxLod = 1.0;
7333 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7334 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007335 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007336 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007337 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007338
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007339 VkDescriptorImageInfo info = {};
7340 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007341
7342 VkWriteDescriptorSet descriptor_write;
7343 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07007344 descriptor_write.sType =
7345 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007347 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007348 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06007350 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08007351
7352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007354 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007355
Chia-I Wuf7458c52015-10-26 21:10:41 +08007356 vkDestroySampler(m_device->device(), sampler, NULL);
7357 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7358 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007359}
7360
Karl Schultz6addd812016-02-02 17:17:23 -07007361TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007362 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07007363 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007364
Karl Schultz6addd812016-02-02 17:17:23 -07007365 m_errorMonitor->SetDesiredFailureMsg(
7366 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007367 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007368
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007369 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007370 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
7371 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007372 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007373 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
7374 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007375
7376 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007377 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7378 ds_pool_ci.pNext = NULL;
7379 ds_pool_ci.maxSets = 1;
7380 ds_pool_ci.poolSizeCount = 1;
7381 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007382
7383 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007384 err =
7385 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007386 ASSERT_VK_SUCCESS(err);
7387
7388 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007389 dsl_binding.binding = 0;
7390 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7391 dsl_binding.descriptorCount = 1;
7392 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7393 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007394
7395 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007396 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7397 ds_layout_ci.pNext = NULL;
7398 ds_layout_ci.bindingCount = 1;
7399 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007400 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007401 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7402 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007403 ASSERT_VK_SUCCESS(err);
7404
7405 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007406 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007408 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007409 alloc_info.descriptorPool = ds_pool;
7410 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7412 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007413 ASSERT_VK_SUCCESS(err);
7414
Karl Schultz6addd812016-02-02 17:17:23 -07007415 VkSampler sampler =
7416 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007417
7418 VkDescriptorImageInfo descriptor_info;
7419 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7420 descriptor_info.sampler = sampler;
7421
7422 VkWriteDescriptorSet descriptor_write;
7423 memset(&descriptor_write, 0, sizeof(descriptor_write));
7424 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007425 descriptor_write.dstSet = descriptorSet;
7426 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007427 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007428 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7429 descriptor_write.pImageInfo = &descriptor_info;
7430
7431 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7432
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007433 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007434
Chia-I Wuf7458c52015-10-26 21:10:41 +08007435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007437}
7438
Karl Schultz6addd812016-02-02 17:17:23 -07007439TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
7440 // Create a single combined Image/Sampler descriptor and send it an invalid
7441 // imageView
7442 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007443
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7445 "Attempted write update to combined "
7446 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06007447 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007448
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007449 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007450 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7452 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007453
7454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7456 ds_pool_ci.pNext = NULL;
7457 ds_pool_ci.maxSets = 1;
7458 ds_pool_ci.poolSizeCount = 1;
7459 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007460
7461 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007462 err =
7463 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007464 ASSERT_VK_SUCCESS(err);
7465
7466 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007467 dsl_binding.binding = 0;
7468 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7469 dsl_binding.descriptorCount = 1;
7470 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7471 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007472
7473 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007474 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7475 ds_layout_ci.pNext = NULL;
7476 ds_layout_ci.bindingCount = 1;
7477 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007478 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007479 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7480 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007481 ASSERT_VK_SUCCESS(err);
7482
7483 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007484 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007485 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007486 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007487 alloc_info.descriptorPool = ds_pool;
7488 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007489 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7490 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007491 ASSERT_VK_SUCCESS(err);
7492
7493 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007494 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7495 sampler_ci.pNext = NULL;
7496 sampler_ci.magFilter = VK_FILTER_NEAREST;
7497 sampler_ci.minFilter = VK_FILTER_NEAREST;
7498 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7499 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7500 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7501 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7502 sampler_ci.mipLodBias = 1.0;
7503 sampler_ci.anisotropyEnable = VK_FALSE;
7504 sampler_ci.maxAnisotropy = 1;
7505 sampler_ci.compareEnable = VK_FALSE;
7506 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7507 sampler_ci.minLod = 1.0;
7508 sampler_ci.maxLod = 1.0;
7509 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7510 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007511
7512 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007513 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007514 ASSERT_VK_SUCCESS(err);
7515
Karl Schultz6addd812016-02-02 17:17:23 -07007516 VkImageView view =
7517 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007518
7519 VkDescriptorImageInfo descriptor_info;
7520 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
7521 descriptor_info.sampler = sampler;
7522 descriptor_info.imageView = view;
7523
7524 VkWriteDescriptorSet descriptor_write;
7525 memset(&descriptor_write, 0, sizeof(descriptor_write));
7526 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007527 descriptor_write.dstSet = descriptorSet;
7528 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007529 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
7531 descriptor_write.pImageInfo = &descriptor_info;
7532
7533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7534
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007536
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 vkDestroySampler(m_device->device(), sampler, NULL);
7538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7539 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06007540}
7541
Karl Schultz6addd812016-02-02 17:17:23 -07007542TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
7543 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
7544 // into the other
7545 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007546
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7548 " binding #1 with type "
7549 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
7550 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007551
Tobin Ehlis04356f92015-10-27 16:35:27 -06007552 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07007553 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007554 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007555 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7556 ds_type_count[0].descriptorCount = 1;
7557 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7558 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007559
7560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7562 ds_pool_ci.pNext = NULL;
7563 ds_pool_ci.maxSets = 1;
7564 ds_pool_ci.poolSizeCount = 2;
7565 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007566
7567 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007568 err =
7569 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007570 ASSERT_VK_SUCCESS(err);
7571 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007572 dsl_binding[0].binding = 0;
7573 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7574 dsl_binding[0].descriptorCount = 1;
7575 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7576 dsl_binding[0].pImmutableSamplers = NULL;
7577 dsl_binding[1].binding = 1;
7578 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7579 dsl_binding[1].descriptorCount = 1;
7580 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7581 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007582
7583 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007584 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7585 ds_layout_ci.pNext = NULL;
7586 ds_layout_ci.bindingCount = 2;
7587 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007588
7589 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7591 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007592 ASSERT_VK_SUCCESS(err);
7593
7594 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007595 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007597 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007598 alloc_info.descriptorPool = ds_pool;
7599 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7601 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007602 ASSERT_VK_SUCCESS(err);
7603
7604 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007605 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
7606 sampler_ci.pNext = NULL;
7607 sampler_ci.magFilter = VK_FILTER_NEAREST;
7608 sampler_ci.minFilter = VK_FILTER_NEAREST;
7609 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
7610 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7611 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7612 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
7613 sampler_ci.mipLodBias = 1.0;
7614 sampler_ci.anisotropyEnable = VK_FALSE;
7615 sampler_ci.maxAnisotropy = 1;
7616 sampler_ci.compareEnable = VK_FALSE;
7617 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
7618 sampler_ci.minLod = 1.0;
7619 sampler_ci.maxLod = 1.0;
7620 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
7621 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007622
7623 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007624 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkDescriptorImageInfo info = {};
7628 info.sampler = sampler;
7629
7630 VkWriteDescriptorSet descriptor_write;
7631 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
7632 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007633 descriptor_write.dstSet = descriptorSet;
7634 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08007635 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06007636 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
7637 descriptor_write.pImageInfo = &info;
7638 // This write update should succeed
7639 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7640 // Now perform a copy update that fails due to type mismatch
7641 VkCopyDescriptorSet copy_ds_update;
7642 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7643 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7644 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06007645 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007646 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007647 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08007648 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007649 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7650
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007651 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007652 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007653 m_errorMonitor->SetDesiredFailureMsg(
7654 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007655 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06007656 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7657 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7658 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007659 copy_ds_update.srcBinding =
7660 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007661 copy_ds_update.dstSet = descriptorSet;
7662 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06007663 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06007664 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7665
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007666 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007667
Tobin Ehlis04356f92015-10-27 16:35:27 -06007668 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07007669 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06007670 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
7671 "update array offset of 0 and update of "
7672 "5 descriptors oversteps total number "
7673 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007674
Tobin Ehlis04356f92015-10-27 16:35:27 -06007675 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
7676 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
7677 copy_ds_update.srcSet = descriptorSet;
7678 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007679 copy_ds_update.dstSet = descriptorSet;
7680 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007681 copy_ds_update.descriptorCount =
7682 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06007683 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
7684
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007685 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06007686
Chia-I Wuf7458c52015-10-26 21:10:41 +08007687 vkDestroySampler(m_device->device(), sampler, NULL);
7688 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7689 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06007690}
7691
Karl Schultz6addd812016-02-02 17:17:23 -07007692TEST_F(VkLayerTest, NumSamplesMismatch) {
7693 // Create CommandBuffer where MSAA samples doesn't match RenderPass
7694 // sampleCount
7695 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007696
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007698 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007699
Tobin Ehlis3b780662015-05-28 12:11:26 -06007700 ASSERT_NO_FATAL_FAILURE(InitState());
7701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007702 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06007703 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007704 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007705
7706 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7708 ds_pool_ci.pNext = NULL;
7709 ds_pool_ci.maxSets = 1;
7710 ds_pool_ci.poolSizeCount = 1;
7711 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06007712
Tobin Ehlis3b780662015-05-28 12:11:26 -06007713 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007714 err =
7715 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007717
Tony Barboureb254902015-07-15 12:50:33 -06007718 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007719 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06007720 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007721 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007722 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7723 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007724
Tony Barboureb254902015-07-15 12:50:33 -06007725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7727 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007728 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007729 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007730
Tobin Ehlis3b780662015-05-28 12:11:26 -06007731 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007732 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7733 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007734 ASSERT_VK_SUCCESS(err);
7735
7736 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007737 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007739 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007740 alloc_info.descriptorPool = ds_pool;
7741 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7743 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007744 ASSERT_VK_SUCCESS(err);
7745
Tony Barboureb254902015-07-15 12:50:33 -06007746 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007747 pipe_ms_state_ci.sType =
7748 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7749 pipe_ms_state_ci.pNext = NULL;
7750 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7751 pipe_ms_state_ci.sampleShadingEnable = 0;
7752 pipe_ms_state_ci.minSampleShading = 1.0;
7753 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007754
Tony Barboureb254902015-07-15 12:50:33 -06007755 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007756 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7757 pipeline_layout_ci.pNext = NULL;
7758 pipeline_layout_ci.setLayoutCount = 1;
7759 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06007760
7761 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007762 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7763 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06007764 ASSERT_VK_SUCCESS(err);
7765
Karl Schultz6addd812016-02-02 17:17:23 -07007766 VkShaderObj vs(m_device, bindStateVertShaderText,
7767 VK_SHADER_STAGE_VERTEX_BIT, this);
7768 VkShaderObj fs(m_device, bindStateFragShaderText,
7769 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007770 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07007771 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007772 VkPipelineObj pipe(m_device);
7773 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007774 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06007775 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007776 pipe.SetMSAA(&pipe_ms_state_ci);
7777 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007778
Tony Barbourfe3351b2015-07-28 10:17:20 -06007779 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007780 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7781 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06007782
Mark Young29927482016-05-04 14:38:51 -06007783 // Render triangle (the error should trigger on the attempt to draw).
7784 Draw(3, 1, 0, 0);
7785
7786 // Finalize recording of the command buffer
7787 EndCommandBuffer();
7788
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007789 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007790
Chia-I Wuf7458c52015-10-26 21:10:41 +08007791 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7792 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7793 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007794}
Mark Young29927482016-05-04 14:38:51 -06007795
Mark Youngc89c6312016-03-31 16:03:20 -06007796TEST_F(VkLayerTest, NumBlendAttachMismatch) {
7797 // Create Pipeline where the number of blend attachments doesn't match the
7798 // number of color attachments. In this case, we don't add any color
7799 // blend attachments even though we have a color attachment.
7800 VkResult err;
7801
7802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06007803 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06007804
7805 ASSERT_NO_FATAL_FAILURE(InitState());
7806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7807 VkDescriptorPoolSize ds_type_count = {};
7808 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7809 ds_type_count.descriptorCount = 1;
7810
7811 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7812 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7813 ds_pool_ci.pNext = NULL;
7814 ds_pool_ci.maxSets = 1;
7815 ds_pool_ci.poolSizeCount = 1;
7816 ds_pool_ci.pPoolSizes = &ds_type_count;
7817
7818 VkDescriptorPool ds_pool;
7819 err =
7820 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7821 ASSERT_VK_SUCCESS(err);
7822
7823 VkDescriptorSetLayoutBinding dsl_binding = {};
7824 dsl_binding.binding = 0;
7825 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7826 dsl_binding.descriptorCount = 1;
7827 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7828 dsl_binding.pImmutableSamplers = NULL;
7829
7830 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7831 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7832 ds_layout_ci.pNext = NULL;
7833 ds_layout_ci.bindingCount = 1;
7834 ds_layout_ci.pBindings = &dsl_binding;
7835
7836 VkDescriptorSetLayout ds_layout;
7837 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7838 &ds_layout);
7839 ASSERT_VK_SUCCESS(err);
7840
7841 VkDescriptorSet descriptorSet;
7842 VkDescriptorSetAllocateInfo alloc_info = {};
7843 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7844 alloc_info.descriptorSetCount = 1;
7845 alloc_info.descriptorPool = ds_pool;
7846 alloc_info.pSetLayouts = &ds_layout;
7847 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7848 &descriptorSet);
7849 ASSERT_VK_SUCCESS(err);
7850
7851 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7852 pipe_ms_state_ci.sType =
7853 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7854 pipe_ms_state_ci.pNext = NULL;
7855 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7856 pipe_ms_state_ci.sampleShadingEnable = 0;
7857 pipe_ms_state_ci.minSampleShading = 1.0;
7858 pipe_ms_state_ci.pSampleMask = NULL;
7859
7860 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7861 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7862 pipeline_layout_ci.pNext = NULL;
7863 pipeline_layout_ci.setLayoutCount = 1;
7864 pipeline_layout_ci.pSetLayouts = &ds_layout;
7865
7866 VkPipelineLayout pipeline_layout;
7867 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7868 &pipeline_layout);
7869 ASSERT_VK_SUCCESS(err);
7870
7871 VkShaderObj vs(m_device, bindStateVertShaderText,
7872 VK_SHADER_STAGE_VERTEX_BIT, this);
7873 VkShaderObj fs(m_device, bindStateFragShaderText,
7874 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06007875 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06007876 // but add it to be able to run on more devices
7877 VkPipelineObj pipe(m_device);
7878 pipe.AddShader(&vs);
7879 pipe.AddShader(&fs);
7880 pipe.SetMSAA(&pipe_ms_state_ci);
7881 pipe.CreateVKPipeline(pipeline_layout, renderPass());
7882
7883 BeginCommandBuffer();
7884 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7885 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
7886
Mark Young29927482016-05-04 14:38:51 -06007887 // Render triangle (the error should trigger on the attempt to draw).
7888 Draw(3, 1, 0, 0);
7889
7890 // Finalize recording of the command buffer
7891 EndCommandBuffer();
7892
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007893 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06007894
7895 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7896 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7897 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7898}
Mark Young29927482016-05-04 14:38:51 -06007899
Karl Schultz6addd812016-02-02 17:17:23 -07007900TEST_F(VkLayerTest, ClearCmdNoDraw) {
7901 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
7902 // to issuing a Draw
7903 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007904
Karl Schultz6addd812016-02-02 17:17:23 -07007905 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07007906 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007907 "vkCmdClearAttachments() issued on CB object ");
7908
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007909 ASSERT_NO_FATAL_FAILURE(InitState());
7910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06007911
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007912 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007913 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7914 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007915
7916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7918 ds_pool_ci.pNext = NULL;
7919 ds_pool_ci.maxSets = 1;
7920 ds_pool_ci.poolSizeCount = 1;
7921 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06007922
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007923 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007924 err =
7925 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007926 ASSERT_VK_SUCCESS(err);
7927
Tony Barboureb254902015-07-15 12:50:33 -06007928 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007929 dsl_binding.binding = 0;
7930 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7931 dsl_binding.descriptorCount = 1;
7932 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7933 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007934
Tony Barboureb254902015-07-15 12:50:33 -06007935 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007936 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7937 ds_layout_ci.pNext = NULL;
7938 ds_layout_ci.bindingCount = 1;
7939 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007940
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007941 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7943 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007944 ASSERT_VK_SUCCESS(err);
7945
7946 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007947 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007948 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007949 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007950 alloc_info.descriptorPool = ds_pool;
7951 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7953 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007954 ASSERT_VK_SUCCESS(err);
7955
Tony Barboureb254902015-07-15 12:50:33 -06007956 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007957 pipe_ms_state_ci.sType =
7958 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7959 pipe_ms_state_ci.pNext = NULL;
7960 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7961 pipe_ms_state_ci.sampleShadingEnable = 0;
7962 pipe_ms_state_ci.minSampleShading = 1.0;
7963 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007964
Tony Barboureb254902015-07-15 12:50:33 -06007965 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007966 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7967 pipeline_layout_ci.pNext = NULL;
7968 pipeline_layout_ci.setLayoutCount = 1;
7969 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007970
7971 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007972 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7973 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007974 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007975
Karl Schultz6addd812016-02-02 17:17:23 -07007976 VkShaderObj vs(m_device, bindStateVertShaderText,
7977 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06007978 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07007979 // on more devices
7980 VkShaderObj fs(m_device, bindStateFragShaderText,
7981 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007982
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007983 VkPipelineObj pipe(m_device);
7984 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06007985 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06007986 pipe.SetMSAA(&pipe_ms_state_ci);
7987 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06007988
7989 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007990
Karl Schultz6addd812016-02-02 17:17:23 -07007991 // Main thing we care about for this test is that the VkImage obj we're
7992 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06007993 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007994 VkClearAttachment color_attachment;
7995 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7996 color_attachment.clearValue.color.float32[0] = 1.0;
7997 color_attachment.clearValue.color.float32[1] = 1.0;
7998 color_attachment.clearValue.color.float32[2] = 1.0;
7999 color_attachment.clearValue.color.float32[3] = 1.0;
8000 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008001 VkClearRect clear_rect = {
8002 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008003
Karl Schultz6addd812016-02-02 17:17:23 -07008004 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
8005 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008006
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008007 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008008
Chia-I Wuf7458c52015-10-26 21:10:41 +08008009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8011 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06008012}
8013
Karl Schultz6addd812016-02-02 17:17:23 -07008014TEST_F(VkLayerTest, VtxBufferBadIndex) {
8015 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008016
Karl Schultz6addd812016-02-02 17:17:23 -07008017 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008018 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07008019 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008020
Tobin Ehlis502480b2015-06-24 15:53:07 -06008021 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06008022 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06008023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06008024
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008025 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008026 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8027 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008028
8029 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008030 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8031 ds_pool_ci.pNext = NULL;
8032 ds_pool_ci.maxSets = 1;
8033 ds_pool_ci.poolSizeCount = 1;
8034 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008035
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008036 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008037 err =
8038 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008039 ASSERT_VK_SUCCESS(err);
8040
Tony Barboureb254902015-07-15 12:50:33 -06008041 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008042 dsl_binding.binding = 0;
8043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8044 dsl_binding.descriptorCount = 1;
8045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8046 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008047
Tony Barboureb254902015-07-15 12:50:33 -06008048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8050 ds_layout_ci.pNext = NULL;
8051 ds_layout_ci.bindingCount = 1;
8052 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008053
Tobin Ehlis502480b2015-06-24 15:53:07 -06008054 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8056 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008057 ASSERT_VK_SUCCESS(err);
8058
8059 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008060 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008061 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008062 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008063 alloc_info.descriptorPool = ds_pool;
8064 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008065 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8066 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008067 ASSERT_VK_SUCCESS(err);
8068
Tony Barboureb254902015-07-15 12:50:33 -06008069 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008070 pipe_ms_state_ci.sType =
8071 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8072 pipe_ms_state_ci.pNext = NULL;
8073 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8074 pipe_ms_state_ci.sampleShadingEnable = 0;
8075 pipe_ms_state_ci.minSampleShading = 1.0;
8076 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008077
Tony Barboureb254902015-07-15 12:50:33 -06008078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8080 pipeline_layout_ci.pNext = NULL;
8081 pipeline_layout_ci.setLayoutCount = 1;
8082 pipeline_layout_ci.pSetLayouts = &ds_layout;
8083 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06008084
Karl Schultz6addd812016-02-02 17:17:23 -07008085 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8086 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008087 ASSERT_VK_SUCCESS(err);
8088
Karl Schultz6addd812016-02-02 17:17:23 -07008089 VkShaderObj vs(m_device, bindStateVertShaderText,
8090 VK_SHADER_STAGE_VERTEX_BIT, this);
8091 VkShaderObj fs(m_device, bindStateFragShaderText,
8092 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008093 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008094 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008095 VkPipelineObj pipe(m_device);
8096 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008097 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008098 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008099 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008100 pipe.SetViewport(m_viewports);
8101 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008102 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06008103
8104 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008105 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8106 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008107 // Don't care about actual data, just need to get to draw to flag error
8108 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07008109 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
8110 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06008111 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06008112 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008113
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008114 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008115
Chia-I Wuf7458c52015-10-26 21:10:41 +08008116 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06008119}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008120// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
8121TEST_F(VkLayerTest, InvalidImageLayout) {
8122 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
8123 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
8124 "images in the wrong layout when they're copied or transitioned.");
8125 // 3 in ValidateCmdBufImageLayouts
8126 // * -1 Attempt to submit cmd buf w/ deleted image
8127 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
8128 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
8129 m_errorMonitor->SetDesiredFailureMsg(
8130 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8131 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
8132
8133 ASSERT_NO_FATAL_FAILURE(InitState());
8134 // Create src & dst images to use for copy operations
8135 VkImage src_image;
8136 VkImage dst_image;
8137
8138 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8139 const int32_t tex_width = 32;
8140 const int32_t tex_height = 32;
8141
8142 VkImageCreateInfo image_create_info = {};
8143 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8144 image_create_info.pNext = NULL;
8145 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8146 image_create_info.format = tex_format;
8147 image_create_info.extent.width = tex_width;
8148 image_create_info.extent.height = tex_height;
8149 image_create_info.extent.depth = 1;
8150 image_create_info.mipLevels = 1;
8151 image_create_info.arrayLayers = 4;
8152 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8153 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8154 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8155 image_create_info.flags = 0;
8156
8157 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
8158 ASSERT_VK_SUCCESS(err);
8159 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
8160 ASSERT_VK_SUCCESS(err);
8161
8162 BeginCommandBuffer();
8163 VkImageCopy copyRegion;
8164 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8165 copyRegion.srcSubresource.mipLevel = 0;
8166 copyRegion.srcSubresource.baseArrayLayer = 0;
8167 copyRegion.srcSubresource.layerCount = 1;
8168 copyRegion.srcOffset.x = 0;
8169 copyRegion.srcOffset.y = 0;
8170 copyRegion.srcOffset.z = 0;
8171 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8172 copyRegion.dstSubresource.mipLevel = 0;
8173 copyRegion.dstSubresource.baseArrayLayer = 0;
8174 copyRegion.dstSubresource.layerCount = 1;
8175 copyRegion.dstOffset.x = 0;
8176 copyRegion.dstOffset.y = 0;
8177 copyRegion.dstOffset.z = 0;
8178 copyRegion.extent.width = 1;
8179 copyRegion.extent.height = 1;
8180 copyRegion.extent.depth = 1;
8181 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8182 m_errorMonitor->VerifyFound();
8183 // Now cause error due to src image layout changing
8184 m_errorMonitor->SetDesiredFailureMsg(
8185 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8186 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8187 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8188 m_errorMonitor->VerifyFound();
8189 // Final src error is due to bad layout type
8190 m_errorMonitor->SetDesiredFailureMsg(
8191 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8192 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
8193 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8194 m_errorMonitor->VerifyFound();
8195 // Now verify same checks for dst
8196 m_errorMonitor->SetDesiredFailureMsg(
8197 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8198 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
8199 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
8200 m_errorMonitor->VerifyFound();
8201 // Now cause error due to src image layout changing
8202 m_errorMonitor->SetDesiredFailureMsg(
8203 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8204 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
8205 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8206 m_errorMonitor->VerifyFound();
8207 m_errorMonitor->SetDesiredFailureMsg(
8208 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8209 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
8210 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
8211 m_errorMonitor->VerifyFound();
8212 // Now cause error due to bad image layout transition in PipelineBarrier
8213 VkImageMemoryBarrier image_barrier[1] = {};
8214 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8215 image_barrier[0].image = src_image;
8216 image_barrier[0].subresourceRange.layerCount = 2;
8217 image_barrier[0].subresourceRange.levelCount = 2;
8218 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8219 m_errorMonitor->SetDesiredFailureMsg(
8220 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8221 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
8222 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
8223 m_errorMonitor->VerifyFound();
8224
8225 // Finally some layout errors at RenderPass create time
8226 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
8227 VkAttachmentReference attach = {};
8228 // perf warning for GENERAL layout w/ non-DS input attachment
8229 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8230 VkSubpassDescription subpass = {};
8231 subpass.inputAttachmentCount = 1;
8232 subpass.pInputAttachments = &attach;
8233 VkRenderPassCreateInfo rpci = {};
8234 rpci.subpassCount = 1;
8235 rpci.pSubpasses = &subpass;
8236 rpci.attachmentCount = 1;
8237 VkAttachmentDescription attach_desc = {};
8238 attach_desc.format = VK_FORMAT_UNDEFINED;
8239 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06008240 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008241 VkRenderPass rp;
8242 m_errorMonitor->SetDesiredFailureMsg(
8243 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8244 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
8245 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8246 m_errorMonitor->VerifyFound();
8247 // error w/ non-general layout
8248 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8249
8250 m_errorMonitor->SetDesiredFailureMsg(
8251 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8252 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
8253 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8254 m_errorMonitor->VerifyFound();
8255 subpass.inputAttachmentCount = 0;
8256 subpass.colorAttachmentCount = 1;
8257 subpass.pColorAttachments = &attach;
8258 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8259 // perf warning for GENERAL layout on color attachment
8260 m_errorMonitor->SetDesiredFailureMsg(
8261 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8262 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
8263 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8264 m_errorMonitor->VerifyFound();
8265 // error w/ non-color opt or GENERAL layout for color attachment
8266 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8267 m_errorMonitor->SetDesiredFailureMsg(
8268 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8269 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
8270 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8271 m_errorMonitor->VerifyFound();
8272 subpass.colorAttachmentCount = 0;
8273 subpass.pDepthStencilAttachment = &attach;
8274 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8275 // perf warning for GENERAL layout on DS attachment
8276 m_errorMonitor->SetDesiredFailureMsg(
8277 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
8278 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
8279 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8280 m_errorMonitor->VerifyFound();
8281 // error w/ non-ds opt or GENERAL layout for color attachment
8282 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
8283 m_errorMonitor->SetDesiredFailureMsg(
8284 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8285 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
8286 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8287 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06008288 // For this error we need a valid renderpass so create default one
8289 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8290 attach.attachment = 0;
8291 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
8292 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8293 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8294 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8295 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8296 // Can't do a CLEAR load on READ_ONLY initialLayout
8297 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8298 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
8299 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8301 " with invalid first layout "
8302 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
8303 "ONLY_OPTIMAL");
8304 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8305 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06008306
8307 vkDestroyImage(m_device->device(), src_image, NULL);
8308 vkDestroyImage(m_device->device(), dst_image, NULL);
8309}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008310#endif // DRAW_STATE_TESTS
8311
Tobin Ehlis0788f522015-05-26 16:11:58 -06008312#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06008313#if GTEST_IS_THREADSAFE
8314struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008315 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008316 VkEvent event;
8317 bool bailout;
8318};
8319
Karl Schultz6addd812016-02-02 17:17:23 -07008320extern "C" void *AddToCommandBuffer(void *arg) {
8321 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008322
Karl Schultz6addd812016-02-02 17:17:23 -07008323 for (int i = 0; i < 10000; i++) {
8324 vkCmdSetEvent(data->commandBuffer, data->event,
8325 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008326 if (data->bailout) {
8327 break;
8328 }
8329 }
8330 return NULL;
8331}
8332
Karl Schultz6addd812016-02-02 17:17:23 -07008333TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008334 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008335
Karl Schultz6addd812016-02-02 17:17:23 -07008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8337 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008338
Mike Stroyanaccf7692015-05-12 16:00:45 -06008339 ASSERT_NO_FATAL_FAILURE(InitState());
8340 ASSERT_NO_FATAL_FAILURE(InitViewport());
8341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008343 // Calls AllocateCommandBuffers
8344 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008345
8346 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008347 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008348
8349 VkEventCreateInfo event_info;
8350 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06008351 VkResult err;
8352
8353 memset(&event_info, 0, sizeof(event_info));
8354 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8355
Chia-I Wuf7458c52015-10-26 21:10:41 +08008356 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008357 ASSERT_VK_SUCCESS(err);
8358
Mike Stroyanaccf7692015-05-12 16:00:45 -06008359 err = vkResetEvent(device(), event);
8360 ASSERT_VK_SUCCESS(err);
8361
8362 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008363 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008364 data.event = event;
8365 data.bailout = false;
8366 m_errorMonitor->SetBailout(&data.bailout);
8367 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008368 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008369 // Add many entries to command buffer from this thread at the same time.
8370 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06008371
Mike Stroyan4268d1f2015-07-13 14:45:35 -06008372 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008373 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008374
Mike Stroyan10b8cb72016-01-22 15:22:03 -07008375 m_errorMonitor->SetBailout(NULL);
8376
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008377 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06008378
Chia-I Wuf7458c52015-10-26 21:10:41 +08008379 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06008380}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008381#endif // GTEST_IS_THREADSAFE
8382#endif // THREADING_TESTS
8383
Chris Forbes9f7ff632015-05-25 11:13:08 +12008384#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008385TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008387 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008388
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008389 ASSERT_NO_FATAL_FAILURE(InitState());
8390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8391
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008392 VkShaderModule module;
8393 VkShaderModuleCreateInfo moduleCreateInfo;
8394 struct icd_spv_header spv;
8395
8396 spv.magic = ICD_SPV_MAGIC;
8397 spv.version = ICD_SPV_VERSION;
8398 spv.gen_magic = 0;
8399
8400 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8401 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008402 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008403 moduleCreateInfo.codeSize = 4;
8404 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008405 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008407 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008408}
8409
Karl Schultz6addd812016-02-02 17:17:23 -07008410TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008412 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008413
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008414 ASSERT_NO_FATAL_FAILURE(InitState());
8415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8416
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008417 VkShaderModule module;
8418 VkShaderModuleCreateInfo moduleCreateInfo;
8419 struct icd_spv_header spv;
8420
8421 spv.magic = ~ICD_SPV_MAGIC;
8422 spv.version = ICD_SPV_VERSION;
8423 spv.gen_magic = 0;
8424
8425 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8426 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008427 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008428 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8429 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008430 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008432 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008433}
8434
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008435#if 0
8436// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07008437TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008439 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008440
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008441 ASSERT_NO_FATAL_FAILURE(InitState());
8442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8443
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008444 VkShaderModule module;
8445 VkShaderModuleCreateInfo moduleCreateInfo;
8446 struct icd_spv_header spv;
8447
8448 spv.magic = ICD_SPV_MAGIC;
8449 spv.version = ~ICD_SPV_VERSION;
8450 spv.gen_magic = 0;
8451
8452 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
8453 moduleCreateInfo.pNext = NULL;
8454
Karl Schultz6addd812016-02-02 17:17:23 -07008455 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008456 moduleCreateInfo.codeSize = sizeof(spv) + 10;
8457 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008458 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008459
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008460 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008461}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12008462#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06008463
Karl Schultz6addd812016-02-02 17:17:23 -07008464TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008466 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008467
Chris Forbes9f7ff632015-05-25 11:13:08 +12008468 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008470
8471 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008472 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008473 "\n"
8474 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008475 "out gl_PerVertex {\n"
8476 " vec4 gl_Position;\n"
8477 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008478 "void main(){\n"
8479 " gl_Position = vec4(1);\n"
8480 " x = 0;\n"
8481 "}\n";
8482 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008483 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12008484 "\n"
8485 "layout(location=0) out vec4 color;\n"
8486 "void main(){\n"
8487 " color = vec4(1);\n"
8488 "}\n";
8489
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008492
8493 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008494 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008495 pipe.AddShader(&vs);
8496 pipe.AddShader(&fs);
8497
Chris Forbes9f7ff632015-05-25 11:13:08 +12008498 VkDescriptorSetObj descriptorSet(m_device);
8499 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12008501
Tony Barbour5781e8f2015-08-04 16:23:11 -06008502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12008503
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008504 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12008505}
Chris Forbes9f7ff632015-05-25 11:13:08 +12008506
Karl Schultz6addd812016-02-02 17:17:23 -07008507TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008509 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008510
Chris Forbes59cb88d2015-05-25 11:13:13 +12008511 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008512 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008513
8514 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008515 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008516 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008517 "out gl_PerVertex {\n"
8518 " vec4 gl_Position;\n"
8519 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008520 "void main(){\n"
8521 " gl_Position = vec4(1);\n"
8522 "}\n";
8523 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008524 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12008525 "\n"
8526 "layout(location=0) in float x;\n"
8527 "layout(location=0) out vec4 color;\n"
8528 "void main(){\n"
8529 " color = vec4(x);\n"
8530 "}\n";
8531
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008532 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8533 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008534
8535 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008536 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008537 pipe.AddShader(&vs);
8538 pipe.AddShader(&fs);
8539
Chris Forbes59cb88d2015-05-25 11:13:13 +12008540 VkDescriptorSetObj descriptorSet(m_device);
8541 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008542 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12008543
Tony Barbour5781e8f2015-08-04 16:23:11 -06008544 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12008545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008546 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12008547}
8548
Karl Schultz6addd812016-02-02 17:17:23 -07008549TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008551 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008552
8553 ASSERT_NO_FATAL_FAILURE(InitState());
8554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8555
8556 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008557 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008558 "\n"
8559 "out gl_PerVertex {\n"
8560 " vec4 gl_Position;\n"
8561 "};\n"
8562 "void main(){\n"
8563 " gl_Position = vec4(1);\n"
8564 "}\n";
8565 char const *fsSource =
8566 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008567 "\n"
8568 "in block { layout(location=0) float x; } ins;\n"
8569 "layout(location=0) out vec4 color;\n"
8570 "void main(){\n"
8571 " color = vec4(ins.x);\n"
8572 "}\n";
8573
8574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8576
8577 VkPipelineObj pipe(m_device);
8578 pipe.AddColorAttachment();
8579 pipe.AddShader(&vs);
8580 pipe.AddShader(&fs);
8581
8582 VkDescriptorSetObj descriptorSet(m_device);
8583 descriptorSet.AppendDummy();
8584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8585
8586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8587
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008588 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008589}
8590
Karl Schultz6addd812016-02-02 17:17:23 -07008591TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13008592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13008593 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07008594 "output arr[2] of float32' vs 'ptr to "
8595 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13008596
8597 ASSERT_NO_FATAL_FAILURE(InitState());
8598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8599
8600 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008601 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008602 "\n"
8603 "layout(location=0) out float x[2];\n"
8604 "out gl_PerVertex {\n"
8605 " vec4 gl_Position;\n"
8606 "};\n"
8607 "void main(){\n"
8608 " x[0] = 0; x[1] = 0;\n"
8609 " gl_Position = vec4(1);\n"
8610 "}\n";
8611 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008612 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13008613 "\n"
8614 "layout(location=0) in float x[3];\n"
8615 "layout(location=0) out vec4 color;\n"
8616 "void main(){\n"
8617 " color = vec4(x[0] + x[1] + x[2]);\n"
8618 "}\n";
8619
8620 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8621 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8622
8623 VkPipelineObj pipe(m_device);
8624 pipe.AddColorAttachment();
8625 pipe.AddShader(&vs);
8626 pipe.AddShader(&fs);
8627
8628 VkDescriptorSetObj descriptorSet(m_device);
8629 descriptorSet.AppendDummy();
8630 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8631
8632 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8633
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008634 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13008635}
8636
Karl Schultz6addd812016-02-02 17:17:23 -07008637TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008639 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008640
Chris Forbesb56af562015-05-25 11:13:17 +12008641 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12008643
8644 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008645 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008646 "\n"
8647 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07008648 "out gl_PerVertex {\n"
8649 " vec4 gl_Position;\n"
8650 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008651 "void main(){\n"
8652 " x = 0;\n"
8653 " gl_Position = vec4(1);\n"
8654 "}\n";
8655 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008656 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12008657 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008658 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12008659 "layout(location=0) out vec4 color;\n"
8660 "void main(){\n"
8661 " color = vec4(x);\n"
8662 "}\n";
8663
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008664 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8665 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12008666
8667 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008668 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12008669 pipe.AddShader(&vs);
8670 pipe.AddShader(&fs);
8671
Chris Forbesb56af562015-05-25 11:13:17 +12008672 VkDescriptorSetObj descriptorSet(m_device);
8673 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008674 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12008675
Tony Barbour5781e8f2015-08-04 16:23:11 -06008676 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12008677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008678 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12008679}
8680
Karl Schultz6addd812016-02-02 17:17:23 -07008681TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13008682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008683 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13008684
8685 ASSERT_NO_FATAL_FAILURE(InitState());
8686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8687
8688 char const *vsSource =
8689 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008690 "\n"
8691 "out block { layout(location=0) int x; } outs;\n"
8692 "out gl_PerVertex {\n"
8693 " vec4 gl_Position;\n"
8694 "};\n"
8695 "void main(){\n"
8696 " outs.x = 0;\n"
8697 " gl_Position = vec4(1);\n"
8698 "}\n";
8699 char const *fsSource =
8700 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13008701 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008702 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13008703 "layout(location=0) out vec4 color;\n"
8704 "void main(){\n"
8705 " color = vec4(ins.x);\n"
8706 "}\n";
8707
8708 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8709 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8710
8711 VkPipelineObj pipe(m_device);
8712 pipe.AddColorAttachment();
8713 pipe.AddShader(&vs);
8714 pipe.AddShader(&fs);
8715
8716 VkDescriptorSetObj descriptorSet(m_device);
8717 descriptorSet.AppendDummy();
8718 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8719
8720 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8721
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008722 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008723}
8724
8725TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
8726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8727 "location 0.0 which is not written by vertex shader");
8728
8729 ASSERT_NO_FATAL_FAILURE(InitState());
8730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8731
8732 char const *vsSource =
8733 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008734 "\n"
8735 "out block { layout(location=1) float x; } outs;\n"
8736 "out gl_PerVertex {\n"
8737 " vec4 gl_Position;\n"
8738 "};\n"
8739 "void main(){\n"
8740 " outs.x = 0;\n"
8741 " gl_Position = vec4(1);\n"
8742 "}\n";
8743 char const *fsSource =
8744 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008745 "\n"
8746 "in block { layout(location=0) float x; } ins;\n"
8747 "layout(location=0) out vec4 color;\n"
8748 "void main(){\n"
8749 " color = vec4(ins.x);\n"
8750 "}\n";
8751
8752 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8753 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8754
8755 VkPipelineObj pipe(m_device);
8756 pipe.AddColorAttachment();
8757 pipe.AddShader(&vs);
8758 pipe.AddShader(&fs);
8759
8760 VkDescriptorSetObj descriptorSet(m_device);
8761 descriptorSet.AppendDummy();
8762 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8763
8764 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8765
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008766 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13008767}
8768
8769TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
8770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8771 "location 0.1 which is not written by vertex shader");
8772
8773 ASSERT_NO_FATAL_FAILURE(InitState());
8774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8775
8776 char const *vsSource =
8777 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008778 "\n"
8779 "out block { layout(location=0, component=0) float x; } outs;\n"
8780 "out gl_PerVertex {\n"
8781 " vec4 gl_Position;\n"
8782 "};\n"
8783 "void main(){\n"
8784 " outs.x = 0;\n"
8785 " gl_Position = vec4(1);\n"
8786 "}\n";
8787 char const *fsSource =
8788 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13008789 "\n"
8790 "in block { layout(location=0, component=1) float x; } ins;\n"
8791 "layout(location=0) out vec4 color;\n"
8792 "void main(){\n"
8793 " color = vec4(ins.x);\n"
8794 "}\n";
8795
8796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8798
8799 VkPipelineObj pipe(m_device);
8800 pipe.AddColorAttachment();
8801 pipe.AddShader(&vs);
8802 pipe.AddShader(&fs);
8803
8804 VkDescriptorSetObj descriptorSet(m_device);
8805 descriptorSet.AppendDummy();
8806 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8807
8808 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8809
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008810 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13008811}
8812
Karl Schultz6addd812016-02-02 17:17:23 -07008813TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008815 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008816
Chris Forbesde136e02015-05-25 11:13:28 +12008817 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008818 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12008819
8820 VkVertexInputBindingDescription input_binding;
8821 memset(&input_binding, 0, sizeof(input_binding));
8822
8823 VkVertexInputAttributeDescription input_attrib;
8824 memset(&input_attrib, 0, sizeof(input_attrib));
8825 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8826
8827 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008828 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008829 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008830 "out gl_PerVertex {\n"
8831 " vec4 gl_Position;\n"
8832 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008833 "void main(){\n"
8834 " gl_Position = vec4(1);\n"
8835 "}\n";
8836 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008837 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12008838 "\n"
8839 "layout(location=0) out vec4 color;\n"
8840 "void main(){\n"
8841 " color = vec4(1);\n"
8842 "}\n";
8843
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008844 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8845 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12008846
8847 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008848 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12008849 pipe.AddShader(&vs);
8850 pipe.AddShader(&fs);
8851
8852 pipe.AddVertexInputBindings(&input_binding, 1);
8853 pipe.AddVertexInputAttribs(&input_attrib, 1);
8854
Chris Forbesde136e02015-05-25 11:13:28 +12008855 VkDescriptorSetObj descriptorSet(m_device);
8856 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12008858
Tony Barbour5781e8f2015-08-04 16:23:11 -06008859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12008860
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008861 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12008862}
8863
Karl Schultz6addd812016-02-02 17:17:23 -07008864TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008866 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13008867
8868 ASSERT_NO_FATAL_FAILURE(InitState());
8869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8870
8871 VkVertexInputBindingDescription input_binding;
8872 memset(&input_binding, 0, sizeof(input_binding));
8873
8874 VkVertexInputAttributeDescription input_attrib;
8875 memset(&input_attrib, 0, sizeof(input_attrib));
8876 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8877
8878 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008879 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008880 "\n"
8881 "layout(location=1) in float x;\n"
8882 "out gl_PerVertex {\n"
8883 " vec4 gl_Position;\n"
8884 "};\n"
8885 "void main(){\n"
8886 " gl_Position = vec4(x);\n"
8887 "}\n";
8888 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008889 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13008890 "\n"
8891 "layout(location=0) out vec4 color;\n"
8892 "void main(){\n"
8893 " color = vec4(1);\n"
8894 "}\n";
8895
8896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8898
8899 VkPipelineObj pipe(m_device);
8900 pipe.AddColorAttachment();
8901 pipe.AddShader(&vs);
8902 pipe.AddShader(&fs);
8903
8904 pipe.AddVertexInputBindings(&input_binding, 1);
8905 pipe.AddVertexInputAttribs(&input_attrib, 1);
8906
8907 VkDescriptorSetObj descriptorSet(m_device);
8908 descriptorSet.AppendDummy();
8909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8910
8911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8912
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008913 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13008914}
8915
Karl Schultz6addd812016-02-02 17:17:23 -07008916TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
8917 m_errorMonitor->SetDesiredFailureMsg(
8918 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008919 "VS consumes input at location 0 but not provided");
8920
Chris Forbes62e8e502015-05-25 11:13:29 +12008921 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12008923
8924 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008925 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008926 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008927 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07008928 "out gl_PerVertex {\n"
8929 " vec4 gl_Position;\n"
8930 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008931 "void main(){\n"
8932 " gl_Position = x;\n"
8933 "}\n";
8934 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008935 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12008936 "\n"
8937 "layout(location=0) out vec4 color;\n"
8938 "void main(){\n"
8939 " color = vec4(1);\n"
8940 "}\n";
8941
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12008944
8945 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008946 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12008947 pipe.AddShader(&vs);
8948 pipe.AddShader(&fs);
8949
Chris Forbes62e8e502015-05-25 11:13:29 +12008950 VkDescriptorSetObj descriptorSet(m_device);
8951 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12008953
Tony Barbour5781e8f2015-08-04 16:23:11 -06008954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12008955
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008956 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12008957}
8958
Karl Schultz6addd812016-02-02 17:17:23 -07008959TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
8960 m_errorMonitor->SetDesiredFailureMsg(
8961 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008962 "location 0 does not match VS input type");
8963
Chris Forbesc97d98e2015-05-25 11:13:31 +12008964 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12008966
8967 VkVertexInputBindingDescription input_binding;
8968 memset(&input_binding, 0, sizeof(input_binding));
8969
8970 VkVertexInputAttributeDescription input_attrib;
8971 memset(&input_attrib, 0, sizeof(input_attrib));
8972 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8973
8974 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008975 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008976 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008977 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07008978 "out gl_PerVertex {\n"
8979 " vec4 gl_Position;\n"
8980 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008981 "void main(){\n"
8982 " gl_Position = vec4(x);\n"
8983 "}\n";
8984 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008985 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12008986 "\n"
8987 "layout(location=0) out vec4 color;\n"
8988 "void main(){\n"
8989 " color = vec4(1);\n"
8990 "}\n";
8991
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008992 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8993 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12008994
8995 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008996 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12008997 pipe.AddShader(&vs);
8998 pipe.AddShader(&fs);
8999
9000 pipe.AddVertexInputBindings(&input_binding, 1);
9001 pipe.AddVertexInputAttribs(&input_attrib, 1);
9002
Chris Forbesc97d98e2015-05-25 11:13:31 +12009003 VkDescriptorSetObj descriptorSet(m_device);
9004 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12009006
Tony Barbour5781e8f2015-08-04 16:23:11 -06009007 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12009008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009009 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12009010}
9011
Chris Forbesc68b43c2016-04-06 11:18:47 +12009012TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
9013 m_errorMonitor->SetDesiredFailureMsg(
9014 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9015 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
9016
9017 ASSERT_NO_FATAL_FAILURE(InitState());
9018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9019
9020 char const *vsSource =
9021 "#version 450\n"
9022 "\n"
9023 "out gl_PerVertex {\n"
9024 " vec4 gl_Position;\n"
9025 "};\n"
9026 "void main(){\n"
9027 " gl_Position = vec4(1);\n"
9028 "}\n";
9029 char const *fsSource =
9030 "#version 450\n"
9031 "\n"
9032 "layout(location=0) out vec4 color;\n"
9033 "void main(){\n"
9034 " color = vec4(1);\n"
9035 "}\n";
9036
9037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9039
9040 VkPipelineObj pipe(m_device);
9041 pipe.AddColorAttachment();
9042 pipe.AddShader(&vs);
9043 pipe.AddShader(&vs);
9044 pipe.AddShader(&fs);
9045
9046 VkDescriptorSetObj descriptorSet(m_device);
9047 descriptorSet.AppendDummy();
9048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9049
9050 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9051
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009052 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12009053}
9054
Karl Schultz6addd812016-02-02 17:17:23 -07009055TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009056 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009057
9058 ASSERT_NO_FATAL_FAILURE(InitState());
9059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9060
9061 VkVertexInputBindingDescription input_binding;
9062 memset(&input_binding, 0, sizeof(input_binding));
9063
9064 VkVertexInputAttributeDescription input_attribs[2];
9065 memset(input_attribs, 0, sizeof(input_attribs));
9066
9067 for (int i = 0; i < 2; i++) {
9068 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9069 input_attribs[i].location = i;
9070 }
9071
9072 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009073 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009074 "\n"
9075 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009076 "out gl_PerVertex {\n"
9077 " vec4 gl_Position;\n"
9078 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009079 "void main(){\n"
9080 " gl_Position = x[0] + x[1];\n"
9081 "}\n";
9082 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009083 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009084 "\n"
9085 "layout(location=0) out vec4 color;\n"
9086 "void main(){\n"
9087 " color = vec4(1);\n"
9088 "}\n";
9089
9090 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9091 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9092
9093 VkPipelineObj pipe(m_device);
9094 pipe.AddColorAttachment();
9095 pipe.AddShader(&vs);
9096 pipe.AddShader(&fs);
9097
9098 pipe.AddVertexInputBindings(&input_binding, 1);
9099 pipe.AddVertexInputAttribs(input_attribs, 2);
9100
9101 VkDescriptorSetObj descriptorSet(m_device);
9102 descriptorSet.AppendDummy();
9103 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9104
9105 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9106
9107 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009108 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009109}
9110
Chris Forbes2682b242015-11-24 11:13:14 +13009111TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
9112{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009113 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13009114
9115 ASSERT_NO_FATAL_FAILURE(InitState());
9116 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9117
9118 VkVertexInputBindingDescription input_binding;
9119 memset(&input_binding, 0, sizeof(input_binding));
9120
9121 VkVertexInputAttributeDescription input_attribs[2];
9122 memset(input_attribs, 0, sizeof(input_attribs));
9123
9124 for (int i = 0; i < 2; i++) {
9125 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
9126 input_attribs[i].location = i;
9127 }
9128
9129 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009130 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009131 "\n"
9132 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07009133 "out gl_PerVertex {\n"
9134 " vec4 gl_Position;\n"
9135 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009136 "void main(){\n"
9137 " gl_Position = x[0] + x[1];\n"
9138 "}\n";
9139 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009140 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13009141 "\n"
9142 "layout(location=0) out vec4 color;\n"
9143 "void main(){\n"
9144 " color = vec4(1);\n"
9145 "}\n";
9146
9147 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9148 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9149
9150 VkPipelineObj pipe(m_device);
9151 pipe.AddColorAttachment();
9152 pipe.AddShader(&vs);
9153 pipe.AddShader(&fs);
9154
9155 pipe.AddVertexInputBindings(&input_binding, 1);
9156 pipe.AddVertexInputAttribs(input_attribs, 2);
9157
9158 VkDescriptorSetObj descriptorSet(m_device);
9159 descriptorSet.AppendDummy();
9160 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9161
9162 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009164 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13009165}
Chris Forbes2682b242015-11-24 11:13:14 +13009166
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009167TEST_F(VkLayerTest, CreatePipelineSimplePositive)
9168{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009169 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009170
9171 ASSERT_NO_FATAL_FAILURE(InitState());
9172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9173
9174 char const *vsSource =
9175 "#version 450\n"
9176 "out gl_PerVertex {\n"
9177 " vec4 gl_Position;\n"
9178 "};\n"
9179 "void main(){\n"
9180 " gl_Position = vec4(0);\n"
9181 "}\n";
9182 char const *fsSource =
9183 "#version 450\n"
9184 "\n"
9185 "layout(location=0) out vec4 color;\n"
9186 "void main(){\n"
9187 " color = vec4(1);\n"
9188 "}\n";
9189
9190 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9191 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9192
9193 VkPipelineObj pipe(m_device);
9194 pipe.AddColorAttachment();
9195 pipe.AddShader(&vs);
9196 pipe.AddShader(&fs);
9197
9198 VkDescriptorSetObj descriptorSet(m_device);
9199 descriptorSet.AppendDummy();
9200 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9201
9202 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9203
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009204 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009205}
9206
Chris Forbes912c9192016-04-05 17:50:35 +12009207TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
9208{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009209 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12009210
9211 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
9212
9213 ASSERT_NO_FATAL_FAILURE(InitState());
9214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9215
9216 char const *vsSource =
9217 "#version 450\n"
9218 "out gl_PerVertex {\n"
9219 " vec4 gl_Position;\n"
9220 "};\n"
9221 "layout(location=0) out vec3 x;\n"
9222 "layout(location=1) out ivec3 y;\n"
9223 "layout(location=2) out vec3 z;\n"
9224 "void main(){\n"
9225 " gl_Position = vec4(0);\n"
9226 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
9227 "}\n";
9228 char const *fsSource =
9229 "#version 450\n"
9230 "\n"
9231 "layout(location=0) out vec4 color;\n"
9232 "layout(location=0) in float x;\n"
9233 "layout(location=1) flat in int y;\n"
9234 "layout(location=2) in vec2 z;\n"
9235 "void main(){\n"
9236 " color = vec4(1 + x + y + z.x);\n"
9237 "}\n";
9238
9239 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9240 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9241
9242 VkPipelineObj pipe(m_device);
9243 pipe.AddColorAttachment();
9244 pipe.AddShader(&vs);
9245 pipe.AddShader(&fs);
9246
9247 VkDescriptorSetObj descriptorSet(m_device);
9248 descriptorSet.AppendDummy();
9249 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9250
9251 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9252
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009253 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12009254}
9255
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009256TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
9257{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009258 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009259
9260 ASSERT_NO_FATAL_FAILURE(InitState());
9261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9262
Chris Forbesc1e852d2016-04-04 19:26:42 +12009263 if (!m_device->phy().features().tessellationShader) {
9264 printf("Device does not support tessellation shaders; skipped.\n");
9265 return;
9266 }
9267
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009268 char const *vsSource =
9269 "#version 450\n"
9270 "void main(){}\n";
9271 char const *tcsSource =
9272 "#version 450\n"
9273 "layout(location=0) out int x[];\n"
9274 "layout(vertices=3) out;\n"
9275 "void main(){\n"
9276 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9277 " gl_TessLevelInner[0] = 1;\n"
9278 " x[gl_InvocationID] = gl_InvocationID;\n"
9279 "}\n";
9280 char const *tesSource =
9281 "#version 450\n"
9282 "layout(triangles, equal_spacing, cw) in;\n"
9283 "layout(location=0) in int x[];\n"
9284 "out gl_PerVertex { vec4 gl_Position; };\n"
9285 "void main(){\n"
9286 " gl_Position.xyz = gl_TessCoord;\n"
9287 " gl_Position.w = x[0] + x[1] + x[2];\n"
9288 "}\n";
9289 char const *fsSource =
9290 "#version 450\n"
9291 "layout(location=0) out vec4 color;\n"
9292 "void main(){\n"
9293 " color = vec4(1);\n"
9294 "}\n";
9295
9296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9297 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9298 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9299 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9300
9301 VkPipelineInputAssemblyStateCreateInfo iasci{
9302 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9303 nullptr,
9304 0,
9305 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9306 VK_FALSE};
9307
Chris Forbesb4cacb62016-04-04 19:15:00 +12009308 VkPipelineTessellationStateCreateInfo tsci{
9309 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9310 nullptr,
9311 0,
9312 3};
9313
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009314 VkPipelineObj pipe(m_device);
9315 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12009316 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009317 pipe.AddColorAttachment();
9318 pipe.AddShader(&vs);
9319 pipe.AddShader(&tcs);
9320 pipe.AddShader(&tes);
9321 pipe.AddShader(&fs);
9322
9323 VkDescriptorSetObj descriptorSet(m_device);
9324 descriptorSet.AppendDummy();
9325 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9326
9327 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9328
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009329 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12009330}
9331
Chris Forbesa0ab8152016-04-20 13:34:27 +12009332TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
9333{
9334 m_errorMonitor->ExpectSuccess();
9335
9336 ASSERT_NO_FATAL_FAILURE(InitState());
9337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9338
9339 if (!m_device->phy().features().geometryShader) {
9340 printf("Device does not support geometry shaders; skipped.\n");
9341 return;
9342 }
9343
9344 char const *vsSource =
9345 "#version 450\n"
9346 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
9347 "void main(){\n"
9348 " vs_out.x = vec4(1);\n"
9349 "}\n";
9350 char const *gsSource =
9351 "#version 450\n"
9352 "layout(triangles) in;\n"
9353 "layout(triangle_strip, max_vertices=3) out;\n"
9354 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
9355 "out gl_PerVertex { vec4 gl_Position; };\n"
9356 "void main() {\n"
9357 " gl_Position = gs_in[0].x;\n"
9358 " EmitVertex();\n"
9359 "}\n";
9360 char const *fsSource =
9361 "#version 450\n"
9362 "layout(location=0) out vec4 color;\n"
9363 "void main(){\n"
9364 " color = vec4(1);\n"
9365 "}\n";
9366
9367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9368 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
9369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9370
9371 VkPipelineObj pipe(m_device);
9372 pipe.AddColorAttachment();
9373 pipe.AddShader(&vs);
9374 pipe.AddShader(&gs);
9375 pipe.AddShader(&fs);
9376
9377 VkDescriptorSetObj descriptorSet(m_device);
9378 descriptorSet.AppendDummy();
9379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9380
9381 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9382
9383 m_errorMonitor->VerifyNotFound();
9384}
9385
Chris Forbesa0193bc2016-04-04 19:19:47 +12009386TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
9387{
9388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9389 "is per-vertex in tessellation control shader stage "
9390 "but per-patch in tessellation evaluation shader stage");
9391
9392 ASSERT_NO_FATAL_FAILURE(InitState());
9393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9394
Chris Forbesc1e852d2016-04-04 19:26:42 +12009395 if (!m_device->phy().features().tessellationShader) {
9396 printf("Device does not support tessellation shaders; skipped.\n");
9397 return;
9398 }
9399
Chris Forbesa0193bc2016-04-04 19:19:47 +12009400 char const *vsSource =
9401 "#version 450\n"
9402 "void main(){}\n";
9403 char const *tcsSource =
9404 "#version 450\n"
9405 "layout(location=0) out int x[];\n"
9406 "layout(vertices=3) out;\n"
9407 "void main(){\n"
9408 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
9409 " gl_TessLevelInner[0] = 1;\n"
9410 " x[gl_InvocationID] = gl_InvocationID;\n"
9411 "}\n";
9412 char const *tesSource =
9413 "#version 450\n"
9414 "layout(triangles, equal_spacing, cw) in;\n"
9415 "layout(location=0) patch in int x;\n"
9416 "out gl_PerVertex { vec4 gl_Position; };\n"
9417 "void main(){\n"
9418 " gl_Position.xyz = gl_TessCoord;\n"
9419 " gl_Position.w = x;\n"
9420 "}\n";
9421 char const *fsSource =
9422 "#version 450\n"
9423 "layout(location=0) out vec4 color;\n"
9424 "void main(){\n"
9425 " color = vec4(1);\n"
9426 "}\n";
9427
9428 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9429 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
9430 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
9431 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9432
9433 VkPipelineInputAssemblyStateCreateInfo iasci{
9434 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
9435 nullptr,
9436 0,
9437 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
9438 VK_FALSE};
9439
9440 VkPipelineTessellationStateCreateInfo tsci{
9441 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
9442 nullptr,
9443 0,
9444 3};
9445
9446 VkPipelineObj pipe(m_device);
9447 pipe.SetInputAssembly(&iasci);
9448 pipe.SetTessellation(&tsci);
9449 pipe.AddColorAttachment();
9450 pipe.AddShader(&vs);
9451 pipe.AddShader(&tcs);
9452 pipe.AddShader(&tes);
9453 pipe.AddShader(&fs);
9454
9455 VkDescriptorSetObj descriptorSet(m_device);
9456 descriptorSet.AppendDummy();
9457 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9458
9459 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9460
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009461 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12009462}
9463
Karl Schultz6addd812016-02-02 17:17:23 -07009464TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
9465 m_errorMonitor->SetDesiredFailureMsg(
9466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009467 "Duplicate vertex input binding descriptions for binding 0");
9468
Chris Forbes280ba2c2015-06-12 11:16:41 +12009469 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009471
9472 /* Two binding descriptions for binding 0 */
9473 VkVertexInputBindingDescription input_bindings[2];
9474 memset(input_bindings, 0, sizeof(input_bindings));
9475
9476 VkVertexInputAttributeDescription input_attrib;
9477 memset(&input_attrib, 0, sizeof(input_attrib));
9478 input_attrib.format = VK_FORMAT_R32_SFLOAT;
9479
9480 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009481 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009482 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009483 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07009484 "out gl_PerVertex {\n"
9485 " vec4 gl_Position;\n"
9486 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009487 "void main(){\n"
9488 " gl_Position = vec4(x);\n"
9489 "}\n";
9490 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009491 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12009492 "\n"
9493 "layout(location=0) out vec4 color;\n"
9494 "void main(){\n"
9495 " color = vec4(1);\n"
9496 "}\n";
9497
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009500
9501 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009502 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009503 pipe.AddShader(&vs);
9504 pipe.AddShader(&fs);
9505
9506 pipe.AddVertexInputBindings(input_bindings, 2);
9507 pipe.AddVertexInputAttribs(&input_attrib, 1);
9508
Chris Forbes280ba2c2015-06-12 11:16:41 +12009509 VkDescriptorSetObj descriptorSet(m_device);
9510 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009511 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12009512
Tony Barbour5781e8f2015-08-04 16:23:11 -06009513 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12009514
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009515 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12009516}
Chris Forbes8f68b562015-05-25 11:13:32 +12009517
Chris Forbes35efec72016-04-21 14:32:08 +12009518TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
9519 m_errorMonitor->ExpectSuccess();
9520
9521 ASSERT_NO_FATAL_FAILURE(InitState());
9522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9523
9524 if (!m_device->phy().features().tessellationShader) {
9525 printf("Device does not support 64bit vertex attributes; skipped.\n");
9526 return;
9527 }
9528
9529 VkVertexInputBindingDescription input_bindings[1];
9530 memset(input_bindings, 0, sizeof(input_bindings));
9531
9532 VkVertexInputAttributeDescription input_attribs[4];
9533 memset(input_attribs, 0, sizeof(input_attribs));
9534 input_attribs[0].location = 0;
9535 input_attribs[0].offset = 0;
9536 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9537 input_attribs[1].location = 2;
9538 input_attribs[1].offset = 32;
9539 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9540 input_attribs[2].location = 4;
9541 input_attribs[2].offset = 64;
9542 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9543 input_attribs[3].location = 6;
9544 input_attribs[3].offset = 96;
9545 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
9546
9547 char const *vsSource =
9548 "#version 450\n"
9549 "\n"
9550 "layout(location=0) in dmat4 x;\n"
9551 "out gl_PerVertex {\n"
9552 " vec4 gl_Position;\n"
9553 "};\n"
9554 "void main(){\n"
9555 " gl_Position = vec4(x[0][0]);\n"
9556 "}\n";
9557 char const *fsSource =
9558 "#version 450\n"
9559 "\n"
9560 "layout(location=0) out vec4 color;\n"
9561 "void main(){\n"
9562 " color = vec4(1);\n"
9563 "}\n";
9564
9565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9567
9568 VkPipelineObj pipe(m_device);
9569 pipe.AddColorAttachment();
9570 pipe.AddShader(&vs);
9571 pipe.AddShader(&fs);
9572
9573 pipe.AddVertexInputBindings(input_bindings, 1);
9574 pipe.AddVertexInputAttribs(input_attribs, 4);
9575
9576 VkDescriptorSetObj descriptorSet(m_device);
9577 descriptorSet.AppendDummy();
9578 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9579
9580 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9581
9582 m_errorMonitor->VerifyNotFound();
9583}
9584
Karl Schultz6addd812016-02-02 17:17:23 -07009585TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009587 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009588
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009589 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009590
9591 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009592 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009593 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009594 "out gl_PerVertex {\n"
9595 " vec4 gl_Position;\n"
9596 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009597 "void main(){\n"
9598 " gl_Position = vec4(1);\n"
9599 "}\n";
9600 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009601 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009602 "\n"
9603 "void main(){\n"
9604 "}\n";
9605
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009608
9609 VkPipelineObj pipe(m_device);
9610 pipe.AddShader(&vs);
9611 pipe.AddShader(&fs);
9612
Chia-I Wu08accc62015-07-07 11:50:03 +08009613 /* set up CB 0, not written */
9614 pipe.AddColorAttachment();
9615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009616
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009617 VkDescriptorSetObj descriptorSet(m_device);
9618 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009619 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009620
Tony Barbour5781e8f2015-08-04 16:23:11 -06009621 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009622
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009623 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12009624}
9625
Karl Schultz6addd812016-02-02 17:17:23 -07009626TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07009627 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009628 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009629 "FS writes to output location 1 with no matching attachment");
9630
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009631 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009632
9633 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009634 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009635 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009636 "out gl_PerVertex {\n"
9637 " vec4 gl_Position;\n"
9638 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009639 "void main(){\n"
9640 " gl_Position = vec4(1);\n"
9641 "}\n";
9642 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009643 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009644 "\n"
9645 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009646 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009647 "void main(){\n"
9648 " x = vec4(1);\n"
9649 " y = vec4(1);\n"
9650 "}\n";
9651
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009652 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9653 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009654
9655 VkPipelineObj pipe(m_device);
9656 pipe.AddShader(&vs);
9657 pipe.AddShader(&fs);
9658
Chia-I Wu08accc62015-07-07 11:50:03 +08009659 /* set up CB 0, not written */
9660 pipe.AddColorAttachment();
9661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009662 /* FS writes CB 1, but we don't configure it */
9663
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009664 VkDescriptorSetObj descriptorSet(m_device);
9665 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009666 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009667
Tony Barbour5781e8f2015-08-04 16:23:11 -06009668 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009670 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12009671}
9672
Karl Schultz6addd812016-02-02 17:17:23 -07009673TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009675 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009676
Chris Forbesa36d69e2015-05-25 11:13:44 +12009677 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009678
9679 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009680 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009681 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009682 "out gl_PerVertex {\n"
9683 " vec4 gl_Position;\n"
9684 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009685 "void main(){\n"
9686 " gl_Position = vec4(1);\n"
9687 "}\n";
9688 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009689 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12009690 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009691 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12009692 "void main(){\n"
9693 " x = ivec4(1);\n"
9694 "}\n";
9695
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009698
9699 VkPipelineObj pipe(m_device);
9700 pipe.AddShader(&vs);
9701 pipe.AddShader(&fs);
9702
Chia-I Wu08accc62015-07-07 11:50:03 +08009703 /* set up CB 0; type is UNORM by default */
9704 pipe.AddColorAttachment();
9705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009706
Chris Forbesa36d69e2015-05-25 11:13:44 +12009707 VkDescriptorSetObj descriptorSet(m_device);
9708 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009709 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12009710
Tony Barbour5781e8f2015-08-04 16:23:11 -06009711 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12009712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009713 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12009714}
Chris Forbes7b1b8932015-06-05 14:43:36 +12009715
Karl Schultz6addd812016-02-02 17:17:23 -07009716TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009718 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009719
Chris Forbes556c76c2015-08-14 12:04:59 +12009720 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12009721
9722 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009723 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009724 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009725 "out gl_PerVertex {\n"
9726 " vec4 gl_Position;\n"
9727 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009728 "void main(){\n"
9729 " gl_Position = vec4(1);\n"
9730 "}\n";
9731 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009732 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12009733 "\n"
9734 "layout(location=0) out vec4 x;\n"
9735 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
9736 "void main(){\n"
9737 " x = vec4(bar.y);\n"
9738 "}\n";
9739
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009740 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9741 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12009742
Chris Forbes556c76c2015-08-14 12:04:59 +12009743 VkPipelineObj pipe(m_device);
9744 pipe.AddShader(&vs);
9745 pipe.AddShader(&fs);
9746
9747 /* set up CB 0; type is UNORM by default */
9748 pipe.AddColorAttachment();
9749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9750
9751 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009752 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12009753
9754 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009756 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12009757}
9758
Chris Forbes5c59e902016-02-26 16:56:09 +13009759TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
9760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9761 "not declared in layout");
9762
9763 ASSERT_NO_FATAL_FAILURE(InitState());
9764
9765 char const *vsSource =
9766 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009767 "\n"
9768 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
9769 "out gl_PerVertex {\n"
9770 " vec4 gl_Position;\n"
9771 "};\n"
9772 "void main(){\n"
9773 " gl_Position = vec4(consts.x);\n"
9774 "}\n";
9775 char const *fsSource =
9776 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13009777 "\n"
9778 "layout(location=0) out vec4 x;\n"
9779 "void main(){\n"
9780 " x = vec4(1);\n"
9781 "}\n";
9782
9783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9784 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9785
9786 VkPipelineObj pipe(m_device);
9787 pipe.AddShader(&vs);
9788 pipe.AddShader(&fs);
9789
9790 /* set up CB 0; type is UNORM by default */
9791 pipe.AddColorAttachment();
9792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9793
9794 VkDescriptorSetObj descriptorSet(m_device);
9795 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9796
9797 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9798
9799 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009800 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13009801}
9802
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009803#endif // SHADER_CHECKER_TESTS
9804
9805#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06009806TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07009807 m_errorMonitor->SetDesiredFailureMsg(
9808 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009809 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009810
9811 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009812
9813 // Create an image
9814 VkImage image;
9815
Karl Schultz6addd812016-02-02 17:17:23 -07009816 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9817 const int32_t tex_width = 32;
9818 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009819
9820 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009821 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9822 image_create_info.pNext = NULL;
9823 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9824 image_create_info.format = tex_format;
9825 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009826 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07009827 image_create_info.extent.depth = 1;
9828 image_create_info.mipLevels = 1;
9829 image_create_info.arrayLayers = 1;
9830 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9831 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9832 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9833 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009834
9835 // Introduce error by sending down a bogus width extent
9836 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009837 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009838
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009839 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06009840}
9841
Mark Youngc48c4c12016-04-11 14:26:49 -06009842TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
9843 m_errorMonitor->SetDesiredFailureMsg(
9844 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9845 "CreateImage extents is 0 for at least one required dimension");
9846
9847 ASSERT_NO_FATAL_FAILURE(InitState());
9848
9849 // Create an image
9850 VkImage image;
9851
9852 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9853 const int32_t tex_width = 32;
9854 const int32_t tex_height = 32;
9855
9856 VkImageCreateInfo image_create_info = {};
9857 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9858 image_create_info.pNext = NULL;
9859 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9860 image_create_info.format = tex_format;
9861 image_create_info.extent.width = tex_width;
9862 image_create_info.extent.height = tex_height;
9863 image_create_info.extent.depth = 1;
9864 image_create_info.mipLevels = 1;
9865 image_create_info.arrayLayers = 1;
9866 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9867 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9868 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9869 image_create_info.flags = 0;
9870
9871 // Introduce error by sending down a bogus width extent
9872 image_create_info.extent.width = 0;
9873 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
9874
9875 m_errorMonitor->VerifyFound();
9876}
9877
Karl Schultz6addd812016-02-02 17:17:23 -07009878TEST_F(VkLayerTest, UpdateBufferAlignment) {
9879 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06009880
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009882 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009883
Mike Stroyana3082432015-09-25 13:39:21 -06009884 ASSERT_NO_FATAL_FAILURE(InitState());
9885
9886 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9887 vk_testing::Buffer buffer;
9888 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9889
9890 BeginCommandBuffer();
9891 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009892 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009893 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009894
Mike Stroyana3082432015-09-25 13:39:21 -06009895 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009897 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009898
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009899 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009900 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009901 EndCommandBuffer();
9902}
9903
Karl Schultz6addd812016-02-02 17:17:23 -07009904TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009906 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06009907
9908 ASSERT_NO_FATAL_FAILURE(InitState());
9909
9910 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9911 vk_testing::Buffer buffer;
9912 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
9913
9914 BeginCommandBuffer();
9915 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009916 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009917 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009918
Mike Stroyana3082432015-09-25 13:39:21 -06009919 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009921 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009922
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009923 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009924
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009925 m_errorMonitor->VerifyFound();
9926
Mike Stroyana3082432015-09-25 13:39:21 -06009927 EndCommandBuffer();
9928}
9929
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009930#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12009931
Tobin Ehliscde08892015-09-22 10:11:37 -06009932#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009933TEST_F(VkLayerTest, InvalidImageView) {
9934 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06009935
Karl Schultz6addd812016-02-02 17:17:23 -07009936 m_errorMonitor->SetDesiredFailureMsg(
9937 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009938 "vkCreateImageView called with baseMipLevel 10 ");
9939
Tobin Ehliscde08892015-09-22 10:11:37 -06009940 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06009941
Mike Stroyana3082432015-09-25 13:39:21 -06009942 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07009943 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06009944
Karl Schultz6addd812016-02-02 17:17:23 -07009945 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9946 const int32_t tex_width = 32;
9947 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06009948
9949 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009950 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9951 image_create_info.pNext = NULL;
9952 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9953 image_create_info.format = tex_format;
9954 image_create_info.extent.width = tex_width;
9955 image_create_info.extent.height = tex_height;
9956 image_create_info.extent.depth = 1;
9957 image_create_info.mipLevels = 1;
9958 image_create_info.arrayLayers = 1;
9959 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9960 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9961 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9962 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06009963
Chia-I Wuf7458c52015-10-26 21:10:41 +08009964 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06009965 ASSERT_VK_SUCCESS(err);
9966
9967 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009968 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9969 image_view_create_info.image = image;
9970 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9971 image_view_create_info.format = tex_format;
9972 image_view_create_info.subresourceRange.layerCount = 1;
9973 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
9974 image_view_create_info.subresourceRange.levelCount = 1;
9975 image_view_create_info.subresourceRange.aspectMask =
9976 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06009977
9978 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009979 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9980 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06009981
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009982 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06009983}
Mike Stroyana3082432015-09-25 13:39:21 -06009984
Karl Schultz6addd812016-02-02 17:17:23 -07009985TEST_F(VkLayerTest, InvalidImageViewAspect) {
9986 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009987
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009989 "vkCreateImageView: Color image "
9990 "formats must have ONLY the "
9991 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009992
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009993 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009994
9995 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07009996 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06009997
Karl Schultz6addd812016-02-02 17:17:23 -07009998 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9999 const int32_t tex_width = 32;
10000 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010001
10002 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010003 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10004 image_create_info.pNext = NULL;
10005 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10006 image_create_info.format = tex_format;
10007 image_create_info.extent.width = tex_width;
10008 image_create_info.extent.height = tex_height;
10009 image_create_info.extent.depth = 1;
10010 image_create_info.mipLevels = 1;
10011 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10012 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10013 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10014 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010015
Chia-I Wuf7458c52015-10-26 21:10:41 +080010016 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010017 ASSERT_VK_SUCCESS(err);
10018
10019 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010020 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10021 image_view_create_info.image = image;
10022 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
10023 image_view_create_info.format = tex_format;
10024 image_view_create_info.subresourceRange.baseMipLevel = 0;
10025 image_view_create_info.subresourceRange.levelCount = 1;
10026 // Cause an error by setting an invalid image aspect
10027 image_view_create_info.subresourceRange.aspectMask =
10028 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010029
10030 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070010031 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
10032 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010033
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010034 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060010035}
10036
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010037TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070010038 VkResult err;
10039 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010040
Karl Schultz6addd812016-02-02 17:17:23 -070010041 m_errorMonitor->SetDesiredFailureMsg(
10042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010043 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010044
Mike Stroyana3082432015-09-25 13:39:21 -060010045 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010046
10047 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010048 VkImage srcImage;
10049 VkImage dstImage;
10050 VkDeviceMemory srcMem;
10051 VkDeviceMemory destMem;
10052 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010053
10054 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010055 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10056 image_create_info.pNext = NULL;
10057 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10058 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10059 image_create_info.extent.width = 32;
10060 image_create_info.extent.height = 32;
10061 image_create_info.extent.depth = 1;
10062 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010063 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070010064 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10065 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10066 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10067 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010068
Karl Schultz6addd812016-02-02 17:17:23 -070010069 err =
10070 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010071 ASSERT_VK_SUCCESS(err);
10072
Karl Schultz6addd812016-02-02 17:17:23 -070010073 err =
10074 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010075 ASSERT_VK_SUCCESS(err);
10076
10077 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010078 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010079 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10080 memAlloc.pNext = NULL;
10081 memAlloc.allocationSize = 0;
10082 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010083
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010084 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010085 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010086 pass =
10087 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010088 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010089 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010090 ASSERT_VK_SUCCESS(err);
10091
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010092 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010093 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010094 pass =
10095 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010096 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010097 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010098 ASSERT_VK_SUCCESS(err);
10099
10100 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10101 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010102 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010103 ASSERT_VK_SUCCESS(err);
10104
10105 BeginCommandBuffer();
10106 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010107 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010108 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010109 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010110 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060010111 copyRegion.srcOffset.x = 0;
10112 copyRegion.srcOffset.y = 0;
10113 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010114 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010115 copyRegion.dstSubresource.mipLevel = 0;
10116 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010117 // Introduce failure by forcing the dst layerCount to differ from src
10118 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010119 copyRegion.dstOffset.x = 0;
10120 copyRegion.dstOffset.y = 0;
10121 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010122 copyRegion.extent.width = 1;
10123 copyRegion.extent.height = 1;
10124 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010125 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10126 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010127 EndCommandBuffer();
10128
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010129 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010130
Chia-I Wuf7458c52015-10-26 21:10:41 +080010131 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010132 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010133 vkFreeMemory(m_device->device(), srcMem, NULL);
10134 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010135}
10136
Tony Barbourd6673642016-05-05 14:46:39 -060010137TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
10138
10139 TEST_DESCRIPTION("Creating images with unsuported formats ");
10140
10141 ASSERT_NO_FATAL_FAILURE(InitState());
10142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10143 VkImageObj image(m_device);
10144 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10145 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10146 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10147 VK_IMAGE_TILING_OPTIMAL, 0);
10148 ASSERT_TRUE(image.initialized());
10149
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010150 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
10151 VkImageCreateInfo image_create_info;
10152 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10153 image_create_info.pNext = NULL;
10154 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10155 image_create_info.format = VK_FORMAT_UNDEFINED;
10156 image_create_info.extent.width = 32;
10157 image_create_info.extent.height = 32;
10158 image_create_info.extent.depth = 1;
10159 image_create_info.mipLevels = 1;
10160 image_create_info.arrayLayers = 1;
10161 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10162 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10163 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10164 image_create_info.flags = 0;
10165
10166 m_errorMonitor->SetDesiredFailureMsg(
10167 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10168 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
10169
10170 VkImage localImage;
10171 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
10172 m_errorMonitor->VerifyFound();
10173
Tony Barbourd6673642016-05-05 14:46:39 -060010174 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010175 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060010176 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10177 VkFormat format = static_cast<VkFormat>(f);
10178 VkFormatProperties fProps = m_device->format_properties(format);
10179 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
10180 fProps.optimalTilingFeatures == 0) {
10181 unsupported = format;
10182 break;
10183 }
10184 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010185
Tony Barbourd6673642016-05-05 14:46:39 -060010186 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060010187 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060010188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010189 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060010190
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060010191 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060010192 m_errorMonitor->VerifyFound();
10193 }
10194}
10195
10196TEST_F(VkLayerTest, ImageLayerViewTests) {
10197 VkResult ret;
10198 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
10199
10200 ASSERT_NO_FATAL_FAILURE(InitState());
10201
10202 VkImageObj image(m_device);
10203 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10204 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10205 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10206 VK_IMAGE_TILING_OPTIMAL, 0);
10207 ASSERT_TRUE(image.initialized());
10208
10209 VkImageView imgView;
10210 VkImageViewCreateInfo imgViewInfo = {};
10211 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10212 imgViewInfo.image = image.handle();
10213 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
10214 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10215 imgViewInfo.subresourceRange.layerCount = 1;
10216 imgViewInfo.subresourceRange.baseMipLevel = 0;
10217 imgViewInfo.subresourceRange.levelCount = 1;
10218 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10219
10220 m_errorMonitor->SetDesiredFailureMsg(
10221 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10222 "vkCreateImageView called with baseMipLevel");
10223 // View can't have baseMipLevel >= image's mipLevels - Expect
10224 // VIEW_CREATE_ERROR
10225 imgViewInfo.subresourceRange.baseMipLevel = 1;
10226 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10227 m_errorMonitor->VerifyFound();
10228 imgViewInfo.subresourceRange.baseMipLevel = 0;
10229
10230 m_errorMonitor->SetDesiredFailureMsg(
10231 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10232 "vkCreateImageView called with baseArrayLayer");
10233 // View can't have baseArrayLayer >= image's arraySize - Expect
10234 // VIEW_CREATE_ERROR
10235 imgViewInfo.subresourceRange.baseArrayLayer = 1;
10236 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10237 m_errorMonitor->VerifyFound();
10238 imgViewInfo.subresourceRange.baseArrayLayer = 0;
10239
10240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10241 "vkCreateImageView called with 0 in "
10242 "pCreateInfo->subresourceRange."
10243 "levelCount");
10244 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
10245 imgViewInfo.subresourceRange.levelCount = 0;
10246 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10247 m_errorMonitor->VerifyFound();
10248 imgViewInfo.subresourceRange.levelCount = 1;
10249
10250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10251 "vkCreateImageView called with 0 in "
10252 "pCreateInfo->subresourceRange."
10253 "layerCount");
10254 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
10255 imgViewInfo.subresourceRange.layerCount = 0;
10256 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10257 m_errorMonitor->VerifyFound();
10258 imgViewInfo.subresourceRange.layerCount = 1;
10259
10260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10261 "but both must be color formats");
10262 // Can't use depth format for view into color image - Expect INVALID_FORMAT
10263 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
10264 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10265 m_errorMonitor->VerifyFound();
10266 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10267
10268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10269 "Formats MUST be IDENTICAL unless "
10270 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
10271 "was set on image creation.");
10272 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
10273 // VIEW_CREATE_ERROR
10274 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
10275 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10276 m_errorMonitor->VerifyFound();
10277 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
10278
10279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10280 "can support ImageViews with "
10281 "differing formats but they must be "
10282 "in the same compatibility class.");
10283 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
10284 // VIEW_CREATE_ERROR
10285 VkImageCreateInfo mutImgInfo = image.create_info();
10286 VkImage mutImage;
10287 mutImgInfo.format = VK_FORMAT_R8_UINT;
10288 assert(
10289 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
10290 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
10291 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
10292 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10293 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
10294 ASSERT_VK_SUCCESS(ret);
10295 imgViewInfo.image = mutImage;
10296 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
10297 m_errorMonitor->VerifyFound();
10298 imgViewInfo.image = image.handle();
10299 vkDestroyImage(m_device->handle(), mutImage, NULL);
10300}
10301
10302TEST_F(VkLayerTest, MiscImageLayerTests) {
10303
10304 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
10305
10306 ASSERT_NO_FATAL_FAILURE(InitState());
10307
10308 VkImageObj image(m_device);
10309 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
10310 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
10311 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
10312 VK_IMAGE_TILING_OPTIMAL, 0);
10313 ASSERT_TRUE(image.initialized());
10314
10315 m_errorMonitor->SetDesiredFailureMsg(
10316 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10317 "number of layers in image subresource is zero");
10318 vk_testing::Buffer buffer;
10319 VkMemoryPropertyFlags reqs = 0;
10320 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
10321 VkBufferImageCopy region = {};
10322 region.bufferRowLength = 128;
10323 region.bufferImageHeight = 128;
10324 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10325 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
10326 region.imageSubresource.layerCount = 0;
10327 region.imageExtent.height = 4;
10328 region.imageExtent.width = 4;
10329 region.imageExtent.depth = 1;
10330 m_commandBuffer->BeginCommandBuffer();
10331 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10332 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10333 1, &region);
10334 m_errorMonitor->VerifyFound();
10335 region.imageSubresource.layerCount = 1;
10336
10337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10338 "aspectMasks for each region must "
10339 "specify only COLOR or DEPTH or "
10340 "STENCIL");
10341 // Expect MISMATCHED_IMAGE_ASPECT
10342 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
10343 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
10344 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
10345 1, &region);
10346 m_errorMonitor->VerifyFound();
10347 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10348
10349 m_errorMonitor->SetDesiredFailureMsg(
10350 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10351 "If the format of srcImage is a depth, stencil, depth stencil or "
10352 "integer-based format then filter must be VK_FILTER_NEAREST");
10353 // Expect INVALID_FILTER
10354 VkImageObj intImage1(m_device);
10355 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
10356 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10357 0);
10358 VkImageObj intImage2(m_device);
10359 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
10360 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
10361 0);
10362 VkImageBlit blitRegion = {};
10363 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10364 blitRegion.srcSubresource.baseArrayLayer = 0;
10365 blitRegion.srcSubresource.layerCount = 1;
10366 blitRegion.srcSubresource.mipLevel = 0;
10367 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10368 blitRegion.dstSubresource.baseArrayLayer = 0;
10369 blitRegion.dstSubresource.layerCount = 1;
10370 blitRegion.dstSubresource.mipLevel = 0;
10371
10372 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
10373 intImage1.layout(), intImage2.handle(), intImage2.layout(),
10374 16, &blitRegion, VK_FILTER_LINEAR);
10375 m_errorMonitor->VerifyFound();
10376
10377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10378 "called with 0 in ppMemoryBarriers");
10379 VkImageMemoryBarrier img_barrier;
10380 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10381 img_barrier.pNext = NULL;
10382 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10383 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10384 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10385 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10386 img_barrier.image = image.handle();
10387 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10388 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
10389 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10390 img_barrier.subresourceRange.baseArrayLayer = 0;
10391 img_barrier.subresourceRange.baseMipLevel = 0;
10392 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
10393 img_barrier.subresourceRange.layerCount = 0;
10394 img_barrier.subresourceRange.levelCount = 1;
10395 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
10396 VK_PIPELINE_STAGE_HOST_BIT,
10397 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
10398 nullptr, 1, &img_barrier);
10399 m_errorMonitor->VerifyFound();
10400 img_barrier.subresourceRange.layerCount = 1;
10401}
10402
10403TEST_F(VkLayerTest, ImageFormatLimits) {
10404
10405 TEST_DESCRIPTION("Exceed the limits of image format ");
10406
10407 m_errorMonitor->SetDesiredFailureMsg(
10408 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10409 "CreateImage extents exceed allowable limits for format");
10410 VkImageCreateInfo image_create_info = {};
10411 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10412 image_create_info.pNext = NULL;
10413 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10414 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10415 image_create_info.extent.width = 32;
10416 image_create_info.extent.height = 32;
10417 image_create_info.extent.depth = 1;
10418 image_create_info.mipLevels = 1;
10419 image_create_info.arrayLayers = 1;
10420 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10421 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10423 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10424 image_create_info.flags = 0;
10425
10426 VkImage nullImg;
10427 VkImageFormatProperties imgFmtProps;
10428 vkGetPhysicalDeviceImageFormatProperties(
10429 gpu(), image_create_info.format, image_create_info.imageType,
10430 image_create_info.tiling, image_create_info.usage,
10431 image_create_info.flags, &imgFmtProps);
10432 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
10433 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10434 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10435 m_errorMonitor->VerifyFound();
10436 image_create_info.extent.depth = 1;
10437
10438 m_errorMonitor->SetDesiredFailureMsg(
10439 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10440 "exceeds allowable maximum supported by format of");
10441 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
10442 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10443 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10444 m_errorMonitor->VerifyFound();
10445 image_create_info.mipLevels = 1;
10446
10447 m_errorMonitor->SetDesiredFailureMsg(
10448 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10449 "exceeds allowable maximum supported by format of");
10450 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
10451 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10452 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10453 m_errorMonitor->VerifyFound();
10454 image_create_info.arrayLayers = 1;
10455
10456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10457 "is not supported by format");
10458 int samples = imgFmtProps.sampleCounts >> 1;
10459 image_create_info.samples = (VkSampleCountFlagBits)samples;
10460 // Expect INVALID_FORMAT_LIMITS_VIOLATION
10461 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10462 m_errorMonitor->VerifyFound();
10463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10464
10465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10466 "pCreateInfo->initialLayout, must be "
10467 "VK_IMAGE_LAYOUT_UNDEFINED or "
10468 "VK_IMAGE_LAYOUT_PREINITIALIZED");
10469 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10470 // Expect INVALID_LAYOUT
10471 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
10472 m_errorMonitor->VerifyFound();
10473 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10474}
10475
Karl Schultz6addd812016-02-02 17:17:23 -070010476TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060010477 VkResult err;
10478 bool pass;
10479
10480 // Create color images with different format sizes and try to copy between them
10481 m_errorMonitor->SetDesiredFailureMsg(
10482 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10483 "vkCmdCopyImage called with unmatched source and dest image format sizes");
10484
10485 ASSERT_NO_FATAL_FAILURE(InitState());
10486
10487 // Create two images of different types and try to copy between them
10488 VkImage srcImage;
10489 VkImage dstImage;
10490 VkDeviceMemory srcMem;
10491 VkDeviceMemory destMem;
10492 VkMemoryRequirements memReqs;
10493
10494 VkImageCreateInfo image_create_info = {};
10495 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10496 image_create_info.pNext = NULL;
10497 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10498 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10499 image_create_info.extent.width = 32;
10500 image_create_info.extent.height = 32;
10501 image_create_info.extent.depth = 1;
10502 image_create_info.mipLevels = 1;
10503 image_create_info.arrayLayers = 1;
10504 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10505 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10506 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10507 image_create_info.flags = 0;
10508
10509 err =
10510 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
10511 ASSERT_VK_SUCCESS(err);
10512
10513 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10514 // Introduce failure by creating second image with a different-sized format.
10515 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
10516
10517 err =
10518 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
10519 ASSERT_VK_SUCCESS(err);
10520
10521 // Allocate memory
10522 VkMemoryAllocateInfo memAlloc = {};
10523 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10524 memAlloc.pNext = NULL;
10525 memAlloc.allocationSize = 0;
10526 memAlloc.memoryTypeIndex = 0;
10527
10528 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
10529 memAlloc.allocationSize = memReqs.size;
10530 pass =
10531 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10532 ASSERT_TRUE(pass);
10533 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
10534 ASSERT_VK_SUCCESS(err);
10535
10536 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
10537 memAlloc.allocationSize = memReqs.size;
10538 pass =
10539 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
10540 ASSERT_TRUE(pass);
10541 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
10542 ASSERT_VK_SUCCESS(err);
10543
10544 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10545 ASSERT_VK_SUCCESS(err);
10546 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
10547 ASSERT_VK_SUCCESS(err);
10548
10549 BeginCommandBuffer();
10550 VkImageCopy copyRegion;
10551 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10552 copyRegion.srcSubresource.mipLevel = 0;
10553 copyRegion.srcSubresource.baseArrayLayer = 0;
10554 copyRegion.srcSubresource.layerCount = 0;
10555 copyRegion.srcOffset.x = 0;
10556 copyRegion.srcOffset.y = 0;
10557 copyRegion.srcOffset.z = 0;
10558 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10559 copyRegion.dstSubresource.mipLevel = 0;
10560 copyRegion.dstSubresource.baseArrayLayer = 0;
10561 copyRegion.dstSubresource.layerCount = 0;
10562 copyRegion.dstOffset.x = 0;
10563 copyRegion.dstOffset.y = 0;
10564 copyRegion.dstOffset.z = 0;
10565 copyRegion.extent.width = 1;
10566 copyRegion.extent.height = 1;
10567 copyRegion.extent.depth = 1;
10568 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10569 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10570 EndCommandBuffer();
10571
10572 m_errorMonitor->VerifyFound();
10573
10574 vkDestroyImage(m_device->device(), srcImage, NULL);
10575 vkDestroyImage(m_device->device(), dstImage, NULL);
10576 vkFreeMemory(m_device->device(), srcMem, NULL);
10577 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010578}
10579
Karl Schultz6addd812016-02-02 17:17:23 -070010580TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
10581 VkResult err;
10582 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010583
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010584 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010585 m_errorMonitor->SetDesiredFailureMsg(
10586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010587 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010588
Mike Stroyana3082432015-09-25 13:39:21 -060010589 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010590
10591 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010592 VkImage srcImage;
10593 VkImage dstImage;
10594 VkDeviceMemory srcMem;
10595 VkDeviceMemory destMem;
10596 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010597
10598 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010599 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10600 image_create_info.pNext = NULL;
10601 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10602 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10603 image_create_info.extent.width = 32;
10604 image_create_info.extent.height = 32;
10605 image_create_info.extent.depth = 1;
10606 image_create_info.mipLevels = 1;
10607 image_create_info.arrayLayers = 1;
10608 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10609 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
10610 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10611 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010612
Karl Schultz6addd812016-02-02 17:17:23 -070010613 err =
10614 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010615 ASSERT_VK_SUCCESS(err);
10616
Karl Schultzbdb75952016-04-19 11:36:49 -060010617 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
10618
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010619 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070010620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060010621 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
10622 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010623
Karl Schultz6addd812016-02-02 17:17:23 -070010624 err =
10625 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010626 ASSERT_VK_SUCCESS(err);
10627
10628 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010629 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010630 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10631 memAlloc.pNext = NULL;
10632 memAlloc.allocationSize = 0;
10633 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010634
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010635 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010636 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010637 pass =
10638 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010639 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010640 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010641 ASSERT_VK_SUCCESS(err);
10642
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010643 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010644 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010645 pass =
10646 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010647 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010648 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010649 ASSERT_VK_SUCCESS(err);
10650
10651 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10652 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010653 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010654 ASSERT_VK_SUCCESS(err);
10655
10656 BeginCommandBuffer();
10657 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010658 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010659 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010660 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010661 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010662 copyRegion.srcOffset.x = 0;
10663 copyRegion.srcOffset.y = 0;
10664 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010665 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010666 copyRegion.dstSubresource.mipLevel = 0;
10667 copyRegion.dstSubresource.baseArrayLayer = 0;
10668 copyRegion.dstSubresource.layerCount = 0;
10669 copyRegion.dstOffset.x = 0;
10670 copyRegion.dstOffset.y = 0;
10671 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010672 copyRegion.extent.width = 1;
10673 copyRegion.extent.height = 1;
10674 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010675 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10676 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010677 EndCommandBuffer();
10678
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010679 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010680
Chia-I Wuf7458c52015-10-26 21:10:41 +080010681 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010682 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010683 vkFreeMemory(m_device->device(), srcMem, NULL);
10684 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010685}
10686
Karl Schultz6addd812016-02-02 17:17:23 -070010687TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
10688 VkResult err;
10689 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010690
Karl Schultz6addd812016-02-02 17:17:23 -070010691 m_errorMonitor->SetDesiredFailureMsg(
10692 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010693 "vkCmdResolveImage called with source sample count less than 2.");
10694
Mike Stroyana3082432015-09-25 13:39:21 -060010695 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010696
10697 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010698 VkImage srcImage;
10699 VkImage dstImage;
10700 VkDeviceMemory srcMem;
10701 VkDeviceMemory destMem;
10702 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010703
10704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10706 image_create_info.pNext = NULL;
10707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10709 image_create_info.extent.width = 32;
10710 image_create_info.extent.height = 1;
10711 image_create_info.extent.depth = 1;
10712 image_create_info.mipLevels = 1;
10713 image_create_info.arrayLayers = 1;
10714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10716 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10717 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010718
Karl Schultz6addd812016-02-02 17:17:23 -070010719 err =
10720 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010721 ASSERT_VK_SUCCESS(err);
10722
Karl Schultz6addd812016-02-02 17:17:23 -070010723 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010724
Karl Schultz6addd812016-02-02 17:17:23 -070010725 err =
10726 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010727 ASSERT_VK_SUCCESS(err);
10728
10729 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010730 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010731 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10732 memAlloc.pNext = NULL;
10733 memAlloc.allocationSize = 0;
10734 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010735
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010736 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010737 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010738 pass =
10739 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010740 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010741 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010742 ASSERT_VK_SUCCESS(err);
10743
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010744 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010745 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010746 pass =
10747 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010748 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010749 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010750 ASSERT_VK_SUCCESS(err);
10751
10752 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10753 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010754 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010755 ASSERT_VK_SUCCESS(err);
10756
10757 BeginCommandBuffer();
10758 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010759 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10760 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010761 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010762 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010763 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010764 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010765 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010766 resolveRegion.srcOffset.x = 0;
10767 resolveRegion.srcOffset.y = 0;
10768 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010769 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010770 resolveRegion.dstSubresource.mipLevel = 0;
10771 resolveRegion.dstSubresource.baseArrayLayer = 0;
10772 resolveRegion.dstSubresource.layerCount = 0;
10773 resolveRegion.dstOffset.x = 0;
10774 resolveRegion.dstOffset.y = 0;
10775 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010776 resolveRegion.extent.width = 1;
10777 resolveRegion.extent.height = 1;
10778 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010779 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10780 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010781 EndCommandBuffer();
10782
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010783 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010784
Chia-I Wuf7458c52015-10-26 21:10:41 +080010785 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010786 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010787 vkFreeMemory(m_device->device(), srcMem, NULL);
10788 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010789}
10790
Karl Schultz6addd812016-02-02 17:17:23 -070010791TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
10792 VkResult err;
10793 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010794
Karl Schultz6addd812016-02-02 17:17:23 -070010795 m_errorMonitor->SetDesiredFailureMsg(
10796 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010797 "vkCmdResolveImage called with dest sample count greater than 1.");
10798
Mike Stroyana3082432015-09-25 13:39:21 -060010799 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010800
Chris Forbesa7530692016-05-08 12:35:39 +120010801 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070010802 VkImage srcImage;
10803 VkImage dstImage;
10804 VkDeviceMemory srcMem;
10805 VkDeviceMemory destMem;
10806 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010807
10808 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10810 image_create_info.pNext = NULL;
10811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10812 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10813 image_create_info.extent.width = 32;
10814 image_create_info.extent.height = 1;
10815 image_create_info.extent.depth = 1;
10816 image_create_info.mipLevels = 1;
10817 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120010818 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070010819 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10820 // Note: Some implementations expect color attachment usage for any
10821 // multisample surface
10822 image_create_info.usage =
10823 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10824 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010825
Karl Schultz6addd812016-02-02 17:17:23 -070010826 err =
10827 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010828 ASSERT_VK_SUCCESS(err);
10829
Karl Schultz6addd812016-02-02 17:17:23 -070010830 // Note: Some implementations expect color attachment usage for any
10831 // multisample surface
10832 image_create_info.usage =
10833 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010834
Karl Schultz6addd812016-02-02 17:17:23 -070010835 err =
10836 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010837 ASSERT_VK_SUCCESS(err);
10838
10839 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010840 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010841 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10842 memAlloc.pNext = NULL;
10843 memAlloc.allocationSize = 0;
10844 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010845
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010846 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010847 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010848 pass =
10849 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010850 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010851 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010852 ASSERT_VK_SUCCESS(err);
10853
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010854 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010855 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010856 pass =
10857 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010858 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010859 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010860 ASSERT_VK_SUCCESS(err);
10861
10862 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10863 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010864 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010865 ASSERT_VK_SUCCESS(err);
10866
10867 BeginCommandBuffer();
10868 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010869 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10870 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010871 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010872 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010873 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010874 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010875 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010876 resolveRegion.srcOffset.x = 0;
10877 resolveRegion.srcOffset.y = 0;
10878 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010879 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010880 resolveRegion.dstSubresource.mipLevel = 0;
10881 resolveRegion.dstSubresource.baseArrayLayer = 0;
10882 resolveRegion.dstSubresource.layerCount = 0;
10883 resolveRegion.dstOffset.x = 0;
10884 resolveRegion.dstOffset.y = 0;
10885 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010886 resolveRegion.extent.width = 1;
10887 resolveRegion.extent.height = 1;
10888 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070010889 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
10890 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060010891 EndCommandBuffer();
10892
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010893 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060010894
Chia-I Wuf7458c52015-10-26 21:10:41 +080010895 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010896 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080010897 vkFreeMemory(m_device->device(), srcMem, NULL);
10898 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060010899}
10900
Karl Schultz6addd812016-02-02 17:17:23 -070010901TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
10902 VkResult err;
10903 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060010904
Karl Schultz6addd812016-02-02 17:17:23 -070010905 m_errorMonitor->SetDesiredFailureMsg(
10906 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010907 "vkCmdResolveImage called with unmatched source and dest formats.");
10908
Mike Stroyana3082432015-09-25 13:39:21 -060010909 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060010910
10911 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070010912 VkImage srcImage;
10913 VkImage dstImage;
10914 VkDeviceMemory srcMem;
10915 VkDeviceMemory destMem;
10916 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060010917
10918 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010919 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10920 image_create_info.pNext = NULL;
10921 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10922 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
10923 image_create_info.extent.width = 32;
10924 image_create_info.extent.height = 1;
10925 image_create_info.extent.depth = 1;
10926 image_create_info.mipLevels = 1;
10927 image_create_info.arrayLayers = 1;
10928 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
10929 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10930 // Note: Some implementations expect color attachment usage for any
10931 // multisample surface
10932 image_create_info.usage =
10933 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10934 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010935
Karl Schultz6addd812016-02-02 17:17:23 -070010936 err =
10937 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010938 ASSERT_VK_SUCCESS(err);
10939
Karl Schultz6addd812016-02-02 17:17:23 -070010940 // Set format to something other than source image
10941 image_create_info.format = VK_FORMAT_R32_SFLOAT;
10942 // Note: Some implementations expect color attachment usage for any
10943 // multisample surface
10944 image_create_info.usage =
10945 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
10946 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010947
Karl Schultz6addd812016-02-02 17:17:23 -070010948 err =
10949 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060010950 ASSERT_VK_SUCCESS(err);
10951
10952 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010953 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010954 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10955 memAlloc.pNext = NULL;
10956 memAlloc.allocationSize = 0;
10957 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010958
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060010959 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010960 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010961 pass =
10962 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010963 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010964 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010965 ASSERT_VK_SUCCESS(err);
10966
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010967 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060010968 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070010969 pass =
10970 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060010971 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010972 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060010973 ASSERT_VK_SUCCESS(err);
10974
10975 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
10976 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010977 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060010978 ASSERT_VK_SUCCESS(err);
10979
10980 BeginCommandBuffer();
10981 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070010982 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
10983 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060010984 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010985 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060010986 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060010987 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010988 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010989 resolveRegion.srcOffset.x = 0;
10990 resolveRegion.srcOffset.y = 0;
10991 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080010992 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010993 resolveRegion.dstSubresource.mipLevel = 0;
10994 resolveRegion.dstSubresource.baseArrayLayer = 0;
10995 resolveRegion.dstSubresource.layerCount = 0;
10996 resolveRegion.dstOffset.x = 0;
10997 resolveRegion.dstOffset.y = 0;
10998 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060010999 resolveRegion.extent.width = 1;
11000 resolveRegion.extent.height = 1;
11001 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011002 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11003 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011004 EndCommandBuffer();
11005
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011006 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011007
Chia-I Wuf7458c52015-10-26 21:10:41 +080011008 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011009 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011010 vkFreeMemory(m_device->device(), srcMem, NULL);
11011 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011012}
11013
Karl Schultz6addd812016-02-02 17:17:23 -070011014TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
11015 VkResult err;
11016 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011017
Karl Schultz6addd812016-02-02 17:17:23 -070011018 m_errorMonitor->SetDesiredFailureMsg(
11019 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011020 "vkCmdResolveImage called with unmatched source and dest image types.");
11021
Mike Stroyana3082432015-09-25 13:39:21 -060011022 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011023
11024 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011025 VkImage srcImage;
11026 VkImage dstImage;
11027 VkDeviceMemory srcMem;
11028 VkDeviceMemory destMem;
11029 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011030
11031 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011032 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11033 image_create_info.pNext = NULL;
11034 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11035 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11036 image_create_info.extent.width = 32;
11037 image_create_info.extent.height = 1;
11038 image_create_info.extent.depth = 1;
11039 image_create_info.mipLevels = 1;
11040 image_create_info.arrayLayers = 1;
11041 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
11042 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11043 // Note: Some implementations expect color attachment usage for any
11044 // multisample surface
11045 image_create_info.usage =
11046 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11047 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011048
Karl Schultz6addd812016-02-02 17:17:23 -070011049 err =
11050 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011051 ASSERT_VK_SUCCESS(err);
11052
Karl Schultz6addd812016-02-02 17:17:23 -070011053 image_create_info.imageType = VK_IMAGE_TYPE_1D;
11054 // Note: Some implementations expect color attachment usage for any
11055 // multisample surface
11056 image_create_info.usage =
11057 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11058 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011059
Karl Schultz6addd812016-02-02 17:17:23 -070011060 err =
11061 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011062 ASSERT_VK_SUCCESS(err);
11063
11064 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011065 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011066 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11067 memAlloc.pNext = NULL;
11068 memAlloc.allocationSize = 0;
11069 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011070
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011071 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011072 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011073 pass =
11074 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011075 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011076 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011077 ASSERT_VK_SUCCESS(err);
11078
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011079 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011080 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011081 pass =
11082 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011083 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011084 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011085 ASSERT_VK_SUCCESS(err);
11086
11087 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11088 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011089 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011090 ASSERT_VK_SUCCESS(err);
11091
11092 BeginCommandBuffer();
11093 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011094 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11095 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011096 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011097 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011098 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011099 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011100 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011101 resolveRegion.srcOffset.x = 0;
11102 resolveRegion.srcOffset.y = 0;
11103 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011104 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011105 resolveRegion.dstSubresource.mipLevel = 0;
11106 resolveRegion.dstSubresource.baseArrayLayer = 0;
11107 resolveRegion.dstSubresource.layerCount = 0;
11108 resolveRegion.dstOffset.x = 0;
11109 resolveRegion.dstOffset.y = 0;
11110 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011111 resolveRegion.extent.width = 1;
11112 resolveRegion.extent.height = 1;
11113 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011114 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11115 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011116 EndCommandBuffer();
11117
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011118 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011119
Chia-I Wuf7458c52015-10-26 21:10:41 +080011120 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011121 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011122 vkFreeMemory(m_device->device(), srcMem, NULL);
11123 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011124}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011125
Karl Schultz6addd812016-02-02 17:17:23 -070011126TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011127 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070011128 // to using a DS format, then cause it to hit error due to COLOR_BIT not
11129 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011130 // The image format check comes 2nd in validation so we trigger it first,
11131 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070011132 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011133
Karl Schultz6addd812016-02-02 17:17:23 -070011134 m_errorMonitor->SetDesiredFailureMsg(
11135 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011136 "Combination depth/stencil image formats can have only the ");
11137
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011138 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011139
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011140 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011141 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11142 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011143
11144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11146 ds_pool_ci.pNext = NULL;
11147 ds_pool_ci.maxSets = 1;
11148 ds_pool_ci.poolSizeCount = 1;
11149 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011150
11151 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070011152 err =
11153 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011154 ASSERT_VK_SUCCESS(err);
11155
11156 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011157 dsl_binding.binding = 0;
11158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
11159 dsl_binding.descriptorCount = 1;
11160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11161 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011162
11163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11165 ds_layout_ci.pNext = NULL;
11166 ds_layout_ci.bindingCount = 1;
11167 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011168 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
11170 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011171 ASSERT_VK_SUCCESS(err);
11172
11173 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011174 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011176 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011177 alloc_info.descriptorPool = ds_pool;
11178 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070011179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
11180 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011181 ASSERT_VK_SUCCESS(err);
11182
Karl Schultz6addd812016-02-02 17:17:23 -070011183 VkImage image_bad;
11184 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011185 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -070011186 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011187 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070011188 const int32_t tex_width = 32;
11189 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011190
11191 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11193 image_create_info.pNext = NULL;
11194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11195 image_create_info.format = tex_format_bad;
11196 image_create_info.extent.width = tex_width;
11197 image_create_info.extent.height = tex_height;
11198 image_create_info.extent.depth = 1;
11199 image_create_info.mipLevels = 1;
11200 image_create_info.arrayLayers = 1;
11201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11202 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11203 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
11204 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11205 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011206
Karl Schultz6addd812016-02-02 17:17:23 -070011207 err =
11208 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011209 ASSERT_VK_SUCCESS(err);
11210 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070011211 image_create_info.usage =
11212 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11213 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
11214 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011215 ASSERT_VK_SUCCESS(err);
11216
11217 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011218 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11219 image_view_create_info.image = image_bad;
11220 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11221 image_view_create_info.format = tex_format_bad;
11222 image_view_create_info.subresourceRange.baseArrayLayer = 0;
11223 image_view_create_info.subresourceRange.baseMipLevel = 0;
11224 image_view_create_info.subresourceRange.layerCount = 1;
11225 image_view_create_info.subresourceRange.levelCount = 1;
11226 image_view_create_info.subresourceRange.aspectMask =
11227 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011228
11229 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011230 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11231 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011232
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011233 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011234
Chia-I Wuf7458c52015-10-26 21:10:41 +080011235 vkDestroyImage(m_device->device(), image_bad, NULL);
11236 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011237 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011239}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060011240
11241TEST_F(VkLayerTest, ClearImageErrors) {
11242 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
11243 "ClearDepthStencilImage with a color image.");
11244
11245 ASSERT_NO_FATAL_FAILURE(InitState());
11246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11247
11248 // Renderpass is started here so end it as Clear cmds can't be in renderpass
11249 BeginCommandBuffer();
11250 m_commandBuffer->EndRenderPass();
11251
11252 // Color image
11253 VkClearColorValue clear_color;
11254 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
11255 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
11256 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
11257 const int32_t img_width = 32;
11258 const int32_t img_height = 32;
11259 VkImageCreateInfo image_create_info = {};
11260 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11261 image_create_info.pNext = NULL;
11262 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11263 image_create_info.format = color_format;
11264 image_create_info.extent.width = img_width;
11265 image_create_info.extent.height = img_height;
11266 image_create_info.extent.depth = 1;
11267 image_create_info.mipLevels = 1;
11268 image_create_info.arrayLayers = 1;
11269 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11270 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11271 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11272
11273 vk_testing::Image color_image;
11274 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
11275 reqs);
11276
11277 const VkImageSubresourceRange color_range =
11278 vk_testing::Image::subresource_range(image_create_info,
11279 VK_IMAGE_ASPECT_COLOR_BIT);
11280
11281 // Depth/Stencil image
11282 VkClearDepthStencilValue clear_value = {0};
11283 reqs = 0; // don't need HOST_VISIBLE DS image
11284 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
11285 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
11286 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11287 ds_image_create_info.extent.width = 64;
11288 ds_image_create_info.extent.height = 64;
11289 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11290 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11291
11292 vk_testing::Image ds_image;
11293 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
11294 reqs);
11295
11296 const VkImageSubresourceRange ds_range =
11297 vk_testing::Image::subresource_range(ds_image_create_info,
11298 VK_IMAGE_ASPECT_DEPTH_BIT);
11299
11300 m_errorMonitor->SetDesiredFailureMsg(
11301 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11302 "vkCmdClearColorImage called with depth/stencil image.");
11303
11304 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
11305 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
11306 &color_range);
11307
11308 m_errorMonitor->VerifyFound();
11309
11310 // Call CmdClearDepthStencilImage with color image
11311 m_errorMonitor->SetDesiredFailureMsg(
11312 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11313 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
11314
11315 vkCmdClearDepthStencilImage(
11316 m_commandBuffer->GetBufferHandle(), color_image.handle(),
11317 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
11318 &ds_range);
11319
11320 m_errorMonitor->VerifyFound();
11321}
Tobin Ehliscde08892015-09-22 10:11:37 -060011322#endif // IMAGE_TESTS
11323
Tony Barbour300a6082015-04-07 13:44:53 -060011324int main(int argc, char **argv) {
11325 int result;
11326
Cody Northrop8e54a402016-03-08 22:25:52 -070011327#ifdef ANDROID
11328 int vulkanSupport = InitVulkan();
11329 if (vulkanSupport == 0)
11330 return 1;
11331#endif
11332
Tony Barbour300a6082015-04-07 13:44:53 -060011333 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060011334 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060011335
11336 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
11337
11338 result = RUN_ALL_TESTS();
11339
Tony Barbour6918cd52015-04-09 12:58:51 -060011340 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060011341 return result;
11342}