blob: 46ff1ec3fea5d0579fccdc366dc15fdda52b0f51 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060066 BsoFailCmdClearAttachments = 0x00000200,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050067} BsoFailSelect;
68
69struct vktriangle_vs_uniform {
70 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070071 float mvp[4][4];
72 float position[3][4];
73 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050074};
75
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050076static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120077 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070078 "vec2 vertices[3];\n"
79 "out gl_PerVertex {\n"
80 " vec4 gl_Position;\n"
81 "};\n"
82 "void main() {\n"
83 " vertices[0] = vec2(-1.0, -1.0);\n"
84 " vertices[1] = vec2( 1.0, -1.0);\n"
85 " vertices[2] = vec2( 0.0, 1.0);\n"
86 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
87 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050088
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050089static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120090 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070091 "\n"
92 "layout(location = 0) out vec4 uFragColor;\n"
93 "void main(){\n"
94 " uFragColor = vec4(0,1,0,1);\n"
95 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050096
Karl Schultz6addd812016-02-02 17:17:23 -070097static VKAPI_ATTR VkBool32 VKAPI_CALL
98myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
99 uint64_t srcObject, size_t location, int32_t msgCode,
100 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600101
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600102// ********************************************************
103// ErrorMonitor Usage:
104//
105// Call SetDesiredFailureMsg with a string to be compared against all
106// encountered log messages. Passing NULL will match all log messages.
107// logMsg will return true for skipCall only if msg is matched or NULL.
108//
109// Call DesiredMsgFound to determine if the desired failure message
110// was encountered.
111
Tony Barbour300a6082015-04-07 13:44:53 -0600112class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700113 public:
114 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600115 test_platform_thread_create_mutex(&m_mutex);
116 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700117 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700118 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600119 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600120 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600121
Dustin Graves48458142016-04-29 16:11:55 -0600122 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
123
Karl Schultz6addd812016-02-02 17:17:23 -0700124 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200125 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600126 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600127 m_failureMsg.clear();
128 m_otherMsgs.clear();
129 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700130 m_msgFound = VK_FALSE;
131 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600132 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600133 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600134
Karl Schultz6addd812016-02-02 17:17:23 -0700135 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600136 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600137 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600138 if (m_bailout != NULL) {
139 *m_bailout = true;
140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141 string errorString(msgString);
142 if (msgFlags & m_msgFlags) {
143 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200144 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
145 m_otherMsgs.push_back(m_failureMsg);
146 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600147 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700148 m_msgFound = VK_TRUE;
149 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600150 } else {
151 m_otherMsgs.push_back(errorString);
152 }
153 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600154 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600155 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600156 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600157
Karl Schultz6addd812016-02-02 17:17:23 -0700158 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600159
Karl Schultz6addd812016-02-02 17:17:23 -0700160 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161
Karl Schultz6addd812016-02-02 17:17:23 -0700162 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163
Karl Schultz6addd812016-02-02 17:17:23 -0700164 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600165
Karl Schultz6addd812016-02-02 17:17:23 -0700166 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600167 vector<string> otherMsgs = GetOtherFailureMsgs();
168 cout << "Other error messages logged for this test were:" << endl;
169 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
170 cout << " " << *iter << endl;
171 }
172 }
173
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200174 /* helpers */
175
176 void ExpectSuccess() {
177 // match anything
178 SetDesiredFailureMsg(~0u, "");
179 }
180
181 void VerifyFound() {
182 // Not seeing the desired message is a failure. /Before/ throwing, dump
183 // any other messages.
184 if (!DesiredMsgFound()) {
185 DumpFailureMsgs();
186 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
187 }
188 }
189
190 void VerifyNotFound() {
191 // ExpectSuccess() configured us to match anything. Any error is a
192 // failure.
193 if (DesiredMsgFound()) {
194 DumpFailureMsgs();
195 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
196 }
197 }
198
Karl Schultz6addd812016-02-02 17:17:23 -0700199 private:
200 VkFlags m_msgFlags;
201 string m_desiredMsg;
202 string m_failureMsg;
203 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600204 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700205 bool *m_bailout;
206 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600207};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500208
Karl Schultz6addd812016-02-02 17:17:23 -0700209static VKAPI_ATTR VkBool32 VKAPI_CALL
210myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
211 uint64_t srcObject, size_t location, int32_t msgCode,
212 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
213 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700214 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700215 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600216 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600218 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600219 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600220}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500221
Karl Schultz6addd812016-02-02 17:17:23 -0700222class VkLayerTest : public VkRenderFramework {
223 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800224 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
225 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700226 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
227 BsoFailSelect failMask);
228 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
229 VkPipelineObj &pipelineobj,
230 VkDescriptorSetObj &descriptorSet,
231 BsoFailSelect failMask);
232 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
233 VkDescriptorSetObj &descriptorSet,
234 BsoFailSelect failMask) {
235 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
236 failMask);
237 }
Tony Barbour300a6082015-04-07 13:44:53 -0600238
Tony Barbourfe3351b2015-07-28 10:17:20 -0600239 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700240 VkResult BeginCommandBuffer() {
241 return BeginCommandBuffer(*m_commandBuffer);
242 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800243 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700244 void Draw(uint32_t vertexCount, uint32_t instanceCount,
245 uint32_t firstVertex, uint32_t firstInstance) {
246 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
247 firstInstance);
248 }
249 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
250 uint32_t firstIndex, int32_t vertexOffset,
251 uint32_t firstInstance) {
252 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
253 vertexOffset, firstInstance);
254 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800255 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700256 void QueueCommandBuffer(const VkFence &fence) {
257 m_commandBuffer->QueueCommandBuffer(fence);
258 }
259 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
260 VkDeviceSize offset, uint32_t binding) {
261 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
262 }
263 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
264 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
265 }
266
267 protected:
268 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600269 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600270
271 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600272 std::vector<const char *> instance_layer_names;
273 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 std::vector<const char *> instance_extension_names;
275 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600276
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700277 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600278 /*
279 * Since CreateDbgMsgCallback is an instance level extension call
280 * any extension / layer that utilizes that feature also needs
281 * to be enabled at create instance time.
282 */
Karl Schultz6addd812016-02-02 17:17:23 -0700283 // Use Threading layer first to protect others from
284 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700285 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600286 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700288 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800289 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
290 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600291 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700292 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600293
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700294 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600295 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700297 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800298 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
299 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600300 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700301 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600302
Ian Elliott2c1daf52016-05-12 09:41:46 -0600303 if (m_enableWSI) {
304 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
305 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
306#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
307#if defined(VK_USE_PLATFORM_ANDROID_KHR)
308 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
309#endif // VK_USE_PLATFORM_ANDROID_KHR
310#if defined(VK_USE_PLATFORM_MIR_KHR)
311 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
312#endif // VK_USE_PLATFORM_MIR_KHR
313#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
314 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
315#endif // VK_USE_PLATFORM_WAYLAND_KHR
316#if defined(VK_USE_PLATFORM_WIN32_KHR)
317 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
318#endif // VK_USE_PLATFORM_WIN32_KHR
319#endif // NEED_TO_TEST_THIS_ON_PLATFORM
320#if defined(VK_USE_PLATFORM_XCB_KHR)
321 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
322#elif defined(VK_USE_PLATFORM_XLIB_KHR)
323 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
324#endif // VK_USE_PLATFORM_XLIB_KHR
325 }
326
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600327 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600328 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800329 this->app_info.pApplicationName = "layer_tests";
330 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600331 this->app_info.pEngineName = "unittest";
332 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600333 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600334
Tony Barbour15524c32015-04-29 17:34:29 -0600335 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600336 InitFramework(instance_layer_names, device_layer_names,
337 instance_extension_names, device_extension_names,
338 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600339 }
340
341 virtual void TearDown() {
342 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600343 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600344 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600345 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600346
347 VkLayerTest() {
348 m_enableWSI = false;
349 }
Tony Barbour300a6082015-04-07 13:44:53 -0600350};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600353 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600354
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800355 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600356
357 /*
358 * For render test all drawing happens in a single render pass
359 * on a single command buffer.
360 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200361 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600363 }
364
365 return result;
366}
367
Karl Schultz6addd812016-02-02 17:17:23 -0700368VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600370
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200371 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800372 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200373 }
Tony Barbour300a6082015-04-07 13:44:53 -0600374
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600376
377 return result;
378}
379
Karl Schultz6addd812016-02-02 17:17:23 -0700380void VkLayerTest::VKTriangleTest(const char *vertShaderText,
381 const char *fragShaderText,
382 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500383 // Create identity matrix
384 int i;
385 struct vktriangle_vs_uniform data;
386
387 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700388 glm::mat4 View = glm::mat4(1.0f);
389 glm::mat4 Model = glm::mat4(1.0f);
390 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500391 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700392 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
394 memcpy(&data.mvp, &MVP[0][0], matrixSize);
395
Karl Schultz6addd812016-02-02 17:17:23 -0700396 static const Vertex tri_data[] = {
397 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
398 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
399 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500400 };
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 data.position[i][0] = tri_data[i].posX;
404 data.position[i][1] = tri_data[i].posY;
405 data.position[i][2] = tri_data[i].posZ;
406 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700407 data.color[i][0] = tri_data[i].r;
408 data.color[i][1] = tri_data[i].g;
409 data.color[i][2] = tri_data[i].b;
410 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500411 }
412
413 ASSERT_NO_FATAL_FAILURE(InitState());
414 ASSERT_NO_FATAL_FAILURE(InitViewport());
415
Karl Schultz6addd812016-02-02 17:17:23 -0700416 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
417 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418
Karl Schultz6addd812016-02-02 17:17:23 -0700419 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
420 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
421 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422
423 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800424 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 pipelineobj.AddShader(&vs);
426 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600427 if (failMask & BsoFailLineWidth) {
428 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600429 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
430 ia_state.sType =
431 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
432 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
433 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 }
435 if (failMask & BsoFailDepthBias) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineRasterizationStateCreateInfo rs_state = {};
438 rs_state.sType =
439 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
440 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600441 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600442 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600443 }
Karl Schultz6addd812016-02-02 17:17:23 -0700444 // Viewport and scissors must stay in synch or other errors will occur than
445 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600446 if (failMask & BsoFailViewport) {
447 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600448 m_viewports.clear();
449 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailScissor) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600453 m_scissors.clear();
454 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 }
456 if (failMask & BsoFailBlend) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600458 VkPipelineColorBlendAttachmentState att_state = {};
459 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
460 att_state.blendEnable = VK_TRUE;
461 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600462 }
463 if (failMask & BsoFailDepthBounds) {
464 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
465 }
466 if (failMask & BsoFailStencilReadMask) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
468 }
469 if (failMask & BsoFailStencilWriteMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
471 }
472 if (failMask & BsoFailStencilReference) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
474 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475
476 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700477 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
478 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600481 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500482
Tony Barbourfe3351b2015-07-28 10:17:20 -0600483 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600486 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
Mark Muellerd4914412016-06-13 17:52:06 -0600488 if (failMask & BsoFailCmdClearAttachments) {
489 VkClearAttachment color_attachment = {};
490 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
491 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
492 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
493
494 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
495 &color_attachment, 1, &clear_rect);
496 }
497
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
Tony Barbourfe3351b2015-07-28 10:17:20 -0600501 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500502}
503
Karl Schultz6addd812016-02-02 17:17:23 -0700504void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
505 VkPipelineObj &pipelineobj,
506 VkDescriptorSetObj &descriptorSet,
507 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700509 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
510 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
513 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 }
515
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800516 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700517 // Make sure depthWriteEnable is set so that Depth fail test will work
518 // correctly
519 // Make sure stencilTestEnable is set so that Stencil fail test will work
520 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600521 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800522 stencil.failOp = VK_STENCIL_OP_KEEP;
523 stencil.passOp = VK_STENCIL_OP_KEEP;
524 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
525 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600526
527 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
528 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600529 ds_ci.pNext = NULL;
530 ds_ci.depthTestEnable = VK_FALSE;
531 ds_ci.depthWriteEnable = VK_TRUE;
532 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
533 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600534 if (failMask & BsoFailDepthBounds) {
535 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600536 ds_ci.maxDepthBounds = 0.0f;
537 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600538 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600539 ds_ci.stencilTestEnable = VK_TRUE;
540 ds_ci.front = stencil;
541 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600542
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600543 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600544 pipelineobj.SetViewport(m_viewports);
545 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800546 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700547 VkResult err = pipelineobj.CreateVKPipeline(
548 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Ian Elliott2c1daf52016-05-12 09:41:46 -0600554class VkWsiEnabledLayerTest : public VkLayerTest {
555 public:
556protected:
557 VkWsiEnabledLayerTest() {
558 m_enableWSI = true;
559 }
560};
561
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562// ********************************************************************************************************************
563// ********************************************************************************************************************
564// ********************************************************************************************************************
565// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600566#if PARAMETER_VALIDATION_TESTS
567TEST_F(VkLayerTest, RequiredParameter) {
568 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
569 "pointer, array, and array count parameters");
570
571 ASSERT_NO_FATAL_FAILURE(InitState());
572
573 m_errorMonitor->SetDesiredFailureMsg(
574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 "required parameter pFeatures specified as NULL");
576 // Specify NULL for a pointer to a handle
577 // Expected to trigger an error with
578 // parameter_validation::validate_required_pointer
579 vkGetPhysicalDeviceFeatures(gpu(), NULL);
580 m_errorMonitor->VerifyFound();
581
582 m_errorMonitor->SetDesiredFailureMsg(
583 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600584 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600585 // Specify NULL for pointer to array count
586 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600587 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600588 m_errorMonitor->VerifyFound();
589
590 m_errorMonitor->SetDesiredFailureMsg(
591 VK_DEBUG_REPORT_ERROR_BIT_EXT,
592 "parameter viewportCount must be greater than 0");
593 // Specify 0 for a required array count
594 // Expected to trigger an error with parameter_validation::validate_array
595 VkViewport view_port = {};
596 m_commandBuffer->SetViewport(0, 0, &view_port);
597 m_errorMonitor->VerifyFound();
598
599 m_errorMonitor->SetDesiredFailureMsg(
600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
601 "required parameter pViewports specified as NULL");
602 // Specify NULL for a required array
603 // Expected to trigger an error with parameter_validation::validate_array
604 m_commandBuffer->SetViewport(0, 1, NULL);
605 m_errorMonitor->VerifyFound();
606
607 m_errorMonitor->SetDesiredFailureMsg(
608 VK_DEBUG_REPORT_ERROR_BIT_EXT,
609 "required parameter memory specified as VK_NULL_HANDLE");
610 // Specify VK_NULL_HANDLE for a required handle
611 // Expected to trigger an error with
612 // parameter_validation::validate_required_handle
613 vkUnmapMemory(device(), VK_NULL_HANDLE);
614 m_errorMonitor->VerifyFound();
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "required parameter pFences[0] specified as VK_NULL_HANDLE");
619 // Specify VK_NULL_HANDLE for a required handle array entry
620 // Expected to trigger an error with
621 // parameter_validation::validate_required_handle_array
622 VkFence fence = VK_NULL_HANDLE;
623 vkResetFences(device(), 1, &fence);
624 m_errorMonitor->VerifyFound();
625
626 m_errorMonitor->SetDesiredFailureMsg(
627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
628 "required parameter pAllocateInfo specified as NULL");
629 // Specify NULL for a required struct pointer
630 // Expected to trigger an error with
631 // parameter_validation::validate_struct_type
632 VkDeviceMemory memory = VK_NULL_HANDLE;
633 vkAllocateMemory(device(), NULL, NULL, &memory);
634 m_errorMonitor->VerifyFound();
635
636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
637 "value of faceMask must not be 0");
638 // Specify 0 for a required VkFlags parameter
639 // Expected to trigger an error with parameter_validation::validate_flags
640 m_commandBuffer->SetStencilReference(0, 0);
641 m_errorMonitor->VerifyFound();
642
643 m_errorMonitor->SetDesiredFailureMsg(
644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
645 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
646 // Specify 0 for a required VkFlags array entry
647 // Expected to trigger an error with
648 // parameter_validation::validate_flags_array
649 VkSemaphore semaphore = VK_NULL_HANDLE;
650 VkPipelineStageFlags stageFlags = 0;
651 VkSubmitInfo submitInfo = {};
652 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
653 submitInfo.waitSemaphoreCount = 1;
654 submitInfo.pWaitSemaphores = &semaphore;
655 submitInfo.pWaitDstStageMask = &stageFlags;
656 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
657 m_errorMonitor->VerifyFound();
658}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600659
Dustin Gravesfce74c02016-05-10 11:42:58 -0600660TEST_F(VkLayerTest, ReservedParameter) {
661 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
662
663 ASSERT_NO_FATAL_FAILURE(InitState());
664
665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
666 " must be 0");
667 // Specify 0 for a reserved VkFlags parameter
668 // Expected to trigger an error with
669 // parameter_validation::validate_reserved_flags
670 VkEvent event_handle = VK_NULL_HANDLE;
671 VkEventCreateInfo event_info = {};
672 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
673 event_info.flags = 1;
674 vkCreateEvent(device(), &event_info, NULL, &event_handle);
675 m_errorMonitor->VerifyFound();
676}
677
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600678TEST_F(VkLayerTest, InvalidStructSType) {
679 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
680 "structure's sType field");
681
682 ASSERT_NO_FATAL_FAILURE(InitState());
683
684 m_errorMonitor->SetDesiredFailureMsg(
685 VK_DEBUG_REPORT_ERROR_BIT_EXT,
686 "parameter pAllocateInfo->sType must be");
687 // Zero struct memory, effectively setting sType to
688 // VK_STRUCTURE_TYPE_APPLICATION_INFO
689 // Expected to trigger an error with
690 // parameter_validation::validate_struct_type
691 VkMemoryAllocateInfo alloc_info = {};
692 VkDeviceMemory memory = VK_NULL_HANDLE;
693 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
694 m_errorMonitor->VerifyFound();
695
696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
697 "parameter pSubmits[0].sType must be");
698 // Zero struct memory, effectively setting sType to
699 // VK_STRUCTURE_TYPE_APPLICATION_INFO
700 // Expected to trigger an error with
701 // parameter_validation::validate_struct_type_array
702 VkSubmitInfo submit_info = {};
703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
704 m_errorMonitor->VerifyFound();
705}
706
707TEST_F(VkLayerTest, InvalidStructPNext) {
708 TEST_DESCRIPTION(
709 "Specify an invalid value for a Vulkan structure's pNext field");
710
711 ASSERT_NO_FATAL_FAILURE(InitState());
712
713 m_errorMonitor->SetDesiredFailureMsg(
714 VK_DEBUG_REPORT_ERROR_BIT_EXT,
715 "value of pAllocateInfo->pNext must be NULL");
716 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
717 // NULL
718 // Expected to trigger an error with
719 // parameter_validation::validate_struct_pnext
720 VkDeviceMemory memory = VK_NULL_HANDLE;
721 // Zero-initialization will provide the correct sType
722 VkApplicationInfo app_info = {};
Dustin Graves47b6cba2016-05-10 17:34:38 -0600723 VkMemoryAllocateInfo memory_alloc_info = {};
724 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
725 memory_alloc_info.pNext = &app_info;
726 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600727 m_errorMonitor->VerifyFound();
728
Dustin Graves47b6cba2016-05-10 17:34:38 -0600729 m_errorMonitor->SetDesiredFailureMsg(
730 VK_DEBUG_REPORT_ERROR_BIT_EXT,
731 " chain includes a structure with unexpected VkStructureType ");
732 // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value
733 // Expected to trigger an error with
734 // parameter_validation::validate_struct_pnext
735 VkDescriptorPoolSize ds_type_count = {};
736 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
737 ds_type_count.descriptorCount = 1;
738
739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
741 ds_pool_ci.pNext = NULL;
742 ds_pool_ci.maxSets = 1;
743 ds_pool_ci.poolSizeCount = 1;
744 ds_pool_ci.pPoolSizes = &ds_type_count;
745
746 VkDescriptorPool ds_pool;
747 VkResult err =
748 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
749 ASSERT_VK_SUCCESS(err);
750
751 VkDescriptorSetLayoutBinding dsl_binding = {};
752 dsl_binding.binding = 0;
753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
754 dsl_binding.descriptorCount = 1;
755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
756 dsl_binding.pImmutableSamplers = NULL;
757
758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
760 ds_layout_ci.pNext = NULL;
761 ds_layout_ci.bindingCount = 1;
762 ds_layout_ci.pBindings = &dsl_binding;
763
764 VkDescriptorSetLayout ds_layout;
765 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
766 &ds_layout);
767 ASSERT_VK_SUCCESS(err);
768
769 VkDescriptorSet descriptorSet;
770 VkDescriptorSetAllocateInfo ds_alloc_info = {};
771 ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
772 ds_alloc_info.descriptorSetCount = 1;
773 ds_alloc_info.descriptorPool = ds_pool;
774 ds_alloc_info.pSetLayouts = &ds_layout;
775 err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info,
776 &descriptorSet);
777 ASSERT_VK_SUCCESS(err);
778
779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
781 pipeline_layout_ci.setLayoutCount = 1;
782 pipeline_layout_ci.pSetLayouts = &ds_layout;
783
784 VkPipelineLayout pipeline_layout;
785 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
786 &pipeline_layout);
787 ASSERT_VK_SUCCESS(err);
788
789 VkViewport vp = {}; // Just need dummy vp to point to
790 VkRect2D sc = {}; // dummy scissor to point to
791
792 VkPipelineViewportStateCreateInfo vp_state_ci = {};
793 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
794 vp_state_ci.scissorCount = 1;
795 vp_state_ci.pScissors = &sc;
796 vp_state_ci.viewportCount = 1;
797 vp_state_ci.pViewports = &vp;
798
799 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
800 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
801 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
802 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
803 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
804 rs_state_ci.depthClampEnable = VK_FALSE;
805 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
806 rs_state_ci.depthBiasEnable = VK_FALSE;
807
808 VkGraphicsPipelineCreateInfo gp_ci = {};
809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
810 gp_ci.pViewportState = &vp_state_ci;
811 gp_ci.pRasterizationState = &rs_state_ci;
812 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
813 gp_ci.layout = pipeline_layout;
814 gp_ci.renderPass = renderPass();
815
816 VkPipelineCacheCreateInfo pc_ci = {};
817 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
818 pc_ci.initialDataSize = 0;
819 pc_ci.pInitialData = 0;
820
821 VkPipeline pipeline;
822 VkPipelineCache pipelineCache;
823
824 err =
825 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
826 ASSERT_VK_SUCCESS(err);
827
828 // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value
829 VkApplicationInfo invalid_pnext_struct = {};
830 rs_state_ci.pNext = &invalid_pnext_struct;
831
832 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
833 &gp_ci, NULL, &pipeline);
834 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -0600835 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
836 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
839
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600840}
Dustin Graves5d33d532016-05-09 16:21:12 -0600841
842TEST_F(VkLayerTest, UnrecognizedValue) {
843 TEST_DESCRIPTION(
844 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
845
846 ASSERT_NO_FATAL_FAILURE(InitState());
847
848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
849 "does not fall within the begin..end "
850 "range of the core VkFormat "
851 "enumeration tokens");
852 // Specify an invalid VkFormat value
853 // Expected to trigger an error with
854 // parameter_validation::validate_ranged_enum
855 VkFormatProperties format_properties;
856 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
857 &format_properties);
858 m_errorMonitor->VerifyFound();
859
860 m_errorMonitor->SetDesiredFailureMsg(
861 VK_DEBUG_REPORT_ERROR_BIT_EXT,
862 "contains flag bits that are not recognized members of");
863 // Specify an invalid VkFlags bitmask value
864 // Expected to trigger an error with parameter_validation::validate_flags
865 VkImageFormatProperties image_format_properties;
866 vkGetPhysicalDeviceImageFormatProperties(
867 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
868 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
869 &image_format_properties);
870 m_errorMonitor->VerifyFound();
871
872 m_errorMonitor->SetDesiredFailureMsg(
873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
874 "contains flag bits that are not recognized members of");
875 // Specify an invalid VkFlags array entry
876 // Expected to trigger an error with
877 // parameter_validation::validate_flags_array
878 VkSemaphore semaphore = VK_NULL_HANDLE;
879 VkPipelineStageFlags stage_flags =
880 static_cast<VkPipelineStageFlags>(1 << 25);
881 VkSubmitInfo submit_info = {};
882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
883 submit_info.waitSemaphoreCount = 1;
884 submit_info.pWaitSemaphores = &semaphore;
885 submit_info.pWaitDstStageMask = &stage_flags;
886 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
887 m_errorMonitor->VerifyFound();
888
889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
890 "is neither VK_TRUE nor VK_FALSE");
891 // Specify an invalid VkBool32 value
892 // Expected to trigger a warning with
893 // parameter_validation::validate_bool32
894 VkSampler sampler = VK_NULL_HANDLE;
895 VkSamplerCreateInfo sampler_info = {};
896 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
897 sampler_info.pNext = NULL;
898 sampler_info.magFilter = VK_FILTER_NEAREST;
899 sampler_info.minFilter = VK_FILTER_NEAREST;
900 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
901 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
902 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
903 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
904 sampler_info.mipLodBias = 1.0;
905 sampler_info.maxAnisotropy = 1;
906 sampler_info.compareEnable = VK_FALSE;
907 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
908 sampler_info.minLod = 1.0;
909 sampler_info.maxLod = 1.0;
910 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
911 sampler_info.unnormalizedCoordinates = VK_FALSE;
912 // Not VK_TRUE or VK_FALSE
913 sampler_info.anisotropyEnable = 3;
914 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesfce74c02016-05-10 11:42:58 -0600917
918TEST_F(VkLayerTest, FailedReturnValue) {
919 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Dustin Graves13c1e2b2016-05-16 15:31:02 -0600923 // Find an unsupported image format
924 VkFormat unsupported = VK_FORMAT_UNDEFINED;
925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
926 VkFormat format = static_cast<VkFormat>(f);
927 VkFormatProperties fProps = m_device->format_properties(format);
928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
929 fProps.optimalTilingFeatures == 0) {
930 unsupported = format;
931 break;
932 }
933 }
934
935 if (unsupported != VK_FORMAT_UNDEFINED) {
936 m_errorMonitor->SetDesiredFailureMsg(
937 VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 "the requested format is not supported on this device");
939 // Specify an unsupported VkFormat value to generate a
940 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
941 // Expected to trigger a warning from
942 // parameter_validation::validate_result
943 VkImageFormatProperties image_format_properties;
944 VkResult err = vkGetPhysicalDeviceImageFormatProperties(
945 gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
946 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
947 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
948 m_errorMonitor->VerifyFound();
949 }
Dustin Gravesfce74c02016-05-10 11:42:58 -0600950}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -0600951
952TEST_F(VkLayerTest, UpdateBufferAlignment) {
953 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
954 uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
955
956 ASSERT_NO_FATAL_FAILURE(InitState());
957
958 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
959 vk_testing::Buffer buffer;
960 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
961
962 BeginCommandBuffer();
963 // Introduce failure by using dstOffset that is not multiple of 4
964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
965 " is not a multiple of 4");
966 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
967 m_errorMonitor->VerifyFound();
968
969 // Introduce failure by using dataSize that is not multiple of 4
970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
971 " is not a multiple of 4");
972 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
973 m_errorMonitor->VerifyFound();
974
975 // Introduce failure by using dataSize that is < 0
976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
977 "must be greater than zero and less than or equal to 65536");
978 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
979 m_errorMonitor->VerifyFound();
980
981 // Introduce failure by using dataSize that is > 65536
982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
983 "must be greater than zero and less than or equal to 65536");
984 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
985 m_errorMonitor->VerifyFound();
986
987 EndCommandBuffer();
988}
989
990TEST_F(VkLayerTest, FillBufferAlignment) {
991 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
992
993 ASSERT_NO_FATAL_FAILURE(InitState());
994
995 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
996 vk_testing::Buffer buffer;
997 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
998
999 BeginCommandBuffer();
1000
1001 // Introduce failure by using dstOffset that is not multiple of 4
1002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1003 " is not a multiple of 4");
1004 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1005 m_errorMonitor->VerifyFound();
1006
1007 // Introduce failure by using size that is not multiple of 4
1008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1009 " is not a multiple of 4");
1010 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Introduce failure by using size that is zero
1014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1015 "must be greater than zero");
1016 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1017 m_errorMonitor->VerifyFound();
1018
1019 EndCommandBuffer();
1020}
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001021#endif // PARAMETER_VALIDATION_TESTS
1022
Tobin Ehlis0788f522015-05-26 16:11:58 -06001023#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001024#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001025TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001026{
1027 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001028 VkFenceCreateInfo fenceInfo = {};
1029 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1030 fenceInfo.pNext = NULL;
1031 fenceInfo.flags = 0;
1032
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001034
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001035 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001036
1037 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1038 vk_testing::Buffer buffer;
1039 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001040
Tony Barbourfe3351b2015-07-28 10:17:20 -06001041 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001042 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001043 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001044
1045 testFence.init(*m_device, fenceInfo);
1046
1047 // Bypass framework since it does the waits automatically
1048 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001049 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1051 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001052 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001053 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001054 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001055 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001056 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001057 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001058 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001059
1060 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001061 ASSERT_VK_SUCCESS( err );
1062
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001063 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001064 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001066 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001067}
1068
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001069TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001070{
1071 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001072 VkFenceCreateInfo fenceInfo = {};
1073 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1074 fenceInfo.pNext = NULL;
1075 fenceInfo.flags = 0;
1076
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001078
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001079 ASSERT_NO_FATAL_FAILURE(InitState());
1080 ASSERT_NO_FATAL_FAILURE(InitViewport());
1081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1082
Tony Barbourfe3351b2015-07-28 10:17:20 -06001083 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001084 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001085 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001086
1087 testFence.init(*m_device, fenceInfo);
1088
1089 // Bypass framework since it does the waits automatically
1090 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001091 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1093 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001094 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001095 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001096 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001097 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001099 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001100 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001101
1102 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001103 ASSERT_VK_SUCCESS( err );
1104
Jon Ashburnf19916e2016-01-11 13:12:43 -07001105 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001106 VkCommandBufferBeginInfo info = {};
1107 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1108 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001109 info.renderPass = VK_NULL_HANDLE;
1110 info.subpass = 0;
1111 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001112 info.occlusionQueryEnable = VK_FALSE;
1113 info.queryFlags = 0;
1114 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001115
1116 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001117 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001119 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001120}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001121#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001122
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001123// This is a positive test. No failures are expected.
1124TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
1125 VkResult err;
1126 bool pass;
1127
1128 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
1129 "the buffer, create an image, and bind the same memory to "
1130 "it");
1131
1132 m_errorMonitor->ExpectSuccess();
1133
1134 ASSERT_NO_FATAL_FAILURE(InitState());
1135
1136 VkBuffer buffer;
1137 VkImage image;
1138 VkDeviceMemory mem;
1139 VkMemoryRequirements mem_reqs;
1140
1141 VkBufferCreateInfo buf_info = {};
1142 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1143 buf_info.pNext = NULL;
1144 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1145 buf_info.size = 256;
1146 buf_info.queueFamilyIndexCount = 0;
1147 buf_info.pQueueFamilyIndices = NULL;
1148 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1149 buf_info.flags = 0;
1150 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1151 ASSERT_VK_SUCCESS(err);
1152
1153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1154
1155 VkMemoryAllocateInfo alloc_info = {};
1156 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1157 alloc_info.pNext = NULL;
1158 alloc_info.memoryTypeIndex = 0;
1159
1160 // Ensure memory is big enough for both bindings
1161 alloc_info.allocationSize = 0x10000;
1162
1163 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1164 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1165 if (!pass) {
1166 vkDestroyBuffer(m_device->device(), buffer, NULL);
1167 return;
1168 }
1169
1170 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1171 ASSERT_VK_SUCCESS(err);
1172
1173 uint8_t *pData;
1174 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1175 (void **)&pData);
1176 ASSERT_VK_SUCCESS(err);
1177
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001178 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001179
1180 vkUnmapMemory(m_device->device(), mem);
1181
1182 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1183 ASSERT_VK_SUCCESS(err);
1184
1185 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
1186 // memory. In fact, it was never used by the GPU.
1187 // Just be be sure, wait for idle.
1188 vkDestroyBuffer(m_device->device(), buffer, NULL);
1189 vkDeviceWaitIdle(m_device->device());
1190
1191 VkImageCreateInfo image_create_info = {};
1192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1193 image_create_info.pNext = NULL;
1194 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1195 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1196 image_create_info.extent.width = 64;
1197 image_create_info.extent.height = 64;
1198 image_create_info.extent.depth = 1;
1199 image_create_info.mipLevels = 1;
1200 image_create_info.arrayLayers = 1;
1201 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1202 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1203 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1205 image_create_info.queueFamilyIndexCount = 0;
1206 image_create_info.pQueueFamilyIndices = NULL;
1207 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1208 image_create_info.flags = 0;
1209
1210 VkMemoryAllocateInfo mem_alloc = {};
1211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1212 mem_alloc.pNext = NULL;
1213 mem_alloc.allocationSize = 0;
1214 mem_alloc.memoryTypeIndex = 0;
1215
1216 /* Create a mappable image. It will be the texture if linear images are ok
1217 * to be textures or it will be the staging image if they are not.
1218 */
1219 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1220 ASSERT_VK_SUCCESS(err);
1221
1222 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
1223
1224 mem_alloc.allocationSize = mem_reqs.size;
1225
1226 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
1227 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1228 if (!pass) {
1229 vkDestroyImage(m_device->device(), image, NULL);
1230 return;
1231 }
1232
Tobin Ehlis077ded32016-05-12 17:39:13 -06001233 // VALIDATION FAILURE:
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001234 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1235 ASSERT_VK_SUCCESS(err);
1236
1237 m_errorMonitor->VerifyNotFound();
1238
Tony Barbourdf4c0042016-06-01 15:55:43 -06001239 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski152fe252016-05-03 16:49:15 -06001240 vkDestroyBuffer(m_device->device(), buffer, NULL);
1241 vkDestroyImage(m_device->device(), image, NULL);
1242}
1243
Tobin Ehlisf11be982016-05-11 13:52:53 -06001244TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1245 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1246 "buffer and image to memory such that they will alias.");
1247 VkResult err;
1248 bool pass;
1249 ASSERT_NO_FATAL_FAILURE(InitState());
1250
Tobin Ehlis077ded32016-05-12 17:39:13 -06001251 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001252 VkImage image;
1253 VkDeviceMemory mem; // buffer will be bound first
1254 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001255 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001256
1257 VkBufferCreateInfo buf_info = {};
1258 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1259 buf_info.pNext = NULL;
1260 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1261 buf_info.size = 256;
1262 buf_info.queueFamilyIndexCount = 0;
1263 buf_info.pQueueFamilyIndices = NULL;
1264 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1265 buf_info.flags = 0;
1266 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1267 ASSERT_VK_SUCCESS(err);
1268
Tobin Ehlis077ded32016-05-12 17:39:13 -06001269 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001270
1271 VkImageCreateInfo image_create_info = {};
1272 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1273 image_create_info.pNext = NULL;
1274 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1275 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1276 image_create_info.extent.width = 64;
1277 image_create_info.extent.height = 64;
1278 image_create_info.extent.depth = 1;
1279 image_create_info.mipLevels = 1;
1280 image_create_info.arrayLayers = 1;
1281 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1282 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1283 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1284 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1285 image_create_info.queueFamilyIndexCount = 0;
1286 image_create_info.pQueueFamilyIndices = NULL;
1287 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1288 image_create_info.flags = 0;
1289
Tobin Ehlisf11be982016-05-11 13:52:53 -06001290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1291 ASSERT_VK_SUCCESS(err);
1292
Tobin Ehlis077ded32016-05-12 17:39:13 -06001293 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1294
1295 VkMemoryAllocateInfo alloc_info = {};
1296 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1297 alloc_info.pNext = NULL;
1298 alloc_info.memoryTypeIndex = 0;
1299 // Ensure memory is big enough for both bindings
1300 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
1301 pass = m_device->phy().set_memory_type(
1302 buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info,
1303 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001304 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001305 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001306 vkDestroyImage(m_device->device(), image, NULL);
1307 return;
1308 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1310 ASSERT_VK_SUCCESS(err);
1311 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlisf11be982016-05-11 13:52:53 -06001314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1315 " is aliased with buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001316 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001317 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1318 m_errorMonitor->VerifyFound();
1319
1320 // Now correctly bind image to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001321 // aliasing buffer2
1322 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1323 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1325 ASSERT_VK_SUCCESS(err);
1326 err = vkBindImageMemory(m_device->device(), image, mem_img, 0);
1327 ASSERT_VK_SUCCESS(err);
1328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1329 " is aliased with image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001330 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 m_errorMonitor->VerifyFound();
1332
1333 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001334 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335 vkDestroyImage(m_device->device(), image, NULL);
1336 vkFreeMemory(m_device->device(), mem, NULL);
1337 vkFreeMemory(m_device->device(), mem_img, NULL);
1338}
1339
Tobin Ehlis35372522016-05-12 08:32:31 -06001340TEST_F(VkLayerTest, InvalidMemoryMapping) {
1341 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1342 VkResult err;
1343 bool pass;
1344 ASSERT_NO_FATAL_FAILURE(InitState());
1345
1346 VkBuffer buffer;
1347 VkDeviceMemory mem;
1348 VkMemoryRequirements mem_reqs;
1349
1350 VkBufferCreateInfo buf_info = {};
1351 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1352 buf_info.pNext = NULL;
1353 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1354 buf_info.size = 256;
1355 buf_info.queueFamilyIndexCount = 0;
1356 buf_info.pQueueFamilyIndices = NULL;
1357 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 buf_info.flags = 0;
1359 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1360 ASSERT_VK_SUCCESS(err);
1361
1362 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1363 VkMemoryAllocateInfo alloc_info = {};
1364 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1365 alloc_info.pNext = NULL;
1366 alloc_info.memoryTypeIndex = 0;
1367
1368 // Ensure memory is big enough for both bindings
1369 static const VkDeviceSize allocation_size = 0x10000;
1370 alloc_info.allocationSize = allocation_size;
1371 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1372 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1373 if (!pass) {
1374 vkDestroyBuffer(m_device->device(), buffer, NULL);
1375 return;
1376 }
1377 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1378 ASSERT_VK_SUCCESS(err);
1379
1380 uint8_t *pData;
1381 // Attempt to map memory size 0 is invalid
1382 m_errorMonitor->SetDesiredFailureMsg(
1383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1384 "VkMapMemory: Attempting to map memory range of size zero");
1385 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1386 m_errorMonitor->VerifyFound();
1387 // Map memory twice
1388 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1389 (void **)&pData);
1390 ASSERT_VK_SUCCESS(err);
1391 m_errorMonitor->SetDesiredFailureMsg(
1392 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1393 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1394 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
1395 (void **)&pData);
1396 m_errorMonitor->VerifyFound();
1397
1398 // Unmap the memory to avoid re-map error
1399 vkUnmapMemory(m_device->device(), mem);
1400 // overstep allocation with VK_WHOLE_SIZE
1401 m_errorMonitor->SetDesiredFailureMsg(
1402 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1403 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1404 err = vkMapMemory(m_device->device(), mem, allocation_size + 1,
1405 VK_WHOLE_SIZE, 0, (void **)&pData);
1406 m_errorMonitor->VerifyFound();
1407 // overstep allocation w/o VK_WHOLE_SIZE
1408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1409 " oversteps total array size 0x");
1410 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0,
1411 (void **)&pData);
1412 m_errorMonitor->VerifyFound();
1413 // Now error due to unmapping memory that's not mapped
1414 m_errorMonitor->SetDesiredFailureMsg(
1415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1416 "Unmapping Memory without memory being mapped: ");
1417 vkUnmapMemory(m_device->device(), mem);
1418 m_errorMonitor->VerifyFound();
1419 // Now map memory and cause errors due to flushing invalid ranges
1420 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0,
1421 (void **)&pData);
1422 ASSERT_VK_SUCCESS(err);
1423 VkMappedMemoryRange mmr = {};
1424 mmr.memory = mem;
1425 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
1426 m_errorMonitor->SetDesiredFailureMsg(
1427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1428 ") is less than Memory Object's offset (");
1429 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1430 m_errorMonitor->VerifyFound();
1431 // Now flush range that oversteps mapped range
1432 vkUnmapMemory(m_device->device(), mem);
1433 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1434 ASSERT_VK_SUCCESS(err);
1435 mmr.offset = 16;
1436 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
1437 m_errorMonitor->SetDesiredFailureMsg(
1438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1439 ") exceeds the Memory Object's upper-bound (");
1440 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1441 m_errorMonitor->VerifyFound();
1442
1443 pass =
1444 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
1445 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1446 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1447 if (!pass) {
1448 vkFreeMemory(m_device->device(), mem, NULL);
1449 vkDestroyBuffer(m_device->device(), buffer, NULL);
1450 return;
1451 }
1452 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1453 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1454
1455 vkDestroyBuffer(m_device->device(), buffer, NULL);
1456 vkFreeMemory(m_device->device(), mem, NULL);
1457}
1458
Ian Elliott1c32c772016-04-28 14:47:13 -06001459TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1460 VkResult err;
1461 bool pass;
1462
Ian Elliott489eec02016-05-05 14:12:44 -06001463// FIXME: After we turn on this code for non-Linux platforms, uncomment the
1464// following declaration (which is temporarily being moved below):
1465// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001466 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1467 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1468 uint32_t swapchain_image_count = 0;
1469// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1470 uint32_t image_index = 0;
1471// VkPresentInfoKHR present_info = {};
1472
1473 ASSERT_NO_FATAL_FAILURE(InitState());
1474
Ian Elliott3f06ce52016-04-29 14:46:21 -06001475#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1476#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1477 // Use the functions from the VK_KHR_android_surface extension without
1478 // enabling that extension:
1479
1480 // Create a surface:
1481 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001482 m_errorMonitor->SetDesiredFailureMsg(
1483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1484 "extension was not enabled for this");
1485 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
1486 &surface);
1487 pass = (err != VK_SUCCESS);
1488 ASSERT_TRUE(pass);
1489 m_errorMonitor->VerifyFound();
1490#endif // VK_USE_PLATFORM_ANDROID_KHR
1491
1492
1493#if defined(VK_USE_PLATFORM_MIR_KHR)
1494 // Use the functions from the VK_KHR_mir_surface extension without enabling
1495 // that extension:
1496
1497 // Create a surface:
1498 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001499 m_errorMonitor->SetDesiredFailureMsg(
1500 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1501 "extension was not enabled for this");
1502 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1503 pass = (err != VK_SUCCESS);
1504 ASSERT_TRUE(pass);
1505 m_errorMonitor->VerifyFound();
1506
1507 // Tell whether an mir_connection supports presentation:
1508 MirConnection *mir_connection = NULL;
1509 m_errorMonitor->SetDesiredFailureMsg(
1510 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1511 "extension was not enabled for this");
1512 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1513 visual_id);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_MIR_KHR
1516
1517
1518#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1519 // Use the functions from the VK_KHR_wayland_surface extension without
1520 // enabling that extension:
1521
1522 // Create a surface:
1523 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 m_errorMonitor->SetDesiredFailureMsg(
1525 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1526 "extension was not enabled for this");
1527 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1528 &surface);
1529 pass = (err != VK_SUCCESS);
1530 ASSERT_TRUE(pass);
1531 m_errorMonitor->VerifyFound();
1532
1533 // Tell whether an wayland_display supports presentation:
1534 struct wl_display wayland_display = {};
1535 m_errorMonitor->SetDesiredFailureMsg(
1536 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "extension was not enabled for this");
1538 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1539 &wayland_display);
1540 m_errorMonitor->VerifyFound();
1541#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001542#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001543
1544
1545#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001546// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1547// TO NON-LINUX PLATFORMS:
1548VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 // Use the functions from the VK_KHR_win32_surface extension without
1550 // enabling that extension:
1551
1552 // Create a surface:
1553 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554 m_errorMonitor->SetDesiredFailureMsg(
1555 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "extension was not enabled for this");
1557 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1558 &surface);
1559 pass = (err != VK_SUCCESS);
1560 ASSERT_TRUE(pass);
1561 m_errorMonitor->VerifyFound();
1562
1563 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001564 m_errorMonitor->SetDesiredFailureMsg(
1565 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1566 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001567 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001568 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001569// Set this (for now, until all platforms are supported and tested):
1570#define NEED_TO_TEST_THIS_ON_PLATFORM
1571#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001572
1573
Ian Elliott1c32c772016-04-28 14:47:13 -06001574#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001575// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1576// TO NON-LINUX PLATFORMS:
1577VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1579 // that extension:
1580
1581 // Create a surface:
1582 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 m_errorMonitor->SetDesiredFailureMsg(
1584 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1585 "extension was not enabled for this");
1586 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1587 pass = (err != VK_SUCCESS);
1588 ASSERT_TRUE(pass);
1589 m_errorMonitor->VerifyFound();
1590
1591 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001593 xcb_visualid_t visual_id = 0;
1594 m_errorMonitor->SetDesiredFailureMsg(
1595 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1596 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001598 visual_id);
1599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
1610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Ian Elliott12630812016-04-29 14:35:43 -06001611 m_errorMonitor->SetDesiredFailureMsg(
1612 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1613 "extension was not enabled for this");
1614 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1615 pass = (err != VK_SUCCESS);
1616 ASSERT_TRUE(pass);
1617 m_errorMonitor->VerifyFound();
1618
1619 // Tell whether an Xlib VisualID supports presentation:
1620 Display *dpy = NULL;
1621 VisualID visual = 0;
1622 m_errorMonitor->SetDesiredFailureMsg(
1623 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1624 "extension was not enabled for this");
1625 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1626 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001627// Set this (for now, until all platforms are supported and tested):
1628#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001629#endif // VK_USE_PLATFORM_XLIB_KHR
1630
1631
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 // Use the functions from the VK_KHR_surface extension without enabling
1633 // that extension:
1634
Ian Elliott489eec02016-05-05 14:12:44 -06001635#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001636 // Destroy a surface:
1637 m_errorMonitor->SetDesiredFailureMsg(
1638 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1639 "extension was not enabled for this");
1640 vkDestroySurfaceKHR(instance(), surface, NULL);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check if surface supports presentation:
1644 VkBool32 supported = false;
1645 m_errorMonitor->SetDesiredFailureMsg(
1646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1647 "extension was not enabled for this");
1648 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1649 pass = (err != VK_SUCCESS);
1650 ASSERT_TRUE(pass);
1651 m_errorMonitor->VerifyFound();
1652
1653 // Check surface capabilities:
1654 VkSurfaceCapabilitiesKHR capabilities = {};
1655 m_errorMonitor->SetDesiredFailureMsg(
1656 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1657 "extension was not enabled for this");
1658 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1659 &capabilities);
1660 pass = (err != VK_SUCCESS);
1661 ASSERT_TRUE(pass);
1662 m_errorMonitor->VerifyFound();
1663
1664 // Check surface formats:
1665 uint32_t format_count = 0;
1666 VkSurfaceFormatKHR *formats = NULL;
1667 m_errorMonitor->SetDesiredFailureMsg(
1668 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1669 "extension was not enabled for this");
1670 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1671 &format_count, formats);
1672 pass = (err != VK_SUCCESS);
1673 ASSERT_TRUE(pass);
1674 m_errorMonitor->VerifyFound();
1675
1676 // Check surface present modes:
1677 uint32_t present_mode_count = 0;
1678 VkSurfaceFormatKHR *present_modes = NULL;
1679 m_errorMonitor->SetDesiredFailureMsg(
1680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1681 "extension was not enabled for this");
1682 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1683 &present_mode_count, present_modes);
1684 pass = (err != VK_SUCCESS);
1685 ASSERT_TRUE(pass);
1686 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001687#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001688
1689
1690 // Use the functions from the VK_KHR_swapchain extension without enabling
1691 // that extension:
1692
1693 // Create a swapchain:
1694 m_errorMonitor->SetDesiredFailureMsg(
1695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1696 "extension was not enabled for this");
1697 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1698 swapchain_create_info.pNext = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001699 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1700 NULL, &swapchain);
1701 pass = (err != VK_SUCCESS);
1702 ASSERT_TRUE(pass);
1703 m_errorMonitor->VerifyFound();
1704
1705 // Get the images from the swapchain:
1706 m_errorMonitor->SetDesiredFailureMsg(
1707 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1708 "extension was not enabled for this");
1709 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1710 &swapchain_image_count, NULL);
1711 pass = (err != VK_SUCCESS);
1712 ASSERT_TRUE(pass);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Try to acquire an image:
1716 m_errorMonitor->SetDesiredFailureMsg(
1717 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1718 "extension was not enabled for this");
1719 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1720 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1721 pass = (err != VK_SUCCESS);
1722 ASSERT_TRUE(pass);
1723 m_errorMonitor->VerifyFound();
1724
1725 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001726 //
1727 // NOTE: Currently can't test this because a real swapchain is needed (as
1728 // opposed to the fake one we created) in order for the layer to lookup the
1729 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001730
1731 // Destroy the swapchain:
1732 m_errorMonitor->SetDesiredFailureMsg(
1733 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1734 "extension was not enabled for this");
1735 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1736 m_errorMonitor->VerifyFound();
1737}
1738
Ian Elliott2c1daf52016-05-12 09:41:46 -06001739TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
Ian Elliott2c1daf52016-05-12 09:41:46 -06001740
Dustin Graves6c6d8982016-05-17 10:09:21 -06001741#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 VkSurfaceKHR surface = VK_NULL_HANDLE;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001743
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001744 VkResult err;
1745 bool pass;
Ian Elliott2c1daf52016-05-12 09:41:46 -06001746 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1747 VkSwapchainCreateInfoKHR swapchain_create_info = {};
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001748 // uint32_t swapchain_image_count = 0;
1749 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
1750 // uint32_t image_index = 0;
1751 // VkPresentInfoKHR present_info = {};
Ian Elliott2c1daf52016-05-12 09:41:46 -06001752
1753 ASSERT_NO_FATAL_FAILURE(InitState());
1754
1755 // Use the create function from one of the VK_KHR_*_surface extension in
1756 // order to create a surface, testing all known errors in the process,
1757 // before successfully creating a surface:
1758 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001761 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
1762 pass = (err != VK_SUCCESS);
1763 ASSERT_TRUE(pass);
1764 m_errorMonitor->VerifyFound();
1765
1766 // Next, try to create a surface with the wrong
1767 // VkXcbSurfaceCreateInfoKHR::sType:
1768 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1769 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1771 "called with the wrong value for");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001772 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
Ian Elliott2c1daf52016-05-12 09:41:46 -06001777 // Create a native window, and then correctly create a surface:
1778 xcb_connection_t *connection;
1779 xcb_screen_t *screen;
1780 xcb_window_t xcb_window;
1781 xcb_intern_atom_reply_t *atom_wm_delete_window;
1782
1783 const xcb_setup_t *setup;
1784 xcb_screen_iterator_t iter;
1785 int scr;
1786 uint32_t value_mask, value_list[32];
1787 int width = 1;
1788 int height = 1;
1789
1790 connection = xcb_connect(NULL, &scr);
1791 ASSERT_TRUE(connection != NULL);
1792 setup = xcb_get_setup(connection);
1793 iter = xcb_setup_roots_iterator(setup);
1794 while (scr-- > 0)
1795 xcb_screen_next(&iter);
1796 screen = iter.data;
1797
1798 xcb_window = xcb_generate_id(connection);
1799
1800 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
1801 value_list[0] = screen->black_pixel;
1802 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE |
1803 XCB_EVENT_MASK_STRUCTURE_NOTIFY;
1804
1805 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window,
1806 screen->root, 0, 0, width, height, 0,
1807 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual,
1808 value_mask, value_list);
1809
1810 /* Magic code that will send notification when window is destroyed */
1811 xcb_intern_atom_cookie_t cookie =
1812 xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
1813 xcb_intern_atom_reply_t *reply =
1814 xcb_intern_atom_reply(connection, cookie, 0);
1815
1816 xcb_intern_atom_cookie_t cookie2 =
1817 xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001818 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001819 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window,
1820 (*reply).atom, 4, 32, 1,
1821 &(*atom_wm_delete_window).atom);
1822 free(reply);
1823
1824 xcb_map_window(connection, xcb_window);
1825
1826 // Force the x/y coordinates to 100,100 results are identical in consecutive
1827 // runs
1828 const uint32_t coords[] = {100, 100};
1829 xcb_configure_window(connection, xcb_window,
1830 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
1831
Ian Elliott2c1daf52016-05-12 09:41:46 -06001832 // Finally, try to correctly create a surface:
1833 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
1834 xcb_create_info.pNext = NULL;
1835 xcb_create_info.flags = 0;
1836 xcb_create_info.connection = connection;
1837 xcb_create_info.window = xcb_window;
1838 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1839 pass = (err == VK_SUCCESS);
1840 ASSERT_TRUE(pass);
1841
Ian Elliott2c1daf52016-05-12 09:41:46 -06001842 // Check if surface supports presentation:
1843
1844 // 1st, do so without having queried the queue families:
1845 VkBool32 supported = false;
1846 // TODO: Get the following error to come out:
1847 m_errorMonitor->SetDesiredFailureMsg(
1848 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1849 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
1850 "function");
1851 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1852 pass = (err != VK_SUCCESS);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001853 // ASSERT_TRUE(pass);
1854 // m_errorMonitor->VerifyFound();
Ian Elliott2c1daf52016-05-12 09:41:46 -06001855
1856 // Next, query a queue family index that's too large:
1857 m_errorMonitor->SetDesiredFailureMsg(
1858 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1859 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001860 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface,
1861 &supported);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001862 pass = (err != VK_SUCCESS);
1863 ASSERT_TRUE(pass);
1864 m_errorMonitor->VerifyFound();
1865
1866 // Finally, do so correctly:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001867 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
1868 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06001869 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1870 pass = (err == VK_SUCCESS);
1871 ASSERT_TRUE(pass);
1872
Ian Elliott2c1daf52016-05-12 09:41:46 -06001873 // Before proceeding, try to create a swapchain without having called
1874 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
1875 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1876 swapchain_create_info.pNext = NULL;
1877 swapchain_create_info.flags = 0;
1878 m_errorMonitor->SetDesiredFailureMsg(
1879 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1880 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001881 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
1882 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001883 pass = (err != VK_SUCCESS);
1884 ASSERT_TRUE(pass);
1885 m_errorMonitor->VerifyFound();
1886
Ian Elliott2c1daf52016-05-12 09:41:46 -06001887 // Get the surface capabilities:
1888 VkSurfaceCapabilitiesKHR surface_capabilities;
1889
1890 // Do so correctly (only error logged by this entrypoint is if the
1891 // extension isn't enabled):
1892 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1893 &surface_capabilities);
1894 pass = (err == VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896
Ian Elliott2c1daf52016-05-12 09:41:46 -06001897 // Get the surface formats:
1898 uint32_t surface_format_count;
1899
1900 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1902 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001903 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
1904 pass = (err == VK_SUCCESS);
1905 ASSERT_TRUE(pass);
1906 m_errorMonitor->VerifyFound();
1907
1908 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
1909 // correctly done a 1st try (to get the count):
1910 m_errorMonitor->SetDesiredFailureMsg(
1911 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1912 "but no prior positive value has been seen for");
1913 surface_format_count = 0;
1914 vkGetPhysicalDeviceSurfaceFormatsKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001915 gpu(), surface, &surface_format_count,
1916 (VkSurfaceFormatKHR *)&surface_format_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001917 pass = (err == VK_SUCCESS);
1918 ASSERT_TRUE(pass);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001922 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1923 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001924 pass = (err == VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926
1927 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001928 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(
1929 surface_format_count * sizeof(VkSurfaceFormatKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001930
1931 // Next, do a 2nd try with surface_format_count being set too high:
1932 surface_format_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1934 "that is greater than the value");
1935 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001936 surface_formats);
1937 pass = (err == VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001942 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
1943 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001944 pass = (err == VK_SUCCESS);
1945 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001946 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count,
Ian Elliott2c1daf52016-05-12 09:41:46 -06001947 surface_formats);
1948 pass = (err == VK_SUCCESS);
1949 ASSERT_TRUE(pass);
1950
Ian Elliott2c1daf52016-05-12 09:41:46 -06001951 // Get the surface present modes:
1952 uint32_t surface_present_mode_count;
1953
1954 // First, try without a pointer to surface_format_count:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1956 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06001957 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
1958 pass = (err == VK_SUCCESS);
1959 ASSERT_TRUE(pass);
1960 m_errorMonitor->VerifyFound();
1961
1962 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
1963 // correctly done a 1st try (to get the count):
1964 m_errorMonitor->SetDesiredFailureMsg(
1965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1966 "but no prior positive value has been seen for");
1967 surface_present_mode_count = 0;
1968 vkGetPhysicalDeviceSurfacePresentModesKHR(
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001969 gpu(), surface, &surface_present_mode_count,
1970 (VkPresentModeKHR *)&surface_present_mode_count);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001971 pass = (err == VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
1975 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001976 vkGetPhysicalDeviceSurfacePresentModesKHR(
1977 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001978 pass = (err == VK_SUCCESS);
1979 ASSERT_TRUE(pass);
1980
1981 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001982 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(
1983 surface_present_mode_count * sizeof(VkPresentModeKHR));
Ian Elliott2c1daf52016-05-12 09:41:46 -06001984
1985 // Next, do a 2nd try with surface_format_count being set too high:
1986 surface_present_mode_count += 5;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1988 "that is greater than the value");
1989 vkGetPhysicalDeviceSurfacePresentModesKHR(
1990 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001991 pass = (err == VK_SUCCESS);
1992 ASSERT_TRUE(pass);
1993 m_errorMonitor->VerifyFound();
1994
1995 // Finally, do a correct 1st and 2nd try:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06001996 vkGetPhysicalDeviceSurfacePresentModesKHR(
1997 gpu(), surface, &surface_present_mode_count, NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06001998 pass = (err == VK_SUCCESS);
1999 ASSERT_TRUE(pass);
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002000 vkGetPhysicalDeviceSurfacePresentModesKHR(
2001 gpu(), surface, &surface_present_mode_count, surface_present_modes);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002002 pass = (err == VK_SUCCESS);
2003 ASSERT_TRUE(pass);
2004
Ian Elliott2c1daf52016-05-12 09:41:46 -06002005 // Create a swapchain:
2006
2007 // First, try without a pointer to swapchain_create_info:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2009 "called with NULL pointer");
Ian Elliott2c1daf52016-05-12 09:41:46 -06002010 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
2011 pass = (err != VK_SUCCESS);
2012 ASSERT_TRUE(pass);
2013 m_errorMonitor->VerifyFound();
2014
2015 // Next, call with a non-NULL swapchain_create_info, that has the wrong
2016 // sType:
2017 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2019 "called with the wrong value for");
2020 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2021 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002022 pass = (err != VK_SUCCESS);
2023 ASSERT_TRUE(pass);
2024 m_errorMonitor->VerifyFound();
2025
2026 // Next, call with a NULL swapchain pointer:
2027 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
2028 swapchain_create_info.pNext = NULL;
2029 swapchain_create_info.flags = 0;
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2031 "called with NULL pointer");
2032 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2033 NULL);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002034 pass = (err != VK_SUCCESS);
2035 ASSERT_TRUE(pass);
2036 m_errorMonitor->VerifyFound();
2037
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002038 // TODO: Enhance swapchain layer so that
2039 // swapchain_create_info.queueFamilyIndexCount is checked against something?
Ian Elliott2c1daf52016-05-12 09:41:46 -06002040
2041 // Next, call with a queue family index that's too large:
2042 uint32_t queueFamilyIndex[2] = {100000, 0};
2043 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2044 swapchain_create_info.queueFamilyIndexCount = 2;
2045 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
2046 m_errorMonitor->SetDesiredFailureMsg(
2047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2048 "called with a queueFamilyIndex that is too large");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002049 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2050 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002051 pass = (err != VK_SUCCESS);
2052 ASSERT_TRUE(pass);
2053 m_errorMonitor->VerifyFound();
2054
2055 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
2056 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
2057 swapchain_create_info.queueFamilyIndexCount = 1;
2058 m_errorMonitor->SetDesiredFailureMsg(
2059 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2060 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
2061 "pCreateInfo->pQueueFamilyIndices).");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002062 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2063 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002064 pass = (err != VK_SUCCESS);
2065 ASSERT_TRUE(pass);
2066 m_errorMonitor->VerifyFound();
2067
2068 // Next, call with an invalid imageSharingMode:
2069 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
2070 swapchain_create_info.queueFamilyIndexCount = 1;
2071 m_errorMonitor->SetDesiredFailureMsg(
2072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2073 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002074 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL,
2075 &swapchain);
Ian Elliott2c1daf52016-05-12 09:41:46 -06002076 pass = (err != VK_SUCCESS);
2077 ASSERT_TRUE(pass);
2078 m_errorMonitor->VerifyFound();
2079 // Fix for the future:
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002080 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
2081 // SUPPORTED
Ian Elliott2c1daf52016-05-12 09:41:46 -06002082 swapchain_create_info.queueFamilyIndexCount = 0;
2083 queueFamilyIndex[0] = 0;
2084 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2085
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002086 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
Ian Elliott2c1daf52016-05-12 09:41:46 -06002087 // Get the images from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002088 // Acquire an image from a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002089 // Present an image to a swapchain:
Ian Elliott2c1daf52016-05-12 09:41:46 -06002090 // Destroy the swapchain:
2091
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002092 // TODOs:
2093 //
2094 // - Try destroying the device without first destroying the swapchain
2095 //
2096 // - Try destroying the device without first destroying the surface
2097 //
2098 // - Try destroying the surface without first destroying the swapchain
Ian Elliott2c1daf52016-05-12 09:41:46 -06002099
2100 // Destroy the surface:
2101 vkDestroySurfaceKHR(instance(), surface, NULL);
2102
Ian Elliott2c1daf52016-05-12 09:41:46 -06002103 // Tear down the window:
2104 xcb_destroy_window(connection, xcb_window);
2105 xcb_disconnect(connection);
2106
2107#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski085d27a2016-05-17 09:34:26 -06002108 return;
Ian Elliott2c1daf52016-05-12 09:41:46 -06002109#endif // VK_USE_PLATFORM_XCB_KHR
2110}
2111
Karl Schultz6addd812016-02-02 17:17:23 -07002112TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2113 VkResult err;
2114 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002115
Karl Schultz6addd812016-02-02 17:17:23 -07002116 m_errorMonitor->SetDesiredFailureMsg(
2117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002118 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
2119
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002120 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002121
2122 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002123 VkImage image;
2124 VkDeviceMemory mem;
2125 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002126
Karl Schultz6addd812016-02-02 17:17:23 -07002127 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2128 const int32_t tex_width = 32;
2129 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002130
Tony Barboureb254902015-07-15 12:50:33 -06002131 VkImageCreateInfo image_create_info = {};
2132 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002133 image_create_info.pNext = NULL;
2134 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2135 image_create_info.format = tex_format;
2136 image_create_info.extent.width = tex_width;
2137 image_create_info.extent.height = tex_height;
2138 image_create_info.extent.depth = 1;
2139 image_create_info.mipLevels = 1;
2140 image_create_info.arrayLayers = 1;
2141 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2142 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2143 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2144 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002145
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002146 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002147 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002148 mem_alloc.pNext = NULL;
2149 mem_alloc.allocationSize = 0;
2150 // Introduce failure, do NOT set memProps to
2151 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
2152 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002153
Chia-I Wuf7458c52015-10-26 21:10:41 +08002154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002155 ASSERT_VK_SUCCESS(err);
2156
Karl Schultz6addd812016-02-02 17:17:23 -07002157 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002158
Mark Lobodzinski23065352015-05-29 09:32:35 -05002159 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002160
Karl Schultz6addd812016-02-02 17:17:23 -07002161 pass =
2162 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
2163 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
2164 if (!pass) { // If we can't find any unmappable memory this test doesn't
2165 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002166 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002167 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002168 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002169
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002170 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002171 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002172 ASSERT_VK_SUCCESS(err);
2173
2174 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002175 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002176 ASSERT_VK_SUCCESS(err);
2177
2178 // Map memory as if to initialize the image
2179 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07002180 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
2181 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002183 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002184
Chia-I Wuf7458c52015-10-26 21:10:41 +08002185 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002186 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002187}
2188
Karl Schultz6addd812016-02-02 17:17:23 -07002189TEST_F(VkLayerTest, RebindMemory) {
2190 VkResult err;
2191 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002192
Karl Schultz6addd812016-02-02 17:17:23 -07002193 m_errorMonitor->SetDesiredFailureMsg(
2194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002195 "which has already been bound to mem object");
2196
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002197 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002198
2199 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002200 VkImage image;
2201 VkDeviceMemory mem1;
2202 VkDeviceMemory mem2;
2203 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002204
Karl Schultz6addd812016-02-02 17:17:23 -07002205 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2206 const int32_t tex_width = 32;
2207 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002208
Tony Barboureb254902015-07-15 12:50:33 -06002209 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002210 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2211 image_create_info.pNext = NULL;
2212 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2213 image_create_info.format = tex_format;
2214 image_create_info.extent.width = tex_width;
2215 image_create_info.extent.height = tex_height;
2216 image_create_info.extent.depth = 1;
2217 image_create_info.mipLevels = 1;
2218 image_create_info.arrayLayers = 1;
2219 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2220 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2221 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2222 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002223
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002224 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002225 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2226 mem_alloc.pNext = NULL;
2227 mem_alloc.allocationSize = 0;
2228 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002229
Karl Schultz6addd812016-02-02 17:17:23 -07002230 // Introduce failure, do NOT set memProps to
2231 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002232 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002234 ASSERT_VK_SUCCESS(err);
2235
Karl Schultz6addd812016-02-02 17:17:23 -07002236 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002237
2238 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002239 pass =
2240 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002241 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002242
2243 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002245 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002247 ASSERT_VK_SUCCESS(err);
2248
2249 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002250 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002251 ASSERT_VK_SUCCESS(err);
2252
Karl Schultz6addd812016-02-02 17:17:23 -07002253 // Introduce validation failure, try to bind a different memory object to
2254 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002255 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002256
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002257 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002258
Chia-I Wuf7458c52015-10-26 21:10:41 +08002259 vkDestroyImage(m_device->device(), image, NULL);
2260 vkFreeMemory(m_device->device(), mem1, NULL);
2261 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002262}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002263
Karl Schultz6addd812016-02-02 17:17:23 -07002264TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002265 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002266
Karl Schultz6addd812016-02-02 17:17:23 -07002267 m_errorMonitor->SetDesiredFailureMsg(
2268 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
2269 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002270
2271 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002272 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2273 fenceInfo.pNext = NULL;
2274 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002275
Tony Barbour300a6082015-04-07 13:44:53 -06002276 ASSERT_NO_FATAL_FAILURE(InitState());
2277 ASSERT_NO_FATAL_FAILURE(InitViewport());
2278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2279
Tony Barbourfe3351b2015-07-28 10:17:20 -06002280 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002281 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2282 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06002283 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002284
2285 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002286
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002287 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002288 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2289 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002290 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002291 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002292 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002293 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002295 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002296 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002297
2298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002299 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002300
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002301 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002302}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002303// This is a positive test. We used to expect error in this case but spec now
2304// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07002305TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002306 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002307 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002308 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002309 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2310 fenceInfo.pNext = NULL;
2311
Tony Barbour0b4d9562015-04-09 10:48:04 -06002312 ASSERT_NO_FATAL_FAILURE(InitState());
2313 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08002314 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002315 VkResult result = vkResetFences(m_device->device(), 1, fences);
2316 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06002317
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06002318 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06002319}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002320
Chris Forbes18127d12016-06-08 16:52:28 +12002321TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync)
2322{
2323 m_errorMonitor->ExpectSuccess();
2324
2325 ASSERT_NO_FATAL_FAILURE(InitState());
2326 VkResult err;
2327
2328 // Record (empty!) command buffer that can be submitted multiple times
2329 // simultaneously.
2330 VkCommandBufferBeginInfo cbbi = {
2331 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
2332 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr
2333 };
2334 m_commandBuffer->BeginCommandBuffer(&cbbi);
2335 m_commandBuffer->EndCommandBuffer();
2336
2337 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
2338 VkFence fence;
2339 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
2343 VkSemaphore s1, s2;
2344 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
2345 ASSERT_VK_SUCCESS(err);
2346 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
2347 ASSERT_VK_SUCCESS(err);
2348
2349 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
2350 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
2351 1, &m_commandBuffer->handle(), 1, &s1 };
2352 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
2353 ASSERT_VK_SUCCESS(err);
2354
2355 // Submit CB again, signaling s2.
2356 si.pSignalSemaphores = &s2;
2357 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
2358 ASSERT_VK_SUCCESS(err);
2359
2360 // Wait for fence.
2361 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2362 ASSERT_VK_SUCCESS(err);
2363
2364 // CB is still in flight from second submission, but semaphore s1 is no
2365 // longer in flight. delete it.
2366 vkDestroySemaphore(m_device->device(), s1, nullptr);
2367
2368 m_errorMonitor->VerifyNotFound();
2369
2370 // Force device idle and clean up remaining objects
2371 vkDeviceWaitIdle(m_device->device());
2372 vkDestroySemaphore(m_device->device(), s2, nullptr);
2373 vkDestroyFence(m_device->device(), fence, nullptr);
2374}
2375
Tobin Ehlis41376e12015-07-03 08:45:14 -06002376TEST_F(VkLayerTest, InvalidUsageBits)
2377{
Tony Barbourf92621a2016-05-02 14:28:12 -06002378 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002379 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06002380 "Initialize buffer with wrong usage then perform copy expecting errors "
2381 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002383 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002384
2385 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06002386 VkImageObj image(m_device);
2387 // Initialize image with USAGE_INPUT_ATTACHMENT
Tobin Ehlis8b313c02016-05-25 15:01:52 -06002388 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002389 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
2390 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002391
Tony Barbourf92621a2016-05-02 14:28:12 -06002392 VkImageView dsv;
2393 VkImageViewCreateInfo dsvci = {};
2394 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2395 dsvci.image = image.handle();
2396 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
2397 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
2398 dsvci.subresourceRange.layerCount = 1;
2399 dsvci.subresourceRange.baseMipLevel = 0;
2400 dsvci.subresourceRange.levelCount = 1;
2401 dsvci.subresourceRange.aspectMask =
2402 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002403
Tony Barbourf92621a2016-05-02 14:28:12 -06002404 // Create a view with depth / stencil aspect for image with different usage
2405 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002408
2409 // Initialize buffer with TRANSFER_DST usage
2410 vk_testing::Buffer buffer;
2411 VkMemoryPropertyFlags reqs = 0;
2412 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2413 VkBufferImageCopy region = {};
2414 region.bufferRowLength = 128;
2415 region.bufferImageHeight = 128;
2416 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2417 region.imageSubresource.layerCount = 1;
2418 region.imageExtent.height = 16;
2419 region.imageExtent.width = 16;
2420 region.imageExtent.depth = 1;
2421
2422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2423 "Invalid usage flag for buffer ");
2424 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2425 // TRANSFER_DST
2426 BeginCommandBuffer();
2427 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2428 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2429 1, &region);
2430 m_errorMonitor->VerifyFound();
2431
2432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2433 "Invalid usage flag for image ");
2434 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
2435 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2436 1, &region);
2437 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002438}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002439#endif // MEM_TRACKER_TESTS
2440
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002441#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002442
2443TEST_F(VkLayerTest, LeakAnObject) {
2444 VkResult err;
2445
2446 TEST_DESCRIPTION(
2447 "Create a fence and destroy its device without first destroying the fence.");
2448
2449 // Note that we have to create a new device since destroying the
2450 // framework's device causes Teardown() to fail and just calling Teardown
2451 // will destroy the errorMonitor.
2452
2453 m_errorMonitor->SetDesiredFailureMsg(
2454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2455 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
2456
2457 ASSERT_NO_FATAL_FAILURE(InitState());
2458
2459 const std::vector<VkQueueFamilyProperties> queue_props =
2460 m_device->queue_props;
2461 std::vector<VkDeviceQueueCreateInfo> queue_info;
2462 queue_info.reserve(queue_props.size());
2463 std::vector<std::vector<float>> queue_priorities;
2464 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2465 VkDeviceQueueCreateInfo qi = {};
2466 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2467 qi.pNext = NULL;
2468 qi.queueFamilyIndex = i;
2469 qi.queueCount = queue_props[i].queueCount;
2470 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2471 qi.pQueuePriorities = queue_priorities[i].data();
2472 queue_info.push_back(qi);
2473 }
2474
2475 std::vector<const char *> device_layer_names;
2476 std::vector<const char *> device_extension_names;
2477 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
2478 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
2479 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
2480 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
2481 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
2482 device_layer_names.push_back("VK_LAYER_LUNARG_image");
2483 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
2484
2485 // The sacrificial device object
2486 VkDevice testDevice;
2487 VkDeviceCreateInfo device_create_info = {};
2488 auto features = m_device->phy().features();
2489 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2490 device_create_info.pNext = NULL;
2491 device_create_info.queueCreateInfoCount = queue_info.size();
2492 device_create_info.pQueueCreateInfos = queue_info.data();
2493 device_create_info.enabledLayerCount = device_layer_names.size();
2494 device_create_info.ppEnabledLayerNames = device_layer_names.data();
2495 device_create_info.pEnabledFeatures = &features;
2496 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2497 ASSERT_VK_SUCCESS(err);
2498
2499 VkFence fence;
2500 VkFenceCreateInfo fence_create_info = {};
2501 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2502 fence_create_info.pNext = NULL;
2503 fence_create_info.flags = 0;
2504 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 // Induce failure by not calling vkDestroyFence
2508 vkDestroyDevice(testDevice, NULL);
2509 m_errorMonitor->VerifyFound();
2510}
2511
2512TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2513
2514 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2515 "attempt to delete them from another.");
2516
2517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2518 "FreeCommandBuffers is attempting to free Command Buffer");
2519
2520 VkCommandPool command_pool_one;
2521 VkCommandPool command_pool_two;
2522
2523 VkCommandPoolCreateInfo pool_create_info{};
2524 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2525 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2526 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2527
2528 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2529 &command_pool_one);
2530
2531 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2532 &command_pool_two);
2533
2534 VkCommandBuffer command_buffer[9];
2535 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2536 command_buffer_allocate_info.sType =
2537 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2538 command_buffer_allocate_info.commandPool = command_pool_one;
2539 command_buffer_allocate_info.commandBufferCount = 9;
2540 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2541 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2542 command_buffer);
2543
2544 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
2545 &command_buffer[3]);
2546
2547 m_errorMonitor->VerifyFound();
2548
2549 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2550 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2551}
2552
2553TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2554 VkResult err;
2555
2556 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
2557 "attempt to delete them from another.");
2558
2559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2560 "FreeDescriptorSets is attempting to free descriptorSet");
2561
2562 ASSERT_NO_FATAL_FAILURE(InitState());
2563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2564
2565 VkDescriptorPoolSize ds_type_count = {};
2566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2567 ds_type_count.descriptorCount = 1;
2568
2569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2571 ds_pool_ci.pNext = NULL;
2572 ds_pool_ci.flags = 0;
2573 ds_pool_ci.maxSets = 1;
2574 ds_pool_ci.poolSizeCount = 1;
2575 ds_pool_ci.pPoolSizes = &ds_type_count;
2576
2577 VkDescriptorPool ds_pool_one;
2578 err =
2579 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
2580 ASSERT_VK_SUCCESS(err);
2581
2582 // Create a second descriptor pool
2583 VkDescriptorPool ds_pool_two;
2584 err =
2585 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
2586 ASSERT_VK_SUCCESS(err);
2587
2588 VkDescriptorSetLayoutBinding dsl_binding = {};
2589 dsl_binding.binding = 0;
2590 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2591 dsl_binding.descriptorCount = 1;
2592 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2593 dsl_binding.pImmutableSamplers = NULL;
2594
2595 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2596 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2597 ds_layout_ci.pNext = NULL;
2598 ds_layout_ci.bindingCount = 1;
2599 ds_layout_ci.pBindings = &dsl_binding;
2600
2601 VkDescriptorSetLayout ds_layout;
2602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2603 &ds_layout);
2604 ASSERT_VK_SUCCESS(err);
2605
2606 VkDescriptorSet descriptorSet;
2607 VkDescriptorSetAllocateInfo alloc_info = {};
2608 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2609 alloc_info.descriptorSetCount = 1;
2610 alloc_info.descriptorPool = ds_pool_one;
2611 alloc_info.pSetLayouts = &ds_layout;
2612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2613 &descriptorSet);
2614 ASSERT_VK_SUCCESS(err);
2615
2616 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2617
2618 m_errorMonitor->VerifyFound();
2619
2620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2621 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2622 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2623}
2624
2625TEST_F(VkLayerTest, CreateUnknownObject) {
2626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2627 "Invalid VkImage Object ");
2628
2629 TEST_DESCRIPTION(
2630 "Pass an invalid image object handle into a Vulkan API call.");
2631
2632 ASSERT_NO_FATAL_FAILURE(InitState());
2633
2634 // Pass bogus handle into GetImageMemoryRequirements
2635 VkMemoryRequirements mem_reqs;
2636 uint64_t fakeImageHandle = 0xCADECADE;
2637 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2638
2639 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2640
2641 m_errorMonitor->VerifyFound();
2642}
2643
Karl Schultz6addd812016-02-02 17:17:23 -07002644TEST_F(VkLayerTest, PipelineNotBound) {
2645 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002646
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002647 TEST_DESCRIPTION(
2648 "Pass in an invalid pipeline object handle into a Vulkan API call.");
2649
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002651 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002652
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002653 ASSERT_NO_FATAL_FAILURE(InitState());
2654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002655
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2658 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002659
2660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2662 ds_pool_ci.pNext = NULL;
2663 ds_pool_ci.maxSets = 1;
2664 ds_pool_ci.poolSizeCount = 1;
2665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002666
2667 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002668 err =
2669 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002670 ASSERT_VK_SUCCESS(err);
2671
2672 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002673 dsl_binding.binding = 0;
2674 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2675 dsl_binding.descriptorCount = 1;
2676 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2677 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002678
2679 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002680 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2681 ds_layout_ci.pNext = NULL;
2682 ds_layout_ci.bindingCount = 1;
2683 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002684
2685 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002686 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2687 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002688 ASSERT_VK_SUCCESS(err);
2689
2690 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002691 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002692 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002693 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002694 alloc_info.descriptorPool = ds_pool;
2695 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002696 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2697 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002698 ASSERT_VK_SUCCESS(err);
2699
2700 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002701 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2702 pipeline_layout_ci.pNext = NULL;
2703 pipeline_layout_ci.setLayoutCount = 1;
2704 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002705
2706 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002707 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
2708 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002709 ASSERT_VK_SUCCESS(err);
2710
Mark Youngad779052016-01-06 14:26:04 -07002711 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002712
2713 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002714 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
2715 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002717 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002718
Chia-I Wuf7458c52015-10-26 21:10:41 +08002719 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002722}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002723#if 0 // Disabling this test for now, needs to be updated
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002724TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2725 VkResult err;
2726
2727 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2728 "during bind[Buffer|Image]Memory time");
2729
2730 m_errorMonitor->SetDesiredFailureMsg(
2731 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2732 "for this object type are not compatible with the memory");
2733
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // Create an image, allocate memory, set a bad typeIndex and then try to
2737 // bind it
2738 VkImage image;
2739 VkDeviceMemory mem;
2740 VkMemoryRequirements mem_reqs;
2741 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2742 const int32_t tex_width = 32;
2743 const int32_t tex_height = 32;
2744
2745 VkImageCreateInfo image_create_info = {};
2746 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2747 image_create_info.pNext = NULL;
2748 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2749 image_create_info.format = tex_format;
2750 image_create_info.extent.width = tex_width;
2751 image_create_info.extent.height = tex_height;
2752 image_create_info.extent.depth = 1;
2753 image_create_info.mipLevels = 1;
2754 image_create_info.arrayLayers = 1;
2755 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2756 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2757 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2758 image_create_info.flags = 0;
2759
2760 VkMemoryAllocateInfo mem_alloc = {};
2761 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 mem_alloc.pNext = NULL;
2763 mem_alloc.allocationSize = 0;
2764 mem_alloc.memoryTypeIndex = 0;
2765
2766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2767 ASSERT_VK_SUCCESS(err);
2768
2769 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2770 mem_alloc.allocationSize = mem_reqs.size;
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002771 // TODO : This is not an ideal way to cause the error and triggers a segF
2772 // on at least one android driver when attempting to Allocate the memory.
2773 // That segF may or may not be a driver bug, but really what we want to do
2774 // here is find a device-supported memory type that is also not supported
2775 // for the particular image we're binding the memory too. If no such
2776 // type exists, then we can print a message and skip the test.
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002777 // Introduce Failure, select likely invalid TypeIndex
2778 mem_alloc.memoryTypeIndex = 31;
2779
2780 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2781 ASSERT_VK_SUCCESS(err);
2782
2783 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2784 (void)err;
2785
2786 m_errorMonitor->VerifyFound();
2787
2788 vkDestroyImage(m_device->device(), image, NULL);
2789 vkFreeMemory(m_device->device(), mem, NULL);
2790}
Tobin Ehlis93d57e12016-06-20 11:32:13 -06002791#endif
Karl Schultz6addd812016-02-02 17:17:23 -07002792TEST_F(VkLayerTest, BindInvalidMemory) {
2793 VkResult err;
2794 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002795
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002797 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002798
Tobin Ehlisec598302015-09-15 15:02:17 -06002799 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002800
2801 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002802 VkImage image;
2803 VkDeviceMemory mem;
2804 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002805
Karl Schultz6addd812016-02-02 17:17:23 -07002806 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2807 const int32_t tex_width = 32;
2808 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002809
2810 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002811 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2812 image_create_info.pNext = NULL;
2813 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2814 image_create_info.format = tex_format;
2815 image_create_info.extent.width = tex_width;
2816 image_create_info.extent.height = tex_height;
2817 image_create_info.extent.depth = 1;
2818 image_create_info.mipLevels = 1;
2819 image_create_info.arrayLayers = 1;
2820 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2821 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2822 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2823 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002824
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002825 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002826 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2827 mem_alloc.pNext = NULL;
2828 mem_alloc.allocationSize = 0;
2829 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002830
Chia-I Wuf7458c52015-10-26 21:10:41 +08002831 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002832 ASSERT_VK_SUCCESS(err);
2833
Karl Schultz6addd812016-02-02 17:17:23 -07002834 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002835
2836 mem_alloc.allocationSize = mem_reqs.size;
2837
Karl Schultz6addd812016-02-02 17:17:23 -07002838 pass =
2839 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002840 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002841
2842 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002843 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002844 ASSERT_VK_SUCCESS(err);
2845
2846 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002847 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002848
2849 // Try to bind free memory that has been freed
2850 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2851 // This may very well return an error.
2852 (void)err;
2853
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002854 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002855
Chia-I Wuf7458c52015-10-26 21:10:41 +08002856 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002857}
2858
Karl Schultz6addd812016-02-02 17:17:23 -07002859TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2860 VkResult err;
2861 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002862
Karl Schultz6addd812016-02-02 17:17:23 -07002863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2864 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002865
Tobin Ehlisec598302015-09-15 15:02:17 -06002866 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002867
Karl Schultz6addd812016-02-02 17:17:23 -07002868 // Create an image object, allocate memory, destroy the object and then try
2869 // to bind it
2870 VkImage image;
2871 VkDeviceMemory mem;
2872 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002873
Karl Schultz6addd812016-02-02 17:17:23 -07002874 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2875 const int32_t tex_width = 32;
2876 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002877
2878 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002879 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2880 image_create_info.pNext = NULL;
2881 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2882 image_create_info.format = tex_format;
2883 image_create_info.extent.width = tex_width;
2884 image_create_info.extent.height = tex_height;
2885 image_create_info.extent.depth = 1;
2886 image_create_info.mipLevels = 1;
2887 image_create_info.arrayLayers = 1;
2888 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2889 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2890 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2891 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002892
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002893 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002894 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2895 mem_alloc.pNext = NULL;
2896 mem_alloc.allocationSize = 0;
2897 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002898
Chia-I Wuf7458c52015-10-26 21:10:41 +08002899 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002900 ASSERT_VK_SUCCESS(err);
2901
Karl Schultz6addd812016-02-02 17:17:23 -07002902 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002903
2904 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07002905 pass =
2906 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002907 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002908
2909 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002910 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002911 ASSERT_VK_SUCCESS(err);
2912
2913 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002914 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002915 ASSERT_VK_SUCCESS(err);
2916
2917 // Now Try to bind memory to this destroyed object
2918 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2919 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002920 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002922 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002923
Chia-I Wuf7458c52015-10-26 21:10:41 +08002924 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002925}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002926
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002927#endif // OBJ_TRACKER_TESTS
2928
Tobin Ehlis0788f522015-05-26 16:11:58 -06002929#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002930
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06002931// This is a positive test. No errors are expected.
2932TEST_F(VkLayerTest, StencilLoadOp) {
2933 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
2934 "CLEAR. stencil[Load|Store]Op used to be ignored.");
2935 VkResult result = VK_SUCCESS;
2936 VkImageFormatProperties formatProps;
2937 vkGetPhysicalDeviceImageFormatProperties(
2938 gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D,
2939 VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2940 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
2941 0, &formatProps);
2942 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
2943 return;
2944 }
2945
2946 ASSERT_NO_FATAL_FAILURE(InitState());
2947 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
2948 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
2949 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
2950 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
2951 VkAttachmentDescription att = {};
2952 VkAttachmentReference ref = {};
2953 att.format = depth_stencil_fmt;
2954 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
2955 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
2956 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
2957 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
2958 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2959 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2960
2961 VkClearValue clear;
2962 clear.depthStencil.depth = 1.0;
2963 clear.depthStencil.stencil = 0;
2964 ref.attachment = 0;
2965 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2966
2967 VkSubpassDescription subpass = {};
2968 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
2969 subpass.flags = 0;
2970 subpass.inputAttachmentCount = 0;
2971 subpass.pInputAttachments = NULL;
2972 subpass.colorAttachmentCount = 0;
2973 subpass.pColorAttachments = NULL;
2974 subpass.pResolveAttachments = NULL;
2975 subpass.pDepthStencilAttachment = &ref;
2976 subpass.preserveAttachmentCount = 0;
2977 subpass.pPreserveAttachments = NULL;
2978
2979 VkRenderPass rp;
2980 VkRenderPassCreateInfo rp_info = {};
2981 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2982 rp_info.attachmentCount = 1;
2983 rp_info.pAttachments = &att;
2984 rp_info.subpassCount = 1;
2985 rp_info.pSubpasses = &subpass;
2986 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
2987 ASSERT_VK_SUCCESS(result);
2988
2989 VkImageView *depthView = m_depthStencil->BindInfo();
2990 VkFramebufferCreateInfo fb_info = {};
2991 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
2992 fb_info.pNext = NULL;
2993 fb_info.renderPass = rp;
2994 fb_info.attachmentCount = 1;
2995 fb_info.pAttachments = depthView;
2996 fb_info.width = 100;
2997 fb_info.height = 100;
2998 fb_info.layers = 1;
2999 VkFramebuffer fb;
3000 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3001 ASSERT_VK_SUCCESS(result);
3002
3003
3004 VkRenderPassBeginInfo rpbinfo = {};
3005 rpbinfo.clearValueCount = 1;
3006 rpbinfo.pClearValues = &clear;
3007 rpbinfo.pNext = NULL;
3008 rpbinfo.renderPass = rp;
3009 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
3010 rpbinfo.renderArea.extent.width = 100;
3011 rpbinfo.renderArea.extent.height = 100;
3012 rpbinfo.renderArea.offset.x = 0;
3013 rpbinfo.renderArea.offset.y = 0;
3014 rpbinfo.framebuffer = fb;
3015
3016 VkFence fence = {};
3017 VkFenceCreateInfo fence_ci = {};
3018 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3019 fence_ci.pNext = nullptr;
3020 fence_ci.flags = 0;
3021 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
3022 ASSERT_VK_SUCCESS(result);
3023
3024
3025 m_commandBuffer->BeginCommandBuffer();
3026 m_commandBuffer->BeginRenderPass(rpbinfo);
3027 m_commandBuffer->EndRenderPass();
3028 m_commandBuffer->EndCommandBuffer();
3029 m_commandBuffer->QueueCommandBuffer(fence);
3030
3031 VkImageObj destImage(m_device);
3032 destImage.init(100, 100, depth_stencil_fmt,
3033 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
3034 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
3035 VK_IMAGE_TILING_OPTIMAL, 0);
3036 VkImageMemoryBarrier barrier = {};
3037 VkImageSubresourceRange range;
3038 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
3039 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3040 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3041 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT |
3042 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
3043 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3044 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3045 barrier.image = m_depthStencil->handle();
3046 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3047 range.baseMipLevel = 0;
3048 range.levelCount = 1;
3049 range.baseArrayLayer = 0;
3050 range.layerCount = 1;
3051 barrier.subresourceRange = range;
3052 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3053 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
3054 cmdbuf.BeginCommandBuffer();
3055 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3056 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3057 nullptr, 1, &barrier);
3058 barrier.srcAccessMask = 0;
3059 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3060 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3061 barrier.image = destImage.handle();
3062 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT |
3063 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
3064 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3065 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0,
3066 nullptr, 1, &barrier);
3067 VkImageCopy cregion;
3068 cregion.srcSubresource.aspectMask =
3069 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3070 cregion.srcSubresource.mipLevel = 0;
3071 cregion.srcSubresource.baseArrayLayer = 0;
3072 cregion.srcSubresource.layerCount = 1;
3073 cregion.srcOffset.x = 0;
3074 cregion.srcOffset.y = 0;
3075 cregion.srcOffset.z = 0;
3076 cregion.dstSubresource.aspectMask =
3077 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
3078 cregion.dstSubresource.mipLevel = 0;
3079 cregion.dstSubresource.baseArrayLayer = 0;
3080 cregion.dstSubresource.layerCount = 1;
3081 cregion.dstOffset.x = 0;
3082 cregion.dstOffset.y = 0;
3083 cregion.dstOffset.z = 0;
3084 cregion.extent.width = 100;
3085 cregion.extent.height = 100;
3086 cregion.extent.depth = 1;
3087 cmdbuf.CopyImage(m_depthStencil->handle(),
3088 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
3089 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
3090 cmdbuf.EndCommandBuffer();
3091
3092 VkSubmitInfo submit_info;
3093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3094 submit_info.pNext = NULL;
3095 submit_info.waitSemaphoreCount = 0;
3096 submit_info.pWaitSemaphores = NULL;
3097 submit_info.pWaitDstStageMask = NULL;
3098 submit_info.commandBufferCount = 1;
3099 submit_info.pCommandBuffers = &cmdbuf.handle();
3100 submit_info.signalSemaphoreCount = 0;
3101 submit_info.pSignalSemaphores = NULL;
3102
3103 m_errorMonitor->ExpectSuccess();
3104 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3105 m_errorMonitor->VerifyNotFound();
3106
Mark Lobodzinskid0440da2016-06-17 15:10:03 -06003107 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinskice7eee72016-06-14 16:33:29 -06003108 vkDestroyFence(m_device->device(), fence, nullptr);
3109 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3110 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3111}
3112
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003113TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3114 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3115 "attachment reference of VK_ATTACHMENT_UNUSED");
3116
3117 ASSERT_NO_FATAL_FAILURE(InitState());
3118 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3119
3120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3121 "must not be VK_ATTACHMENT_UNUSED");
3122
3123 VkAttachmentReference color_attach = {};
3124 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3125 color_attach.attachment = 0;
3126 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3127 VkSubpassDescription subpass = {};
3128 subpass.colorAttachmentCount = 1;
3129 subpass.pColorAttachments = &color_attach;
3130 subpass.preserveAttachmentCount = 1;
3131 subpass.pPreserveAttachments = &preserve_attachment;
3132
3133 VkRenderPassCreateInfo rpci = {};
3134 rpci.subpassCount = 1;
3135 rpci.pSubpasses = &subpass;
3136 rpci.attachmentCount = 1;
3137 VkAttachmentDescription attach_desc = {};
3138 attach_desc.format = VK_FORMAT_UNDEFINED;
3139 rpci.pAttachments = &attach_desc;
3140 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3141 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003142 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003143
3144 m_errorMonitor->VerifyFound();
3145
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003146 if (result == VK_SUCCESS) {
3147 vkDestroyRenderPass(m_device->device(), rp, NULL);
3148 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003149}
3150
3151TEST_F(VkLayerTest, AttachmentUsageMismatch) {
3152 TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image "
3153 "in the depthStencil attachment point");
3154
3155 ASSERT_NO_FATAL_FAILURE(InitState());
3156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3157
3158 m_errorMonitor->SetDesiredFailureMsg(
3159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3160 "conflicts with the image's IMAGE_USAGE flags");
3161
3162 // Create a renderPass with a depth-stencil attachment created with
3163 // IMAGE_USAGE_COLOR_ATTACHMENT
3164 VkAttachmentReference attach = {};
3165 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3166 VkSubpassDescription subpass = {};
3167 // Add our color attachment to pDepthStencilAttachment
3168 subpass.pDepthStencilAttachment = &attach;
3169 VkRenderPassCreateInfo rpci = {};
3170 rpci.subpassCount = 1;
3171 rpci.pSubpasses = &subpass;
3172 rpci.attachmentCount = 1;
3173 VkAttachmentDescription attach_desc = {};
3174 attach_desc.format = VK_FORMAT_UNDEFINED;
3175 rpci.pAttachments = &attach_desc;
3176 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3177 VkRenderPass rp;
3178 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3179 ASSERT_VK_SUCCESS(err);
3180
3181 VkImageView imageView =
3182 m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3183 VkFramebufferCreateInfo fb_info = {};
3184 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3185 fb_info.pNext = NULL;
3186 fb_info.renderPass = rp;
3187 fb_info.attachmentCount = 1;
3188 fb_info.pAttachments = &imageView;
3189 fb_info.width = 100;
3190 fb_info.height = 100;
3191 fb_info.layers = 1;
3192
3193 VkFramebuffer fb;
3194 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3195
3196 m_errorMonitor->VerifyFound();
3197
3198 if (err == VK_SUCCESS) {
3199 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3200 }
3201 vkDestroyRenderPass(m_device->device(), rp, NULL);
3202}
3203
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003204// This is a positive test. No errors should be generated.
Michael Lentine860b0fe2016-05-20 10:14:00 -05003205TEST_F(VkLayerTest, WaitEventThenSet) {
3206 TEST_DESCRIPTION(
3207 "Wait on a event then set it after the wait has been submitted.");
3208
Michael Lentine860b0fe2016-05-20 10:14:00 -05003209 m_errorMonitor->ExpectSuccess();
3210
3211 VkEvent event;
3212 VkEventCreateInfo event_create_info{};
3213 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3214 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3215
3216 VkCommandPool command_pool;
3217 VkCommandPoolCreateInfo pool_create_info{};
3218 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3219 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3220 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3221 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3222 &command_pool);
3223
3224 VkCommandBuffer command_buffer;
3225 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3226 command_buffer_allocate_info.sType =
3227 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3228 command_buffer_allocate_info.commandPool = command_pool;
3229 command_buffer_allocate_info.commandBufferCount = 1;
3230 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3231 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3232 &command_buffer);
3233
3234 VkQueue queue = VK_NULL_HANDLE;
3235 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003236 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003237
3238 {
3239 VkCommandBufferBeginInfo begin_info{};
3240 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3241 vkBeginCommandBuffer(command_buffer, &begin_info);
3242
3243 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT,
3244 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3245 nullptr, 0, nullptr);
3246 vkCmdResetEvent(command_buffer, event,
3247 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3248 vkEndCommandBuffer(command_buffer);
3249 }
3250 {
3251 VkSubmitInfo submit_info{};
3252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3253 submit_info.commandBufferCount = 1;
3254 submit_info.pCommandBuffers = &command_buffer;
3255 submit_info.signalSemaphoreCount = 0;
3256 submit_info.pSignalSemaphores = nullptr;
3257 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3258 }
3259 { vkSetEvent(m_device->device(), event); }
3260
3261 vkQueueWaitIdle(queue);
3262
3263 vkDestroyEvent(m_device->device(), event, nullptr);
3264 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3265 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3266
3267 m_errorMonitor->VerifyNotFound();
3268}
Michael Lentine5627e692016-05-20 17:45:02 -05003269// This is a positive test. No errors should be generated.
3270TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) {
3271 TEST_DESCRIPTION(
3272 "Issue a query and copy from it on a second command buffer.");
3273
3274 if ((m_device->queue_props.empty()) ||
3275 (m_device->queue_props[0].queueCount < 2))
3276 return;
3277
3278 m_errorMonitor->ExpectSuccess();
3279
3280 VkQueryPool query_pool;
3281 VkQueryPoolCreateInfo query_pool_create_info{};
3282 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
3283 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
3284 query_pool_create_info.queryCount = 1;
3285 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr,
3286 &query_pool);
3287
3288 VkCommandPool command_pool;
3289 VkCommandPoolCreateInfo pool_create_info{};
3290 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3291 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3292 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3293 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3294 &command_pool);
3295
3296 VkCommandBuffer command_buffer[2];
3297 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3298 command_buffer_allocate_info.sType =
3299 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3300 command_buffer_allocate_info.commandPool = command_pool;
3301 command_buffer_allocate_info.commandBufferCount = 2;
3302 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3303 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3304 command_buffer);
3305
3306 VkQueue queue = VK_NULL_HANDLE;
3307 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3308 1, &queue);
3309
3310 uint32_t qfi = 0;
3311 VkBufferCreateInfo buff_create_info = {};
3312 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3313 buff_create_info.size = 1024;
3314 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
3315 buff_create_info.queueFamilyIndexCount = 1;
3316 buff_create_info.pQueueFamilyIndices = &qfi;
3317
3318 VkResult err;
3319 VkBuffer buffer;
3320 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
3321 ASSERT_VK_SUCCESS(err);
3322 VkMemoryAllocateInfo mem_alloc = {};
3323 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3324 mem_alloc.pNext = NULL;
3325 mem_alloc.allocationSize = 1024;
3326 mem_alloc.memoryTypeIndex = 0;
3327
3328 VkMemoryRequirements memReqs;
3329 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
3330 bool pass =
3331 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
3332 if (!pass) {
3333 vkDestroyBuffer(m_device->device(), buffer, NULL);
3334 return;
3335 }
3336
3337 VkDeviceMemory mem;
3338 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3339 ASSERT_VK_SUCCESS(err);
3340 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3341 ASSERT_VK_SUCCESS(err);
3342
3343 {
3344 VkCommandBufferBeginInfo begin_info{};
3345 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3346 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3347
3348 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
3349 vkCmdWriteTimestamp(command_buffer[0],
3350 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
3351
3352 vkEndCommandBuffer(command_buffer[0]);
3353
3354 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3355
3356 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer,
3357 0, 0, 0);
3358
3359 vkEndCommandBuffer(command_buffer[1]);
3360 }
3361 {
3362 VkSubmitInfo submit_info{};
3363 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3364 submit_info.commandBufferCount = 2;
3365 submit_info.pCommandBuffers = command_buffer;
3366 submit_info.signalSemaphoreCount = 0;
3367 submit_info.pSignalSemaphores = nullptr;
3368 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3369 }
3370
3371 vkQueueWaitIdle(queue);
3372
3373 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
3374 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
3375 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06003376 vkDestroyBuffer(m_device->device(), buffer, NULL);
3377 vkFreeMemory(m_device->device(), mem, NULL);
Michael Lentine5627e692016-05-20 17:45:02 -05003378
3379 m_errorMonitor->VerifyNotFound();
3380}
Michael Lentine860b0fe2016-05-20 10:14:00 -05003381
3382TEST_F(VkLayerTest, ResetEventThenSet) {
3383 TEST_DESCRIPTION(
3384 "Reset an event then set it after the reset has been submitted.");
3385
Michael Lentine860b0fe2016-05-20 10:14:00 -05003386 m_errorMonitor->ExpectSuccess();
3387
3388 VkEvent event;
3389 VkEventCreateInfo event_create_info{};
3390 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
3391 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
3392
3393 VkCommandPool command_pool;
3394 VkCommandPoolCreateInfo pool_create_info{};
3395 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3396 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3397 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3398 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3399 &command_pool);
3400
3401 VkCommandBuffer command_buffer;
3402 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3403 command_buffer_allocate_info.sType =
3404 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3405 command_buffer_allocate_info.commandPool = command_pool;
3406 command_buffer_allocate_info.commandBufferCount = 1;
3407 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3408 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3409 &command_buffer);
3410
3411 VkQueue queue = VK_NULL_HANDLE;
3412 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
Tony Barbourfe302c02016-06-06 13:05:19 -06003413 0, &queue);
Michael Lentine860b0fe2016-05-20 10:14:00 -05003414
3415 {
3416 VkCommandBufferBeginInfo begin_info{};
3417 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3418 vkBeginCommandBuffer(command_buffer, &begin_info);
3419
3420 vkCmdResetEvent(command_buffer, event,
3421 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
3422 vkCmdWaitEvents(command_buffer, 1, &event,
3423 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3424 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
3425 nullptr, 0, nullptr);
3426 vkEndCommandBuffer(command_buffer);
3427 }
3428 {
3429 VkSubmitInfo submit_info{};
3430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3431 submit_info.commandBufferCount = 1;
3432 submit_info.pCommandBuffers = &command_buffer;
3433 submit_info.signalSemaphoreCount = 0;
3434 submit_info.pSignalSemaphores = nullptr;
3435 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3436 }
3437 {
3438 m_errorMonitor->SetDesiredFailureMsg(
3439 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event "
3440 "0x1 that is already in use by a "
3441 "command buffer.");
3442 vkSetEvent(m_device->device(), event);
3443 m_errorMonitor->VerifyFound();
3444 }
3445
3446 vkQueueWaitIdle(queue);
3447
3448 vkDestroyEvent(m_device->device(), event, nullptr);
3449 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
3450 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3451}
3452
3453// This is a positive test. No errors should be generated.
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003454TEST_F(VkLayerTest, TwoFencesThreeFrames) {
3455 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
3456 "run through a Submit & WaitForFences cycle 3 times. This "
3457 "previously revealed a bug so running this positive test "
3458 "to prevent a regression.");
3459 m_errorMonitor->ExpectSuccess();
3460
3461 ASSERT_NO_FATAL_FAILURE(InitState());
3462 VkQueue queue = VK_NULL_HANDLE;
3463 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3464 0, &queue);
3465
3466 static const uint32_t NUM_OBJECTS = 2;
3467 static const uint32_t NUM_FRAMES = 3;
3468 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
3469 VkFence fences[NUM_OBJECTS] = {};
3470
3471 VkCommandPool cmd_pool;
3472 VkCommandPoolCreateInfo cmd_pool_ci = {};
3473 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3474 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
3475 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3476 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci,
3477 nullptr, &cmd_pool);
3478 ASSERT_VK_SUCCESS(err);
3479
3480 VkCommandBufferAllocateInfo cmd_buf_info = {};
3481 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3482 cmd_buf_info.commandPool = cmd_pool;
3483 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3484 cmd_buf_info.commandBufferCount = 1;
3485
3486 VkFenceCreateInfo fence_ci = {};
3487 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3488 fence_ci.pNext = nullptr;
3489 fence_ci.flags = 0;
3490
3491 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3492 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info,
3493 &cmd_buffers[i]);
3494 ASSERT_VK_SUCCESS(err);
3495 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
3496 ASSERT_VK_SUCCESS(err);
3497 }
3498
3499 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
Tobin Ehlisf9025162016-05-26 06:55:21 -06003500 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
3501 // Create empty cmd buffer
3502 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3503 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003504
Tobin Ehlisf9025162016-05-26 06:55:21 -06003505 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
3506 ASSERT_VK_SUCCESS(err);
3507 err = vkEndCommandBuffer(cmd_buffers[obj]);
3508 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003509
Tobin Ehlisf9025162016-05-26 06:55:21 -06003510 VkSubmitInfo submit_info = {};
3511 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3512 submit_info.commandBufferCount = 1;
3513 submit_info.pCommandBuffers = &cmd_buffers[obj];
3514 // Submit cmd buffer and wait for fence
3515 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
3516 ASSERT_VK_SUCCESS(err);
3517 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE,
3518 UINT64_MAX);
3519 ASSERT_VK_SUCCESS(err);
3520 err = vkResetFences(m_device->device(), 1, &fences[obj]);
3521 ASSERT_VK_SUCCESS(err);
3522 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003523 }
3524 m_errorMonitor->VerifyNotFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06003525 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
3526 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
3527 vkDestroyFence(m_device->device(), fences[i], nullptr);
3528 }
Tobin Ehlis0bb263b2016-05-10 12:13:02 -06003529}
3530// This is a positive test. No errors should be generated.
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003531TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
3532
3533 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3534 "submitted on separate queues followed by a QueueWaitIdle.");
3535
Dustin Graves48458142016-04-29 16:11:55 -06003536 if ((m_device->queue_props.empty()) ||
3537 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003538 return;
3539
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003540 m_errorMonitor->ExpectSuccess();
3541
3542 VkSemaphore semaphore;
3543 VkSemaphoreCreateInfo semaphore_create_info{};
3544 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3545 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3546 &semaphore);
3547
3548 VkCommandPool command_pool;
3549 VkCommandPoolCreateInfo pool_create_info{};
3550 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3551 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3552 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3553 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3554 &command_pool);
3555
3556 VkCommandBuffer command_buffer[2];
3557 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3558 command_buffer_allocate_info.sType =
3559 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3560 command_buffer_allocate_info.commandPool = command_pool;
3561 command_buffer_allocate_info.commandBufferCount = 2;
3562 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3563 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3564 command_buffer);
3565
3566 VkQueue queue = VK_NULL_HANDLE;
3567 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3568 1, &queue);
3569
3570 {
3571 VkCommandBufferBeginInfo begin_info{};
3572 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3573 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3574
3575 vkCmdPipelineBarrier(command_buffer[0],
3576 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3577 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3578 0, nullptr, 0, nullptr);
3579
3580 VkViewport viewport{};
3581 viewport.maxDepth = 1.0f;
3582 viewport.minDepth = 0.0f;
3583 viewport.width = 512;
3584 viewport.height = 512;
3585 viewport.x = 0;
3586 viewport.y = 0;
3587 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3588 vkEndCommandBuffer(command_buffer[0]);
3589 }
3590 {
3591 VkCommandBufferBeginInfo begin_info{};
3592 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3593 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3594
3595 VkViewport viewport{};
3596 viewport.maxDepth = 1.0f;
3597 viewport.minDepth = 0.0f;
3598 viewport.width = 512;
3599 viewport.height = 512;
3600 viewport.x = 0;
3601 viewport.y = 0;
3602 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3603 vkEndCommandBuffer(command_buffer[1]);
3604 }
3605 {
3606 VkSubmitInfo submit_info{};
3607 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3608 submit_info.commandBufferCount = 1;
3609 submit_info.pCommandBuffers = &command_buffer[0];
3610 submit_info.signalSemaphoreCount = 1;
3611 submit_info.pSignalSemaphores = &semaphore;
3612 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3613 }
3614 {
3615 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3616 VkSubmitInfo submit_info{};
3617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.commandBufferCount = 1;
3619 submit_info.pCommandBuffers = &command_buffer[1];
3620 submit_info.waitSemaphoreCount = 1;
3621 submit_info.pWaitSemaphores = &semaphore;
3622 submit_info.pWaitDstStageMask = flags;
3623 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3624 }
3625
3626 vkQueueWaitIdle(m_device->m_queue);
3627
3628 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3629 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3630 &command_buffer[0]);
3631 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3632
3633 m_errorMonitor->VerifyNotFound();
3634}
3635
3636// This is a positive test. No errors should be generated.
3637TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
3638
3639 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3640 "submitted on separate queues, the second having a fence"
3641 "followed by a QueueWaitIdle.");
3642
Dustin Graves48458142016-04-29 16:11:55 -06003643 if ((m_device->queue_props.empty()) ||
3644 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003645 return;
3646
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003647 m_errorMonitor->ExpectSuccess();
3648
3649 VkFence fence;
3650 VkFenceCreateInfo fence_create_info{};
3651 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3652 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3653
3654 VkSemaphore semaphore;
3655 VkSemaphoreCreateInfo semaphore_create_info{};
3656 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3657 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3658 &semaphore);
3659
3660 VkCommandPool command_pool;
3661 VkCommandPoolCreateInfo pool_create_info{};
3662 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3663 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3664 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3665 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3666 &command_pool);
3667
3668 VkCommandBuffer command_buffer[2];
3669 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3670 command_buffer_allocate_info.sType =
3671 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3672 command_buffer_allocate_info.commandPool = command_pool;
3673 command_buffer_allocate_info.commandBufferCount = 2;
3674 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3675 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3676 command_buffer);
3677
3678 VkQueue queue = VK_NULL_HANDLE;
3679 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3680 1, &queue);
3681
3682 {
3683 VkCommandBufferBeginInfo begin_info{};
3684 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3685 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3686
3687 vkCmdPipelineBarrier(command_buffer[0],
3688 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3689 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3690 0, nullptr, 0, nullptr);
3691
3692 VkViewport viewport{};
3693 viewport.maxDepth = 1.0f;
3694 viewport.minDepth = 0.0f;
3695 viewport.width = 512;
3696 viewport.height = 512;
3697 viewport.x = 0;
3698 viewport.y = 0;
3699 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3700 vkEndCommandBuffer(command_buffer[0]);
3701 }
3702 {
3703 VkCommandBufferBeginInfo begin_info{};
3704 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3705 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3706
3707 VkViewport viewport{};
3708 viewport.maxDepth = 1.0f;
3709 viewport.minDepth = 0.0f;
3710 viewport.width = 512;
3711 viewport.height = 512;
3712 viewport.x = 0;
3713 viewport.y = 0;
3714 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3715 vkEndCommandBuffer(command_buffer[1]);
3716 }
3717 {
3718 VkSubmitInfo submit_info{};
3719 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3720 submit_info.commandBufferCount = 1;
3721 submit_info.pCommandBuffers = &command_buffer[0];
3722 submit_info.signalSemaphoreCount = 1;
3723 submit_info.pSignalSemaphores = &semaphore;
3724 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3725 }
3726 {
3727 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3728 VkSubmitInfo submit_info{};
3729 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3730 submit_info.commandBufferCount = 1;
3731 submit_info.pCommandBuffers = &command_buffer[1];
3732 submit_info.waitSemaphoreCount = 1;
3733 submit_info.pWaitSemaphores = &semaphore;
3734 submit_info.pWaitDstStageMask = flags;
3735 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3736 }
3737
3738 vkQueueWaitIdle(m_device->m_queue);
3739
3740 vkDestroyFence(m_device->device(), fence, nullptr);
3741 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3742 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3743 &command_buffer[0]);
3744 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3745
3746 m_errorMonitor->VerifyNotFound();
3747}
3748
3749// This is a positive test. No errors should be generated.
3750TEST_F(VkLayerTest,
3751 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
3752
3753 TEST_DESCRIPTION(
3754 "Two command buffers, each in a separate QueueSubmit call "
3755 "submitted on separate queues, the second having a fence"
3756 "followed by two consecutive WaitForFences calls on the same fence.");
3757
Dustin Graves48458142016-04-29 16:11:55 -06003758 if ((m_device->queue_props.empty()) ||
3759 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003760 return;
3761
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003762 m_errorMonitor->ExpectSuccess();
3763
3764 VkFence fence;
3765 VkFenceCreateInfo fence_create_info{};
3766 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3767 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3768
3769 VkSemaphore semaphore;
3770 VkSemaphoreCreateInfo semaphore_create_info{};
3771 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3772 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3773 &semaphore);
3774
3775 VkCommandPool command_pool;
3776 VkCommandPoolCreateInfo pool_create_info{};
3777 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3778 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3779 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3780 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3781 &command_pool);
3782
3783 VkCommandBuffer command_buffer[2];
3784 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3785 command_buffer_allocate_info.sType =
3786 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3787 command_buffer_allocate_info.commandPool = command_pool;
3788 command_buffer_allocate_info.commandBufferCount = 2;
3789 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3790 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3791 command_buffer);
3792
3793 VkQueue queue = VK_NULL_HANDLE;
3794 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3795 1, &queue);
3796
3797 {
3798 VkCommandBufferBeginInfo begin_info{};
3799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3800 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3801
3802 vkCmdPipelineBarrier(command_buffer[0],
3803 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3804 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3805 0, nullptr, 0, nullptr);
3806
3807 VkViewport viewport{};
3808 viewport.maxDepth = 1.0f;
3809 viewport.minDepth = 0.0f;
3810 viewport.width = 512;
3811 viewport.height = 512;
3812 viewport.x = 0;
3813 viewport.y = 0;
3814 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3815 vkEndCommandBuffer(command_buffer[0]);
3816 }
3817 {
3818 VkCommandBufferBeginInfo begin_info{};
3819 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3820 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3821
3822 VkViewport viewport{};
3823 viewport.maxDepth = 1.0f;
3824 viewport.minDepth = 0.0f;
3825 viewport.width = 512;
3826 viewport.height = 512;
3827 viewport.x = 0;
3828 viewport.y = 0;
3829 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3830 vkEndCommandBuffer(command_buffer[1]);
3831 }
3832 {
3833 VkSubmitInfo submit_info{};
3834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3835 submit_info.commandBufferCount = 1;
3836 submit_info.pCommandBuffers = &command_buffer[0];
3837 submit_info.signalSemaphoreCount = 1;
3838 submit_info.pSignalSemaphores = &semaphore;
3839 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3840 }
3841 {
3842 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3843 VkSubmitInfo submit_info{};
3844 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3845 submit_info.commandBufferCount = 1;
3846 submit_info.pCommandBuffers = &command_buffer[1];
3847 submit_info.waitSemaphoreCount = 1;
3848 submit_info.pWaitSemaphores = &semaphore;
3849 submit_info.pWaitDstStageMask = flags;
3850 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3851 }
3852
3853 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3854 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3855
3856 vkDestroyFence(m_device->device(), fence, nullptr);
3857 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3858 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3859 &command_buffer[0]);
3860 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3861
3862 m_errorMonitor->VerifyNotFound();
3863}
3864
3865// This is a positive test. No errors should be generated.
3866TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
3867
3868 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3869 "submitted on separate queues, the second having a fence, "
3870 "followed by a WaitForFences call.");
3871
Dustin Graves48458142016-04-29 16:11:55 -06003872 if ((m_device->queue_props.empty()) ||
3873 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06003874 return;
3875
Mark Lobodzinskic808d442016-04-14 10:57:23 -06003876 m_errorMonitor->ExpectSuccess();
3877
3878 VkFence fence;
3879 VkFenceCreateInfo fence_create_info{};
3880 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3881 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3882
3883 VkSemaphore semaphore;
3884 VkSemaphoreCreateInfo semaphore_create_info{};
3885 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3886 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3887 &semaphore);
3888
3889 VkCommandPool command_pool;
3890 VkCommandPoolCreateInfo pool_create_info{};
3891 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
3892 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
3893 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
3894 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
3895 &command_pool);
3896
3897 VkCommandBuffer command_buffer[2];
3898 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
3899 command_buffer_allocate_info.sType =
3900 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
3901 command_buffer_allocate_info.commandPool = command_pool;
3902 command_buffer_allocate_info.commandBufferCount = 2;
3903 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
3904 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
3905 command_buffer);
3906
3907 VkQueue queue = VK_NULL_HANDLE;
3908 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
3909 1, &queue);
3910
3911
3912 {
3913 VkCommandBufferBeginInfo begin_info{};
3914 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3915 vkBeginCommandBuffer(command_buffer[0], &begin_info);
3916
3917 vkCmdPipelineBarrier(command_buffer[0],
3918 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
3919 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
3920 0, nullptr, 0, nullptr);
3921
3922 VkViewport viewport{};
3923 viewport.maxDepth = 1.0f;
3924 viewport.minDepth = 0.0f;
3925 viewport.width = 512;
3926 viewport.height = 512;
3927 viewport.x = 0;
3928 viewport.y = 0;
3929 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
3930 vkEndCommandBuffer(command_buffer[0]);
3931 }
3932 {
3933 VkCommandBufferBeginInfo begin_info{};
3934 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3935 vkBeginCommandBuffer(command_buffer[1], &begin_info);
3936
3937 VkViewport viewport{};
3938 viewport.maxDepth = 1.0f;
3939 viewport.minDepth = 0.0f;
3940 viewport.width = 512;
3941 viewport.height = 512;
3942 viewport.x = 0;
3943 viewport.y = 0;
3944 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
3945 vkEndCommandBuffer(command_buffer[1]);
3946 }
3947 {
3948 VkSubmitInfo submit_info{};
3949 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3950 submit_info.commandBufferCount = 1;
3951 submit_info.pCommandBuffers = &command_buffer[0];
3952 submit_info.signalSemaphoreCount = 1;
3953 submit_info.pSignalSemaphores = &semaphore;
3954 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
3955 }
3956 {
3957 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
3958 VkSubmitInfo submit_info{};
3959 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3960 submit_info.commandBufferCount = 1;
3961 submit_info.pCommandBuffers = &command_buffer[1];
3962 submit_info.waitSemaphoreCount = 1;
3963 submit_info.pWaitSemaphores = &semaphore;
3964 submit_info.pWaitDstStageMask = flags;
3965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
3966 }
3967
3968 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
3969
3970 vkDestroyFence(m_device->device(), fence, nullptr);
3971 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
3972 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
3973 &command_buffer[0]);
3974 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
3975
3976 m_errorMonitor->VerifyNotFound();
3977}
3978
3979// This is a positive test. No errors should be generated.
3980TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
3981
3982 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
3983 "on the same queue, sharing a signal/wait semaphore, the "
3984 "second having a fence, "
3985 "followed by a WaitForFences call.");
3986
3987 m_errorMonitor->ExpectSuccess();
3988
3989 VkFence fence;
3990 VkFenceCreateInfo fence_create_info{};
3991 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
3992 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
3993
3994 VkSemaphore semaphore;
3995 VkSemaphoreCreateInfo semaphore_create_info{};
3996 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
3997 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
3998 &semaphore);
3999
4000 VkCommandPool command_pool;
4001 VkCommandPoolCreateInfo pool_create_info{};
4002 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4003 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4004 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4005 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4006 &command_pool);
4007
4008 VkCommandBuffer command_buffer[2];
4009 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4010 command_buffer_allocate_info.sType =
4011 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4012 command_buffer_allocate_info.commandPool = command_pool;
4013 command_buffer_allocate_info.commandBufferCount = 2;
4014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4015 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4016 command_buffer);
4017
4018 {
4019 VkCommandBufferBeginInfo begin_info{};
4020 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4021 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4022
4023 vkCmdPipelineBarrier(command_buffer[0],
4024 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4025 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4026 0, nullptr, 0, nullptr);
4027
4028 VkViewport viewport{};
4029 viewport.maxDepth = 1.0f;
4030 viewport.minDepth = 0.0f;
4031 viewport.width = 512;
4032 viewport.height = 512;
4033 viewport.x = 0;
4034 viewport.y = 0;
4035 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4036 vkEndCommandBuffer(command_buffer[0]);
4037 }
4038 {
4039 VkCommandBufferBeginInfo begin_info{};
4040 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4041 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4042
4043 VkViewport viewport{};
4044 viewport.maxDepth = 1.0f;
4045 viewport.minDepth = 0.0f;
4046 viewport.width = 512;
4047 viewport.height = 512;
4048 viewport.x = 0;
4049 viewport.y = 0;
4050 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4051 vkEndCommandBuffer(command_buffer[1]);
4052 }
4053 {
4054 VkSubmitInfo submit_info{};
4055 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4056 submit_info.commandBufferCount = 1;
4057 submit_info.pCommandBuffers = &command_buffer[0];
4058 submit_info.signalSemaphoreCount = 1;
4059 submit_info.pSignalSemaphores = &semaphore;
4060 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4061 }
4062 {
4063 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4064 VkSubmitInfo submit_info{};
4065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4066 submit_info.commandBufferCount = 1;
4067 submit_info.pCommandBuffers = &command_buffer[1];
4068 submit_info.waitSemaphoreCount = 1;
4069 submit_info.pWaitSemaphores = &semaphore;
4070 submit_info.pWaitDstStageMask = flags;
4071 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4072 }
4073
4074 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4075
4076 vkDestroyFence(m_device->device(), fence, nullptr);
4077 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
4078 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4079 &command_buffer[0]);
4080 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4081
4082 m_errorMonitor->VerifyNotFound();
4083}
4084
4085// This is a positive test. No errors should be generated.
4086TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
4087
4088 TEST_DESCRIPTION(
4089 "Two command buffers, each in a separate QueueSubmit call "
4090 "on the same queue, no fences, followed by a third QueueSubmit with NO "
4091 "SubmitInfos but with a fence, followed by a WaitForFences call.");
4092
4093 m_errorMonitor->ExpectSuccess();
4094
4095 VkFence fence;
4096 VkFenceCreateInfo fence_create_info{};
4097 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4098 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4099
4100 VkCommandPool command_pool;
4101 VkCommandPoolCreateInfo pool_create_info{};
4102 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4103 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4104 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4105 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4106 &command_pool);
4107
4108 VkCommandBuffer command_buffer[2];
4109 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4110 command_buffer_allocate_info.sType =
4111 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4112 command_buffer_allocate_info.commandPool = command_pool;
4113 command_buffer_allocate_info.commandBufferCount = 2;
4114 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4115 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4116 command_buffer);
4117
4118 {
4119 VkCommandBufferBeginInfo begin_info{};
4120 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4121 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4122
4123 vkCmdPipelineBarrier(command_buffer[0],
4124 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4125 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4126 0, nullptr, 0, nullptr);
4127
4128 VkViewport viewport{};
4129 viewport.maxDepth = 1.0f;
4130 viewport.minDepth = 0.0f;
4131 viewport.width = 512;
4132 viewport.height = 512;
4133 viewport.x = 0;
4134 viewport.y = 0;
4135 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4136 vkEndCommandBuffer(command_buffer[0]);
4137 }
4138 {
4139 VkCommandBufferBeginInfo begin_info{};
4140 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4141 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4142
4143 VkViewport viewport{};
4144 viewport.maxDepth = 1.0f;
4145 viewport.minDepth = 0.0f;
4146 viewport.width = 512;
4147 viewport.height = 512;
4148 viewport.x = 0;
4149 viewport.y = 0;
4150 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4151 vkEndCommandBuffer(command_buffer[1]);
4152 }
4153 {
4154 VkSubmitInfo submit_info{};
4155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4156 submit_info.commandBufferCount = 1;
4157 submit_info.pCommandBuffers = &command_buffer[0];
4158 submit_info.signalSemaphoreCount = 0;
4159 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4161 }
4162 {
4163 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4164 VkSubmitInfo submit_info{};
4165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4166 submit_info.commandBufferCount = 1;
4167 submit_info.pCommandBuffers = &command_buffer[1];
4168 submit_info.waitSemaphoreCount = 0;
4169 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4170 submit_info.pWaitDstStageMask = flags;
4171 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4172 }
4173
4174 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
4175
4176 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4177
4178 vkDestroyFence(m_device->device(), fence, nullptr);
4179 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4180 &command_buffer[0]);
4181 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4182
4183 m_errorMonitor->VerifyNotFound();
4184}
4185
4186// This is a positive test. No errors should be generated.
4187TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
4188
4189 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
4190 "on the same queue, the second having a fence, followed "
4191 "by a WaitForFences call.");
4192
4193 m_errorMonitor->ExpectSuccess();
4194
4195 VkFence fence;
4196 VkFenceCreateInfo fence_create_info{};
4197 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4198 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4199
4200 VkCommandPool command_pool;
4201 VkCommandPoolCreateInfo pool_create_info{};
4202 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4203 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4204 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4205 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4206 &command_pool);
4207
4208 VkCommandBuffer command_buffer[2];
4209 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4210 command_buffer_allocate_info.sType =
4211 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4212 command_buffer_allocate_info.commandPool = command_pool;
4213 command_buffer_allocate_info.commandBufferCount = 2;
4214 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4215 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4216 command_buffer);
4217
4218 {
4219 VkCommandBufferBeginInfo begin_info{};
4220 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4221 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4222
4223 vkCmdPipelineBarrier(command_buffer[0],
4224 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4225 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4226 0, nullptr, 0, nullptr);
4227
4228 VkViewport viewport{};
4229 viewport.maxDepth = 1.0f;
4230 viewport.minDepth = 0.0f;
4231 viewport.width = 512;
4232 viewport.height = 512;
4233 viewport.x = 0;
4234 viewport.y = 0;
4235 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4236 vkEndCommandBuffer(command_buffer[0]);
4237 }
4238 {
4239 VkCommandBufferBeginInfo begin_info{};
4240 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4241 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4242
4243 VkViewport viewport{};
4244 viewport.maxDepth = 1.0f;
4245 viewport.minDepth = 0.0f;
4246 viewport.width = 512;
4247 viewport.height = 512;
4248 viewport.x = 0;
4249 viewport.y = 0;
4250 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4251 vkEndCommandBuffer(command_buffer[1]);
4252 }
4253 {
4254 VkSubmitInfo submit_info{};
4255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4256 submit_info.commandBufferCount = 1;
4257 submit_info.pCommandBuffers = &command_buffer[0];
4258 submit_info.signalSemaphoreCount = 0;
4259 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
4260 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4261 }
4262 {
4263 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4264 VkSubmitInfo submit_info{};
4265 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4266 submit_info.commandBufferCount = 1;
4267 submit_info.pCommandBuffers = &command_buffer[1];
4268 submit_info.waitSemaphoreCount = 0;
4269 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
4270 submit_info.pWaitDstStageMask = flags;
4271 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
4272 }
4273
4274 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4275
4276 vkDestroyFence(m_device->device(), fence, nullptr);
4277 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4278 &command_buffer[0]);
4279 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
4280
4281 m_errorMonitor->VerifyNotFound();
4282}
4283
4284// This is a positive test. No errors should be generated.
4285TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
4286
4287 TEST_DESCRIPTION(
4288 "Two command buffers each in a separate SubmitInfo sent in a single "
4289 "QueueSubmit call followed by a WaitForFences call.");
4290
4291 m_errorMonitor->ExpectSuccess();
4292
4293 VkFence fence;
4294 VkFenceCreateInfo fence_create_info{};
4295 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
4296 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
4297
4298 VkSemaphore semaphore;
4299 VkSemaphoreCreateInfo semaphore_create_info{};
4300 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
4301 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
4302 &semaphore);
4303
4304 VkCommandPool command_pool;
4305 VkCommandPoolCreateInfo pool_create_info{};
4306 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
4307 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
4308 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
4309 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
4310 &command_pool);
4311
4312 VkCommandBuffer command_buffer[2];
4313 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
4314 command_buffer_allocate_info.sType =
4315 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
4316 command_buffer_allocate_info.commandPool = command_pool;
4317 command_buffer_allocate_info.commandBufferCount = 2;
4318 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
4319 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
4320 command_buffer);
4321
4322 {
4323 VkCommandBufferBeginInfo begin_info{};
4324 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4325 vkBeginCommandBuffer(command_buffer[0], &begin_info);
4326
4327 vkCmdPipelineBarrier(command_buffer[0],
4328 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4329 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
4330 0, nullptr, 0, nullptr);
4331
4332 VkViewport viewport{};
4333 viewport.maxDepth = 1.0f;
4334 viewport.minDepth = 0.0f;
4335 viewport.width = 512;
4336 viewport.height = 512;
4337 viewport.x = 0;
4338 viewport.y = 0;
4339 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
4340 vkEndCommandBuffer(command_buffer[0]);
4341 }
4342 {
4343 VkCommandBufferBeginInfo begin_info{};
4344 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4345 vkBeginCommandBuffer(command_buffer[1], &begin_info);
4346
4347 VkViewport viewport{};
4348 viewport.maxDepth = 1.0f;
4349 viewport.minDepth = 0.0f;
4350 viewport.width = 512;
4351 viewport.height = 512;
4352 viewport.x = 0;
4353 viewport.y = 0;
4354 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
4355 vkEndCommandBuffer(command_buffer[1]);
4356 }
4357 {
4358 VkSubmitInfo submit_info[2];
4359 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
4360
4361 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4362 submit_info[0].pNext = NULL;
4363 submit_info[0].commandBufferCount = 1;
4364 submit_info[0].pCommandBuffers = &command_buffer[0];
4365 submit_info[0].signalSemaphoreCount = 1;
4366 submit_info[0].pSignalSemaphores = &semaphore;
4367 submit_info[0].waitSemaphoreCount = 0;
4368 submit_info[0].pWaitSemaphores = NULL;
4369 submit_info[0].pWaitDstStageMask = 0;
4370
4371 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4372 submit_info[1].pNext = NULL;
4373 submit_info[1].commandBufferCount = 1;
4374 submit_info[1].pCommandBuffers = &command_buffer[1];
4375 submit_info[1].waitSemaphoreCount = 1;
4376 submit_info[1].pWaitSemaphores = &semaphore;
4377 submit_info[1].pWaitDstStageMask = flags;
4378 submit_info[1].signalSemaphoreCount = 0;
4379 submit_info[1].pSignalSemaphores = NULL;
4380 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
4381 }
4382
4383 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
4384
4385 vkDestroyFence(m_device->device(), fence, nullptr);
4386 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
4387 &command_buffer[0]);
4388 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06004389 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Mark Lobodzinskic808d442016-04-14 10:57:23 -06004390
4391 m_errorMonitor->VerifyNotFound();
4392}
4393
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004394TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004395 TEST_DESCRIPTION(
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004396 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4397 "state is required but not correctly bound.");
4398
4399 // Dynamic depth bias
4400 m_errorMonitor->SetDesiredFailureMsg(
4401 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4402 "Dynamic depth bias state not set for this command buffer");
4403 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4404 BsoFailDepthBias);
4405 m_errorMonitor->VerifyFound();
4406}
4407
4408TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
4409 TEST_DESCRIPTION(
4410 "Run a simple draw calls to validate failure when Line Width dynamic "
4411 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004412
4413 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07004414 m_errorMonitor->SetDesiredFailureMsg(
4415 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004416 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004417 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4418 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004419 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004420}
4421
4422TEST_F(VkLayerTest, DynamicViewportNotBound) {
4423 TEST_DESCRIPTION(
4424 "Run a simple draw calls to validate failure when Viewport dynamic "
4425 "state is required but not correctly bound.");
4426
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004427 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07004428 m_errorMonitor->SetDesiredFailureMsg(
4429 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004430 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004431 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4432 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004433 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004434}
4435
4436TEST_F(VkLayerTest, DynamicScissorNotBound) {
4437 TEST_DESCRIPTION(
4438 "Run a simple draw calls to validate failure when Scissor dynamic "
4439 "state is required but not correctly bound.");
4440
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004441 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07004442 m_errorMonitor->SetDesiredFailureMsg(
4443 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004444 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004445 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4446 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004447 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004448}
4449
Tobin Ehlis21c88352016-05-26 06:15:45 -06004450TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) {
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004451 TEST_DESCRIPTION(
Tobin Ehlis21c88352016-05-26 06:15:45 -06004452 "Run a simple draw calls to validate failure when Blend Constants "
4453 "dynamic state is required but not correctly bound.");
4454 // Dynamic blend constant state
4455 m_errorMonitor->SetDesiredFailureMsg(
4456 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4457 "Dynamic blend constants state not set for this command buffer");
4458 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4459 BsoFailBlend);
4460 m_errorMonitor->VerifyFound();
4461}
4462
4463TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
4464 TEST_DESCRIPTION(
4465 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004466 "state is required but not correctly bound.");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004467 if (!m_device->phy().features().depthBounds) {
4468 printf("Device does not support depthBounds test; skipped.\n");
4469 return;
4470 }
4471 // Dynamic depth bounds
Karl Schultz6addd812016-02-02 17:17:23 -07004472 m_errorMonitor->SetDesiredFailureMsg(
4473 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004474 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004475 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4476 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004477 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004478}
4479
4480TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
4481 TEST_DESCRIPTION(
4482 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4483 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004484 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07004485 m_errorMonitor->SetDesiredFailureMsg(
4486 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004487 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4489 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004490 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004491}
4492
4493TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
4494 TEST_DESCRIPTION(
4495 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4496 " state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004497 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07004498 m_errorMonitor->SetDesiredFailureMsg(
4499 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004500 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004501 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4502 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004503 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004504}
4505
4506TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
4507 TEST_DESCRIPTION(
4508 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4509 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004510 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07004511 m_errorMonitor->SetDesiredFailureMsg(
4512 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004513 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07004514 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
4515 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004516 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004517}
4518
Karl Schultz6addd812016-02-02 17:17:23 -07004519TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Karl Schultz6addd812016-02-02 17:17:23 -07004520 m_errorMonitor->SetDesiredFailureMsg(
4521 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4522 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4523 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004524
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004525 ASSERT_NO_FATAL_FAILURE(InitState());
4526 ASSERT_NO_FATAL_FAILURE(InitViewport());
4527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4528
Karl Schultz6addd812016-02-02 17:17:23 -07004529 // We luck out b/c by default the framework creates CB w/ the
4530 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004531 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004532 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
4533 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004534 EndCommandBuffer();
4535
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004536 // Bypass framework since it does the waits automatically
4537 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004538 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004539 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4540 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004541 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004542 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004543 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004544 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004545 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004546 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004547 submit_info.pSignalSemaphores = NULL;
4548
Chris Forbes40028e22016-06-13 09:59:34 +12004549 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004550 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004551
Karl Schultz6addd812016-02-02 17:17:23 -07004552 // Cause validation error by re-submitting cmd buffer that should only be
4553 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004554 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004555
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004556 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004557}
4558
Karl Schultz6addd812016-02-02 17:17:23 -07004559TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004560 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07004561 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004562
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004564 "Unable to allocate 1 descriptors of "
4565 "type "
4566 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004567
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004568 ASSERT_NO_FATAL_FAILURE(InitState());
4569 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004570
Karl Schultz6addd812016-02-02 17:17:23 -07004571 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4572 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004573 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004574 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
4575 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004576
4577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4579 ds_pool_ci.pNext = NULL;
4580 ds_pool_ci.flags = 0;
4581 ds_pool_ci.maxSets = 1;
4582 ds_pool_ci.poolSizeCount = 1;
4583 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004584
4585 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004586 err =
4587 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004588 ASSERT_VK_SUCCESS(err);
4589
4590 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004591 dsl_binding.binding = 0;
4592 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4593 dsl_binding.descriptorCount = 1;
4594 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4595 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004596
4597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4599 ds_layout_ci.pNext = NULL;
4600 ds_layout_ci.bindingCount = 1;
4601 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004602
4603 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004604 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4605 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004606 ASSERT_VK_SUCCESS(err);
4607
4608 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004609 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004610 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004611 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004612 alloc_info.descriptorPool = ds_pool;
4613 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004614 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4615 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004616
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004617 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004618
Chia-I Wuf7458c52015-10-26 21:10:41 +08004619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4620 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004621}
4622
Karl Schultz6addd812016-02-02 17:17:23 -07004623TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4624 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004625
Karl Schultz6addd812016-02-02 17:17:23 -07004626 m_errorMonitor->SetDesiredFailureMsg(
4627 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4628 "It is invalid to call vkFreeDescriptorSets() with a pool created "
4629 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004630
Tobin Ehlise735c692015-10-08 13:13:50 -06004631 ASSERT_NO_FATAL_FAILURE(InitState());
4632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004633
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004634 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004635 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4636 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004637
4638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4640 ds_pool_ci.pNext = NULL;
4641 ds_pool_ci.maxSets = 1;
4642 ds_pool_ci.poolSizeCount = 1;
4643 ds_pool_ci.flags = 0;
4644 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4645 // app can only call vkResetDescriptorPool on this pool.;
4646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004647
4648 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004649 err =
4650 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004651 ASSERT_VK_SUCCESS(err);
4652
4653 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004654 dsl_binding.binding = 0;
4655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4656 dsl_binding.descriptorCount = 1;
4657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004659
4660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4662 ds_layout_ci.pNext = NULL;
4663 ds_layout_ci.bindingCount = 1;
4664 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004665
4666 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4668 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004669 ASSERT_VK_SUCCESS(err);
4670
4671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004675 alloc_info.descriptorPool = ds_pool;
4676 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4678 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004679 ASSERT_VK_SUCCESS(err);
4680
4681 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004682 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004683
Chia-I Wuf7458c52015-10-26 21:10:41 +08004684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004686}
4687
Karl Schultz6addd812016-02-02 17:17:23 -07004688TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004689 // Attempt to clear Descriptor Pool with bad object.
4690 // ObjectTracker should catch this.
4691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4692 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004693 uint64_t fake_pool_handle = 0xbaad6001;
4694 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4695 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004696 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004697}
4698
Karl Schultz6addd812016-02-02 17:17:23 -07004699TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004700 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4701 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004702 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004703 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004704
4705 uint64_t fake_set_handle = 0xbaad6001;
4706 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004707 VkResult err;
4708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4709 "Invalid VkDescriptorSet Object 0xbaad6001");
4710
4711 ASSERT_NO_FATAL_FAILURE(InitState());
4712
4713 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4714 layout_bindings[0].binding = 0;
4715 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4716 layout_bindings[0].descriptorCount = 1;
4717 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4718 layout_bindings[0].pImmutableSamplers = NULL;
4719
4720 VkDescriptorSetLayout descriptor_set_layout;
4721 VkDescriptorSetLayoutCreateInfo dslci = {};
4722 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4723 dslci.pNext = NULL;
4724 dslci.bindingCount = 1;
4725 dslci.pBindings = layout_bindings;
4726 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004727 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004728
4729 VkPipelineLayout pipeline_layout;
4730 VkPipelineLayoutCreateInfo plci = {};
4731 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4732 plci.pNext = NULL;
4733 plci.setLayoutCount = 1;
4734 plci.pSetLayouts = &descriptor_set_layout;
4735 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004736 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004737
4738 BeginCommandBuffer();
4739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004740 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004741 m_errorMonitor->VerifyFound();
4742 EndCommandBuffer();
4743 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4744 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004745}
4746
Karl Schultz6addd812016-02-02 17:17:23 -07004747TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004748 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4749 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004750 uint64_t fake_layout_handle = 0xbaad6001;
4751 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4753 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
4754
4755 VkPipelineLayout pipeline_layout;
4756 VkPipelineLayoutCreateInfo plci = {};
4757 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4758 plci.pNext = NULL;
4759 plci.setLayoutCount = 1;
4760 plci.pSetLayouts = &bad_layout;
4761 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4762
4763 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004764}
4765
Mark Muellerd4914412016-06-13 17:52:06 -06004766TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
4767 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4768 "1) A uniform buffer update must have a valid buffer index."
4769 "2) When using an array of descriptors in a single WriteDescriptor,"
4770 " the descriptor types and stageflags must all be the same."
4771 "3) Immutable Sampler state must match across descriptors");
4772
4773 const char *invalid_BufferInfo_ErrorMessage =
4774 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
4775 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
4776 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
4777 const char *stateFlag_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004778 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004779 const char *immutable_ErrorMessage =
Mark Mueller5c838ce2016-06-16 09:54:29 -06004780 "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06004781
Mark Muellerd4914412016-06-13 17:52:06 -06004782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
4783
4784 ASSERT_NO_FATAL_FAILURE(InitState());
4785 VkDescriptorPoolSize ds_type_count[4] = {};
4786 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4787 ds_type_count[0].descriptorCount = 1;
4788 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4789 ds_type_count[1].descriptorCount = 1;
4790 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4791 ds_type_count[2].descriptorCount = 1;
4792 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4793 ds_type_count[3].descriptorCount = 1;
4794
4795 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4796 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4797 ds_pool_ci.maxSets = 1;
4798 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4799 ds_pool_ci.pPoolSizes = ds_type_count;
4800
4801 VkDescriptorPool ds_pool;
4802 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4803 ASSERT_VK_SUCCESS(err);
4804
Mark Muellerb9896722016-06-16 09:54:29 -06004805 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004806 layout_binding[0].binding = 0;
4807 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4808 layout_binding[0].descriptorCount = 1;
4809 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4810 layout_binding[0].pImmutableSamplers = NULL;
4811
4812 layout_binding[1].binding = 1;
4813 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4814 layout_binding[1].descriptorCount = 1;
4815 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4816 layout_binding[1].pImmutableSamplers = NULL;
4817
4818 VkSamplerCreateInfo sampler_ci = {};
4819 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4820 sampler_ci.pNext = NULL;
4821 sampler_ci.magFilter = VK_FILTER_NEAREST;
4822 sampler_ci.minFilter = VK_FILTER_NEAREST;
4823 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4824 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4825 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4826 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4827 sampler_ci.mipLodBias = 1.0;
4828 sampler_ci.anisotropyEnable = VK_FALSE;
4829 sampler_ci.maxAnisotropy = 1;
4830 sampler_ci.compareEnable = VK_FALSE;
4831 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4832 sampler_ci.minLod = 1.0;
4833 sampler_ci.maxLod = 1.0;
4834 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4835 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4836 VkSampler sampler;
4837
4838 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4839 ASSERT_VK_SUCCESS(err);
4840
4841 layout_binding[2].binding = 2;
4842 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4843 layout_binding[2].descriptorCount = 1;
4844 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4845 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4846
Mark Muellerd4914412016-06-13 17:52:06 -06004847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4849 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4850 ds_layout_ci.pBindings = layout_binding;
4851 VkDescriptorSetLayout ds_layout;
4852 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4853 ASSERT_VK_SUCCESS(err);
4854
4855 VkDescriptorSetAllocateInfo alloc_info = {};
4856 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4857 alloc_info.descriptorSetCount = 1;
4858 alloc_info.descriptorPool = ds_pool;
4859 alloc_info.pSetLayouts = &ds_layout;
4860 VkDescriptorSet descriptorSet;
4861 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4862 ASSERT_VK_SUCCESS(err);
4863
4864 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4865 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4866 pipeline_layout_ci.pNext = NULL;
4867 pipeline_layout_ci.setLayoutCount = 1;
4868 pipeline_layout_ci.pSetLayouts = &ds_layout;
4869
4870 VkPipelineLayout pipeline_layout;
4871 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4872 ASSERT_VK_SUCCESS(err);
4873
Mark Mueller5c838ce2016-06-16 09:54:29 -06004874 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004875 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4876 descriptor_write.dstSet = descriptorSet;
4877 descriptor_write.dstBinding = 0;
4878 descriptor_write.descriptorCount = 1;
4879 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4880
Mark Mueller5c838ce2016-06-16 09:54:29 -06004881 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004882 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4883 m_errorMonitor->VerifyFound();
4884
4885 // Create a buffer to update the descriptor with
4886 uint32_t qfi = 0;
4887 VkBufferCreateInfo buffCI = {};
4888 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4889 buffCI.size = 1024;
4890 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4891 buffCI.queueFamilyIndexCount = 1;
4892 buffCI.pQueueFamilyIndices = &qfi;
4893
4894 VkBuffer dyub;
4895 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4896 ASSERT_VK_SUCCESS(err);
4897 VkDescriptorBufferInfo buffInfo = {};
4898 buffInfo.buffer = dyub;
4899 buffInfo.offset = 0;
4900 buffInfo.range = 1024;
4901
4902 descriptor_write.pBufferInfo = &buffInfo;
4903 descriptor_write.descriptorCount = 2;
4904
Mark Mueller5c838ce2016-06-16 09:54:29 -06004905 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06004906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
4907 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4908 m_errorMonitor->VerifyFound();
4909
Mark Mueller5c838ce2016-06-16 09:54:29 -06004910 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4911 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004912 descriptor_write.dstBinding = 1;
4913 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004914
4915
4916 // Make pImageInfo index non-null to avoid complaints of it missing
4917 VkDescriptorImageInfo imageInfo = {};
4918 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4919 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
4921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4922 m_errorMonitor->VerifyFound();
4923
Mark Muellerd4914412016-06-13 17:52:06 -06004924 vkDestroyBuffer(m_device->device(), dyub, NULL);
4925 vkDestroySampler(m_device->device(), sampler, NULL);
4926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4929}
4930
Karl Schultz6addd812016-02-02 17:17:23 -07004931TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004932 // Attempt to bind an invalid Pipeline to a valid Command Buffer
4933 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004934 // Create a valid cmd buffer
4935 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004936 uint64_t fake_pipeline_handle = 0xbaad6001;
4937 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4939 "Invalid VkPipeline Object 0xbaad6001");
4940 ASSERT_NO_FATAL_FAILURE(InitState());
4941 BeginCommandBuffer();
4942 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4943 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
4944 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004945 // Now issue a draw call with no pipeline bound
4946 m_errorMonitor->SetDesiredFailureMsg(
4947 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4948 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tony Barbourdf4c0042016-06-01 15:55:43 -06004949
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004950 BeginCommandBuffer();
4951 Draw(1, 0, 0, 0);
4952 m_errorMonitor->VerifyFound();
4953 // Finally same check once more but with Dispatch/Compute
4954 m_errorMonitor->SetDesiredFailureMsg(
4955 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4956 "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06004957 BeginCommandBuffer();
4958 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
4959 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004960}
4961
Karl Schultz6addd812016-02-02 17:17:23 -07004962TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
4963 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
4964 // CommandBuffer
4965 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004966
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07004967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004968 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004969
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004970 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06004971 ASSERT_NO_FATAL_FAILURE(InitViewport());
4972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004973 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4975 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004976
4977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4979 ds_pool_ci.pNext = NULL;
4980 ds_pool_ci.maxSets = 1;
4981 ds_pool_ci.poolSizeCount = 1;
4982 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06004983
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004984 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004985 err =
4986 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004987 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004988
Tony Barboureb254902015-07-15 12:50:33 -06004989 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004990 dsl_binding.binding = 0;
4991 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4992 dsl_binding.descriptorCount = 1;
4993 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4994 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004995
Tony Barboureb254902015-07-15 12:50:33 -06004996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4998 ds_layout_ci.pNext = NULL;
4999 ds_layout_ci.bindingCount = 1;
5000 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005001 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5003 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005004 ASSERT_VK_SUCCESS(err);
5005
5006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005010 alloc_info.descriptorPool = ds_pool;
5011 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5013 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005014 ASSERT_VK_SUCCESS(err);
5015
Tony Barboureb254902015-07-15 12:50:33 -06005016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5018 pipeline_layout_ci.pNext = NULL;
5019 pipeline_layout_ci.setLayoutCount = 1;
5020 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005021
5022 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5024 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005025 ASSERT_VK_SUCCESS(err);
5026
Karl Schultz6addd812016-02-02 17:17:23 -07005027 VkShaderObj vs(m_device, bindStateVertShaderText,
5028 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005029 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005030 // on more devices
5031 VkShaderObj fs(m_device, bindStateFragShaderText,
5032 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005033
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005034 VkPipelineObj pipe(m_device);
5035 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005036 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005037 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005039
5040 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005041 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5042 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5043 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5044 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5045 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005046
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005047 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005048
Chia-I Wuf7458c52015-10-26 21:10:41 +08005049 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5050 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5051 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005052}
5053
Karl Schultz6addd812016-02-02 17:17:23 -07005054TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005055 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005056 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005057
Karl Schultz6addd812016-02-02 17:17:23 -07005058 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005059 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5060 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005061
5062 ASSERT_NO_FATAL_FAILURE(InitState());
5063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5065 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005066
5067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5069 ds_pool_ci.pNext = NULL;
5070 ds_pool_ci.maxSets = 1;
5071 ds_pool_ci.poolSizeCount = 1;
5072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005073
5074 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005075 err =
5076 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005080 dsl_binding.binding = 0;
5081 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5082 dsl_binding.descriptorCount = 1;
5083 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5084 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005085
5086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005087 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5088 ds_layout_ci.pNext = NULL;
5089 ds_layout_ci.bindingCount = 1;
5090 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005091 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005092 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5093 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005094 ASSERT_VK_SUCCESS(err);
5095
5096 VkDescriptorSet descriptorSet;
5097 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005098 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005099 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005100 alloc_info.descriptorPool = ds_pool;
5101 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005102 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5103 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005104 ASSERT_VK_SUCCESS(err);
5105
Karl Schultz6addd812016-02-02 17:17:23 -07005106 VkBufferView view =
5107 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005108 VkWriteDescriptorSet descriptor_write;
5109 memset(&descriptor_write, 0, sizeof(descriptor_write));
5110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5111 descriptor_write.dstSet = descriptorSet;
5112 descriptor_write.dstBinding = 0;
5113 descriptor_write.descriptorCount = 1;
5114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5115 descriptor_write.pTexelBufferView = &view;
5116
5117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005119 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005120
5121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5123}
5124
Karl Schultz6addd812016-02-02 17:17:23 -07005125TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5126 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5127 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005128 // 1. No dynamicOffset supplied
5129 // 2. Too many dynamicOffsets supplied
5130 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005131 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005133 " requires 1 dynamicOffsets, but only "
5134 "0 dynamicOffsets are left in "
5135 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005136
5137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitViewport());
5139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5140
5141 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005142 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5143 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005144
5145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5147 ds_pool_ci.pNext = NULL;
5148 ds_pool_ci.maxSets = 1;
5149 ds_pool_ci.poolSizeCount = 1;
5150 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005151
5152 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005153 err =
5154 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005155 ASSERT_VK_SUCCESS(err);
5156
5157 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005158 dsl_binding.binding = 0;
5159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5160 dsl_binding.descriptorCount = 1;
5161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5162 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005163
5164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5166 ds_layout_ci.pNext = NULL;
5167 ds_layout_ci.bindingCount = 1;
5168 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005169 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5171 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005172 ASSERT_VK_SUCCESS(err);
5173
5174 VkDescriptorSet descriptorSet;
5175 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005176 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005177 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005178 alloc_info.descriptorPool = ds_pool;
5179 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005180 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5181 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005182 ASSERT_VK_SUCCESS(err);
5183
5184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5186 pipeline_layout_ci.pNext = NULL;
5187 pipeline_layout_ci.setLayoutCount = 1;
5188 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005189
5190 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5192 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005193 ASSERT_VK_SUCCESS(err);
5194
5195 // Create a buffer to update the descriptor with
5196 uint32_t qfi = 0;
5197 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005198 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5199 buffCI.size = 1024;
5200 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5201 buffCI.queueFamilyIndexCount = 1;
5202 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005203
5204 VkBuffer dyub;
5205 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5206 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005207 // Allocate memory and bind to buffer so we can make it to the appropriate
5208 // error
5209 VkMemoryAllocateInfo mem_alloc = {};
5210 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5211 mem_alloc.pNext = NULL;
5212 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005213 mem_alloc.memoryTypeIndex = 0;
5214
5215 VkMemoryRequirements memReqs;
5216 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
5217 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
5218 0);
5219 if (!pass) {
5220 vkDestroyBuffer(m_device->device(), dyub, NULL);
5221 return;
5222 }
5223
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005224 VkDeviceMemory mem;
5225 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5226 ASSERT_VK_SUCCESS(err);
5227 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5228 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005229 // Correctly update descriptor to avoid "NOT_UPDATED" error
5230 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005231 buffInfo.buffer = dyub;
5232 buffInfo.offset = 0;
5233 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005234
5235 VkWriteDescriptorSet descriptor_write;
5236 memset(&descriptor_write, 0, sizeof(descriptor_write));
5237 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5238 descriptor_write.dstSet = descriptorSet;
5239 descriptor_write.dstBinding = 0;
5240 descriptor_write.descriptorCount = 1;
5241 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5242 descriptor_write.pBufferInfo = &buffInfo;
5243
5244 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5245
5246 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5248 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5249 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005250 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005251 uint32_t pDynOff[2] = {512, 756};
5252 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07005253 m_errorMonitor->SetDesiredFailureMsg(
5254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07005255 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07005256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5257 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5258 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005259 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005260 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5262 " dynamic offset 512 combined with "
5263 "offset 0 and range 1024 that "
5264 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005265 // Create PSO to be used for draw-time errors below
5266 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005267 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005268 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005269 "out gl_PerVertex { \n"
5270 " vec4 gl_Position;\n"
5271 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005272 "void main(){\n"
5273 " gl_Position = vec4(1);\n"
5274 "}\n";
5275 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005276 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07005277 "\n"
5278 "layout(location=0) out vec4 x;\n"
5279 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5280 "void main(){\n"
5281 " x = vec4(bar.y);\n"
5282 "}\n";
5283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5285 VkPipelineObj pipe(m_device);
5286 pipe.AddShader(&vs);
5287 pipe.AddShader(&fs);
5288 pipe.AddColorAttachment();
5289 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5290
Karl Schultz6addd812016-02-02 17:17:23 -07005291 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5292 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5293 // This update should succeed, but offset size of 512 will overstep buffer
5294 // /w range 1024 & size 1024
5295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5296 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
5297 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005298 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005299 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005300
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005301 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005302 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005303
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005305 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005306 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5307}
5308
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005309TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005310 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005311 ASSERT_NO_FATAL_FAILURE(InitState());
5312 ASSERT_NO_FATAL_FAILURE(InitViewport());
5313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5314
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005315 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005316 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005317 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5318 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5319 pipeline_layout_ci.pushConstantRangeCount = 1;
5320 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5321
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005322 //
5323 // Check for invalid push constant ranges in pipeline layouts.
5324 //
5325 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005326 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005327 char const *msg;
5328 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005329
Karl Schultzc81037d2016-05-12 08:11:23 -06005330 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5331 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5332 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5333 "vkCreatePipelineLayout() call has push constants index 0 with "
5334 "size 0."},
5335 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5336 "vkCreatePipelineLayout() call has push constants index 0 with "
5337 "size 1."},
5338 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5339 "vkCreatePipelineLayout() call has push constants index 0 with "
5340 "size 1."},
5341 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5342 "vkCreatePipelineLayout() call has push constants index 0 with "
5343 "size 0."},
5344 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5345 "vkCreatePipelineLayout() call has push constants index 0 with "
5346 "offset 1. Offset must"},
5347 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5348 "vkCreatePipelineLayout() call has push constants index 0 "
5349 "with offset "},
5350 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5351 "vkCreatePipelineLayout() call has push constants "
5352 "index 0 with offset "},
5353 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
5354 "vkCreatePipelineLayout() call has push constants index 0 "
5355 "with offset "},
5356 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5357 "vkCreatePipelineLayout() call has push "
5358 "constants index 0 with offset "},
5359 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5360 "vkCreatePipelineLayout() call has push "
5361 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005362 }};
5363
5364 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06005365 for (const auto &iter : range_tests) {
5366 pc_range = iter.range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5368 iter.msg);
5369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5370 NULL, &pipeline_layout);
5371 m_errorMonitor->VerifyFound();
5372 if (VK_SUCCESS == err) {
5373 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5374 }
5375 }
5376
5377 // Check for invalid stage flag
5378 pc_range.offset = 0;
5379 pc_range.size = 16;
5380 pc_range.stageFlags = 0;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005381 m_errorMonitor->SetDesiredFailureMsg(
5382 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005383 "vkCreatePipelineLayout() call has no stageFlags set.");
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005384 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5385 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005386 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005387 if (VK_SUCCESS == err) {
5388 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5389 }
5390
5391 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06005392 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005393 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005394 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005395 char const *msg;
5396 };
5397
Karl Schultzc81037d2016-05-12 08:11:23 -06005398 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005399 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5400 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5401 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5402 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5403 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5404 "vkCreatePipelineLayout() call has push constants with overlapping "
5405 "ranges: 0:[0, 4), 1:[0, 4)"},
5406 {
5407 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5408 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5409 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5410 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5411 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5412 "vkCreatePipelineLayout() call has push constants with "
5413 "overlapping "
5414 "ranges: 3:[12, 20), 4:[16, 20)",
5415 },
5416 {
5417 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5418 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5419 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5420 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5421 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5422 "vkCreatePipelineLayout() call has push constants with "
5423 "overlapping "
5424 "ranges: 0:[16, 20), 1:[12, 20)",
5425 },
5426 {
5427 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5428 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5429 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5430 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
5431 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5432 "vkCreatePipelineLayout() call has push constants with "
5433 "overlapping "
5434 "ranges: 0:[16, 20), 3:[12, 20)",
5435 },
5436 {
5437 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5438 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
5439 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
5440 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
5441 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
5442 "vkCreatePipelineLayout() call has push constants with "
5443 "overlapping "
5444 "ranges: 0:[16, 20), 2:[4, 100)",
5445 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005446
Karl Schultzc81037d2016-05-12 08:11:23 -06005447 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005448 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06005449 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
5450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005451 iter.msg);
5452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5453 NULL, &pipeline_layout);
5454 m_errorMonitor->VerifyFound();
5455 if (VK_SUCCESS == err) {
5456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5457 }
5458 }
5459
5460 // Run some positive tests to make sure overlap checking in the layer is OK
Karl Schultzc81037d2016-05-12 08:11:23 -06005461 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos =
5462 {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5463 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
5464 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
5465 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
5466 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
5467 ""},
5468 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
5469 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
5470 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
5471 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
5472 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
5473 ""}}};
5474 for (const auto &iter : overlapping_range_tests_pos) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005475 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
5476 m_errorMonitor->ExpectSuccess();
5477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci,
5478 NULL, &pipeline_layout);
5479 m_errorMonitor->VerifyNotFound();
5480 if (VK_SUCCESS == err) {
5481 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5482 }
5483 }
5484
5485 //
5486 // CmdPushConstants tests
5487 //
Karl Schultzc81037d2016-05-12 08:11:23 -06005488 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005489
5490 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzc81037d2016-05-12 08:11:23 -06005491 const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{
5492 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5493 "vkCmdPushConstants() call has push constants with size 0. Size "
5494 "must be greater than zero and a multiple of 4."},
5495 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5496 "vkCmdPushConstants() call has push constants with size 1. Size "
5497 "must be greater than zero and a multiple of 4."},
5498 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1},
5499 "vkCmdPushConstants() call has push constants with size 1. Size "
5500 "must be greater than zero and a multiple of 4."},
5501 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0},
5502 "vkCmdPushConstants() call has push constants with offset 1. "
5503 "Offset must be a multiple of 4."},
5504 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5505 "vkCmdPushConstants() call has push constants with offset 1. "
5506 "Offset must be a multiple of 4."},
5507 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5508 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5509 "0x1 not within flag-matching ranges in pipeline layout"},
5510 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
5511 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
5512 "0x1 not within flag-matching ranges in pipeline layout"},
5513 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
5514 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
5515 "0x1 not within flag-matching ranges in pipeline layout"},
5516 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
5517 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
5518 "0x1 not within flag-matching ranges in pipeline layout"},
5519 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
5520 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
5521 "any of the ranges in pipeline layout"},
5522 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
5523 0, 16},
5524 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
5525 "any of the ranges in pipeline layout"},
5526 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005527 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005528 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005529 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005530 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005531 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005532 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005533 "vkCmdPushConstants() call has push constants with offset "},
Karl Schultzc81037d2016-05-12 08:11:23 -06005534 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005535 "vkCmdPushConstants() call has push constants with offset "},
5536 }};
5537
5538 // Two ranges for testing robustness
Karl Schultzc81037d2016-05-12 08:11:23 -06005539 const VkPushConstantRange pc_range2[] = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005540 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06005541 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005542 };
Karl Schultzc81037d2016-05-12 08:11:23 -06005543 pipeline_layout_ci.pushConstantRangeCount =
5544 sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005545 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005546 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5547 &pipeline_layout);
5548 ASSERT_VK_SUCCESS(err);
5549 BeginCommandBuffer();
Karl Schultzc81037d2016-05-12 08:11:23 -06005550 for (const auto &iter : cmd_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5552 iter.msg);
5553 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
Karl Schultzc81037d2016-05-12 08:11:23 -06005554 iter.range.stageFlags, iter.range.offset,
5555 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005556 m_errorMonitor->VerifyFound();
5557 }
5558
5559 // Check for invalid stage flag
5560 m_errorMonitor->SetDesiredFailureMsg(
5561 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5562 "vkCmdPushConstants() call has no stageFlags set.");
5563 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0,
Karl Schultzc81037d2016-05-12 08:11:23 -06005564 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005565 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06005566 EndCommandBuffer();
5567 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5568 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005569
Karl Schultzc81037d2016-05-12 08:11:23 -06005570 // overlapping range tests with cmd
5571 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
5572 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
5573 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
5574 "0x1 not within flag-matching ranges in pipeline layout"},
5575 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
5576 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
5577 "0x1 not within flag-matching ranges in pipeline layout"},
5578 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
5579 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
5580 "0x1 not within flag-matching ranges in pipeline layout"},
5581 }};
5582 const VkPushConstantRange pc_range3[] = {
5583 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5584 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5585 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5586 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5587 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5588 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5589 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5590 };
5591 pipeline_layout_ci.pushConstantRangeCount =
5592 sizeof(pc_range3) / sizeof(VkPushConstantRange);
5593 pipeline_layout_ci.pPushConstantRanges = pc_range3;
5594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5595 &pipeline_layout);
5596 ASSERT_VK_SUCCESS(err);
5597 BeginCommandBuffer();
5598 for (const auto &iter : cmd_overlap_tests) {
5599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5600 iter.msg);
5601 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5602 iter.range.stageFlags, iter.range.offset,
5603 iter.range.size, dummy_values);
5604 m_errorMonitor->VerifyFound();
5605 }
5606 EndCommandBuffer();
5607 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
5608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5609
5610 // positive overlapping range tests with cmd
5611 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
5612 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
5613 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
5614 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
5615 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
5616 }};
5617 const VkPushConstantRange pc_range4[] = {
5618 {VK_SHADER_STAGE_VERTEX_BIT, 0, 64},
5619 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16},
5620 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
5621 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
5622 {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
5623 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12},
5624 {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
5625 {VK_SHADER_STAGE_VERTEX_BIT, 56, 28},
5626 };
5627 pipeline_layout_ci.pushConstantRangeCount =
5628 sizeof(pc_range4) / sizeof(VkPushConstantRange);
5629 pipeline_layout_ci.pPushConstantRanges = pc_range4;
5630 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5631 &pipeline_layout);
5632 ASSERT_VK_SUCCESS(err);
5633 BeginCommandBuffer();
5634 for (const auto &iter : cmd_overlap_tests_pos) {
5635 m_errorMonitor->ExpectSuccess();
5636 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
5637 iter.range.stageFlags, iter.range.offset,
5638 iter.range.size, dummy_values);
5639 m_errorMonitor->VerifyNotFound();
5640 }
5641 EndCommandBuffer();
5642 vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5644}
5645
Karl Schultz6addd812016-02-02 17:17:23 -07005646TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005647 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07005648 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005649
5650 ASSERT_NO_FATAL_FAILURE(InitState());
5651 ASSERT_NO_FATAL_FAILURE(InitViewport());
5652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5653
5654 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
5655 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005656 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5657 ds_type_count[0].descriptorCount = 10;
5658 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5659 ds_type_count[1].descriptorCount = 2;
5660 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5661 ds_type_count[2].descriptorCount = 2;
5662 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
5663 ds_type_count[3].descriptorCount = 5;
5664 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
5665 // type
5666 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
5667 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
5668 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005669
5670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5672 ds_pool_ci.pNext = NULL;
5673 ds_pool_ci.maxSets = 5;
5674 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
5675 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005676
5677 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005678 err =
5679 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005680 ASSERT_VK_SUCCESS(err);
5681
5682 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
5683 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005684 dsl_binding[0].binding = 0;
5685 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5686 dsl_binding[0].descriptorCount = 5;
5687 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
5688 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005689
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005690 // Create layout identical to set0 layout but w/ different stageFlags
5691 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005692 dsl_fs_stage_only.binding = 0;
5693 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5694 dsl_fs_stage_only.descriptorCount = 5;
5695 dsl_fs_stage_only.stageFlags =
5696 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
5697 // bind time
5698 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005699 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005700 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5701 ds_layout_ci.pNext = NULL;
5702 ds_layout_ci.bindingCount = 1;
5703 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005704 static const uint32_t NUM_LAYOUTS = 4;
5705 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005706 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005707 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
5708 // layout for error case
5709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5710 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005711 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005712 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5714 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005715 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005716 dsl_binding[0].binding = 0;
5717 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005718 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005719 dsl_binding[1].binding = 1;
5720 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
5721 dsl_binding[1].descriptorCount = 2;
5722 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
5723 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07005724 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005725 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005726 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5727 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005728 ASSERT_VK_SUCCESS(err);
5729 dsl_binding[0].binding = 0;
5730 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005731 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005732 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07005733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5734 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005735 ASSERT_VK_SUCCESS(err);
5736 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005737 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07005738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5739 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005740 ASSERT_VK_SUCCESS(err);
5741
5742 static const uint32_t NUM_SETS = 4;
5743 VkDescriptorSet descriptorSet[NUM_SETS] = {};
5744 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005745 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005746 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005747 alloc_info.descriptorPool = ds_pool;
5748 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005749 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5750 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005751 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005752 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07005753 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005754 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005755 err =
5756 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005758
5759 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005760 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5761 pipeline_layout_ci.pNext = NULL;
5762 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
5763 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005764
5765 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5767 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005769 // Create pipelineLayout with only one setLayout
5770 pipeline_layout_ci.setLayoutCount = 1;
5771 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5773 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005774 ASSERT_VK_SUCCESS(err);
5775 // Create pipelineLayout with 2 descriptor setLayout at index 0
5776 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
5777 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07005778 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5779 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005780 ASSERT_VK_SUCCESS(err);
5781 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
5782 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
5783 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07005784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5785 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005786 ASSERT_VK_SUCCESS(err);
5787 // Create pipelineLayout with UB type, but stageFlags for FS only
5788 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
5789 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07005790 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5791 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005792 ASSERT_VK_SUCCESS(err);
5793 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
5794 VkDescriptorSetLayout pl_bad_s0[2] = {};
5795 pl_bad_s0[0] = ds_layout_fs_only;
5796 pl_bad_s0[1] = ds_layout[1];
5797 pipeline_layout_ci.setLayoutCount = 2;
5798 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
5799 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07005800 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5801 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005802 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005803
5804 // Create a buffer to update the descriptor with
5805 uint32_t qfi = 0;
5806 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005807 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5808 buffCI.size = 1024;
5809 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5810 buffCI.queueFamilyIndexCount = 1;
5811 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005812
5813 VkBuffer dyub;
5814 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5815 ASSERT_VK_SUCCESS(err);
5816 // Correctly update descriptor to avoid "NOT_UPDATED" error
5817 static const uint32_t NUM_BUFFS = 5;
5818 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005819 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07005820 buffInfo[i].buffer = dyub;
5821 buffInfo[i].offset = 0;
5822 buffInfo[i].range = 1024;
5823 }
Karl Schultz6addd812016-02-02 17:17:23 -07005824 VkImage image;
5825 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5826 const int32_t tex_width = 32;
5827 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005828 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005829 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5830 image_create_info.pNext = NULL;
5831 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5832 image_create_info.format = tex_format;
5833 image_create_info.extent.width = tex_width;
5834 image_create_info.extent.height = tex_height;
5835 image_create_info.extent.depth = 1;
5836 image_create_info.mipLevels = 1;
5837 image_create_info.arrayLayers = 1;
5838 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5839 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5840 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5841 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5843 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005844
Karl Schultz6addd812016-02-02 17:17:23 -07005845 VkMemoryRequirements memReqs;
5846 VkDeviceMemory imageMem;
5847 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005848 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5850 memAlloc.pNext = NULL;
5851 memAlloc.allocationSize = 0;
5852 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005853 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
5854 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07005855 pass =
5856 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07005857 ASSERT_TRUE(pass);
5858 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
5859 ASSERT_VK_SUCCESS(err);
5860 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
5861 ASSERT_VK_SUCCESS(err);
5862
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005863 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005864 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5865 image_view_create_info.image = image;
5866 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5867 image_view_create_info.format = tex_format;
5868 image_view_create_info.subresourceRange.layerCount = 1;
5869 image_view_create_info.subresourceRange.baseMipLevel = 0;
5870 image_view_create_info.subresourceRange.levelCount = 1;
5871 image_view_create_info.subresourceRange.aspectMask =
5872 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07005873
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005874 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07005875 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
5876 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005877 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005878 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005879 imageInfo[0].imageView = view;
5880 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5881 imageInfo[1].imageView = view;
5882 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005883 imageInfo[2].imageView = view;
5884 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5885 imageInfo[3].imageView = view;
5886 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005887
5888 static const uint32_t NUM_SET_UPDATES = 3;
5889 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
5890 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5891 descriptor_write[0].dstSet = descriptorSet[0];
5892 descriptor_write[0].dstBinding = 0;
5893 descriptor_write[0].descriptorCount = 5;
5894 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5895 descriptor_write[0].pBufferInfo = buffInfo;
5896 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5897 descriptor_write[1].dstSet = descriptorSet[1];
5898 descriptor_write[1].dstBinding = 0;
5899 descriptor_write[1].descriptorCount = 2;
5900 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
5901 descriptor_write[1].pImageInfo = imageInfo;
5902 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5903 descriptor_write[2].dstSet = descriptorSet[1];
5904 descriptor_write[2].dstBinding = 1;
5905 descriptor_write[2].descriptorCount = 2;
5906 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07005907 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005908
5909 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005910
Tobin Ehlis88452832015-12-03 09:40:56 -07005911 // Create PSO to be used for draw-time errors below
5912 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005913 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005914 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07005915 "out gl_PerVertex {\n"
5916 " vec4 gl_Position;\n"
5917 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005918 "void main(){\n"
5919 " gl_Position = vec4(1);\n"
5920 "}\n";
5921 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12005922 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07005923 "\n"
5924 "layout(location=0) out vec4 x;\n"
5925 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5926 "void main(){\n"
5927 " x = vec4(bar.y);\n"
5928 "}\n";
5929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07005931 VkPipelineObj pipe(m_device);
5932 pipe.AddShader(&vs);
5933 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07005934 pipe.AddColorAttachment();
5935 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07005936
5937 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07005938
Karl Schultz6addd812016-02-02 17:17:23 -07005939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5940 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5941 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
5942 // of PSO
5943 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
5944 // cmd_pipeline.c
5945 // due to the fact that cmd_alloc_dset_data() has not been called in
5946 // cmd_bind_graphics_pipeline()
5947 // TODO : Want to cause various binding incompatibility issues here to test
5948 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07005949 // First cause various verify_layout_compatibility() fails
5950 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005951 // verify_set_layout_compatibility fail cases:
5952 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07005953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5954 " due to: invalid VkPipelineLayout ");
5955 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5956 VK_PIPELINE_BIND_POINT_GRAPHICS,
5957 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
5958 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005959 m_errorMonitor->VerifyFound();
5960
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005961 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07005962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5963 " attempting to bind set to index 1");
5964 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
5965 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
5966 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005967 m_errorMonitor->VerifyFound();
5968
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005969 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07005970 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
5971 // descriptors
5972 m_errorMonitor->SetDesiredFailureMsg(
5973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005974 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005975 vkCmdBindDescriptorSets(
5976 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5977 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005978 m_errorMonitor->VerifyFound();
5979
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005980 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
5981 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07005982 m_errorMonitor->SetDesiredFailureMsg(
5983 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005984 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07005985 vkCmdBindDescriptorSets(
5986 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5987 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005988 m_errorMonitor->VerifyFound();
5989
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005990 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
5991 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07005992 m_errorMonitor->SetDesiredFailureMsg(
5993 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005994 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07005995 vkCmdBindDescriptorSets(
5996 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
5997 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005998 m_errorMonitor->VerifyFound();
5999
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006000 // Cause INFO messages due to disturbing previously bound Sets
6001 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07006002 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6003 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6004 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006005 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07006006 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006007 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006008 " previously bound as set #0 was disturbed ");
6009 vkCmdBindDescriptorSets(
6010 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6011 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006012 m_errorMonitor->VerifyFound();
6013
Karl Schultz6addd812016-02-02 17:17:23 -07006014 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6015 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6016 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006017 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006019 " newly bound as set #0 so set #1 and "
6020 "any subsequent sets were disturbed ");
6021 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6022 VK_PIPELINE_BIND_POINT_GRAPHICS,
6023 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006024 m_errorMonitor->VerifyFound();
6025
Tobin Ehlis88452832015-12-03 09:40:56 -07006026 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006027 // 1. Error due to not binding required set (we actually use same code as
6028 // above to disturb set0)
6029 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6030 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6031 2, &descriptorSet[0], 0, NULL);
6032 vkCmdBindDescriptorSets(
6033 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6034 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
6035 m_errorMonitor->SetDesiredFailureMsg(
6036 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6037 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006038 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006039 m_errorMonitor->VerifyFound();
6040
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006041 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006042 // 2. Error due to bound set not being compatible with PSO's
6043 // VkPipelineLayout (diff stageFlags in this case)
6044 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
6045 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
6046 2, &descriptorSet[0], 0, NULL);
6047 m_errorMonitor->SetDesiredFailureMsg(
6048 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6049 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006050 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006051 m_errorMonitor->VerifyFound();
6052
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006053 // Remaining clean-up
6054 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006055 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6057 }
6058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06006059 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
6060 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006061 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006062 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6063 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006064 vkFreeMemory(m_device->device(), imageMem, NULL);
6065 vkDestroyImage(m_device->device(), image, NULL);
6066 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006067}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006068
Karl Schultz6addd812016-02-02 17:17:23 -07006069TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006070
Karl Schultz6addd812016-02-02 17:17:23 -07006071 m_errorMonitor->SetDesiredFailureMsg(
6072 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006073 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006074
6075 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006076 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006077 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006078 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006079
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006080 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006081}
6082
Karl Schultz6addd812016-02-02 17:17:23 -07006083TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6084 VkResult err;
6085 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006086
Karl Schultz6addd812016-02-02 17:17:23 -07006087 m_errorMonitor->SetDesiredFailureMsg(
6088 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006089 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006090
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006091 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006092
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006093 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006094 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006095 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006096 cmd.commandPool = m_commandPool;
6097 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006098 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006099
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006100 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006101 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006102
6103 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006104 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006105 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006106 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006107 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006108 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
6109 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006110 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006111
6112 // The error should be caught by validation of the BeginCommandBuffer call
6113 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6114
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006115 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006116 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006117}
6118
Karl Schultz6addd812016-02-02 17:17:23 -07006119TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006120 // Cause error due to Begin while recording CB
6121 // Then cause 2 errors for attempting to reset CB w/o having
6122 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6123 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006125 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006126
6127 ASSERT_NO_FATAL_FAILURE(InitState());
6128
6129 // Calls AllocateCommandBuffers
6130 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6131
Karl Schultz6addd812016-02-02 17:17:23 -07006132 // Force the failure by setting the Renderpass and Framebuffer fields with
6133 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006134 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006135 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006136 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6137 cmd_buf_info.pNext = NULL;
6138 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006139 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006140
6141 // Begin CB to transition to recording state
6142 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6143 // Can't re-begin. This should trigger error
6144 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006145 m_errorMonitor->VerifyFound();
6146
Karl Schultz6addd812016-02-02 17:17:23 -07006147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006149 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6150 // Reset attempt will trigger error due to incorrect CommandPool state
6151 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006152 m_errorMonitor->VerifyFound();
6153
Karl Schultz6addd812016-02-02 17:17:23 -07006154 m_errorMonitor->SetDesiredFailureMsg(
6155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6156 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006157 // Transition CB to RECORDED state
6158 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6159 // Now attempting to Begin will implicitly reset, which triggers error
6160 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006161 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006162}
6163
Karl Schultz6addd812016-02-02 17:17:23 -07006164TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006165 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006166 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006167
Karl Schultz6addd812016-02-02 17:17:23 -07006168 m_errorMonitor->SetDesiredFailureMsg(
6169 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006170 "Invalid Pipeline CreateInfo State: Vtx Shader required");
6171
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006172 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006174
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6177 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006178
6179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6181 ds_pool_ci.pNext = NULL;
6182 ds_pool_ci.maxSets = 1;
6183 ds_pool_ci.poolSizeCount = 1;
6184 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006185
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006186 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006187 err =
6188 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006189 ASSERT_VK_SUCCESS(err);
6190
Tony Barboureb254902015-07-15 12:50:33 -06006191 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006192 dsl_binding.binding = 0;
6193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6194 dsl_binding.descriptorCount = 1;
6195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6196 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006197
Tony Barboureb254902015-07-15 12:50:33 -06006198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6200 ds_layout_ci.pNext = NULL;
6201 ds_layout_ci.bindingCount = 1;
6202 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006203
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006204 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6206 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006207 ASSERT_VK_SUCCESS(err);
6208
6209 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006210 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006212 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006213 alloc_info.descriptorPool = ds_pool;
6214 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6216 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006217 ASSERT_VK_SUCCESS(err);
6218
Tony Barboureb254902015-07-15 12:50:33 -06006219 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006220 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6221 pipeline_layout_ci.setLayoutCount = 1;
6222 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006223
6224 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6226 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006227 ASSERT_VK_SUCCESS(err);
6228
Tobin Ehlise68360f2015-10-01 11:15:13 -06006229 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006230 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006231
6232 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006233 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6234 vp_state_ci.scissorCount = 1;
6235 vp_state_ci.pScissors = &sc;
6236 vp_state_ci.viewportCount = 1;
6237 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006238
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006239 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6240 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6241 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6242 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6243 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6244 rs_state_ci.depthClampEnable = VK_FALSE;
6245 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6246 rs_state_ci.depthBiasEnable = VK_FALSE;
6247
Tony Barboureb254902015-07-15 12:50:33 -06006248 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6250 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006251 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006252 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6253 gp_ci.layout = pipeline_layout;
6254 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006255
6256 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006257 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6258 pc_ci.initialDataSize = 0;
6259 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006260
6261 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006262 VkPipelineCache pipelineCache;
6263
Karl Schultz6addd812016-02-02 17:17:23 -07006264 err =
6265 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006266 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006267 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6268 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006269
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006270 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006271
Chia-I Wuf7458c52015-10-26 21:10:41 +08006272 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6273 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6274 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6275 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006276}
Tobin Ehlis912df022015-09-17 08:46:18 -06006277/*// TODO : This test should be good, but needs Tess support in compiler to run
6278TEST_F(VkLayerTest, InvalidPatchControlPoints)
6279{
6280 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006281 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006282
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006284 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6285primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006286
Tobin Ehlis912df022015-09-17 08:46:18 -06006287 ASSERT_NO_FATAL_FAILURE(InitState());
6288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006289
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006290 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006291 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006292 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006293
6294 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6295 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6296 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006297 ds_pool_ci.poolSizeCount = 1;
6298 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006299
6300 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006301 err = vkCreateDescriptorPool(m_device->device(),
6302VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006303 ASSERT_VK_SUCCESS(err);
6304
6305 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006306 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006307 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006308 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006309 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6310 dsl_binding.pImmutableSamplers = NULL;
6311
6312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006313 ds_layout_ci.sType =
6314VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006315 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006316 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006317 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006318
6319 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6321&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006322 ASSERT_VK_SUCCESS(err);
6323
6324 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006325 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6326VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006327 ASSERT_VK_SUCCESS(err);
6328
6329 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006330 pipeline_layout_ci.sType =
6331VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006332 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006333 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006334 pipeline_layout_ci.pSetLayouts = &ds_layout;
6335
6336 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6338&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006339 ASSERT_VK_SUCCESS(err);
6340
6341 VkPipelineShaderStageCreateInfo shaderStages[3];
6342 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6343
Karl Schultz6addd812016-02-02 17:17:23 -07006344 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6345this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006346 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006347 VkShaderObj
6348tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6349this);
6350 VkShaderObj
6351te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6352this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006353
Karl Schultz6addd812016-02-02 17:17:23 -07006354 shaderStages[0].sType =
6355VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006356 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006357 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006358 shaderStages[1].sType =
6359VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006360 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006361 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006362 shaderStages[2].sType =
6363VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006364 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006365 shaderStages[2].shader = te.handle();
6366
6367 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006368 iaCI.sType =
6369VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006370 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006371
6372 VkPipelineTessellationStateCreateInfo tsCI = {};
6373 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6374 tsCI.patchControlPoints = 0; // This will cause an error
6375
6376 VkGraphicsPipelineCreateInfo gp_ci = {};
6377 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6378 gp_ci.pNext = NULL;
6379 gp_ci.stageCount = 3;
6380 gp_ci.pStages = shaderStages;
6381 gp_ci.pVertexInputState = NULL;
6382 gp_ci.pInputAssemblyState = &iaCI;
6383 gp_ci.pTessellationState = &tsCI;
6384 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006385 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006386 gp_ci.pMultisampleState = NULL;
6387 gp_ci.pDepthStencilState = NULL;
6388 gp_ci.pColorBlendState = NULL;
6389 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6390 gp_ci.layout = pipeline_layout;
6391 gp_ci.renderPass = renderPass();
6392
6393 VkPipelineCacheCreateInfo pc_ci = {};
6394 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6395 pc_ci.pNext = NULL;
6396 pc_ci.initialSize = 0;
6397 pc_ci.initialData = 0;
6398 pc_ci.maxSize = 0;
6399
6400 VkPipeline pipeline;
6401 VkPipelineCache pipelineCache;
6402
Karl Schultz6addd812016-02-02 17:17:23 -07006403 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6404&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006405 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006406 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6407&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006409 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006410
Chia-I Wuf7458c52015-10-26 21:10:41 +08006411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006415}
6416*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006417// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006418TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006419 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006420
Karl Schultz6addd812016-02-02 17:17:23 -07006421 m_errorMonitor->SetDesiredFailureMsg(
6422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006423 "Gfx Pipeline viewport count (1) must match scissor count (0).");
6424
Tobin Ehlise68360f2015-10-01 11:15:13 -06006425 ASSERT_NO_FATAL_FAILURE(InitState());
6426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006427
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006428 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6430 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006431
6432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6434 ds_pool_ci.maxSets = 1;
6435 ds_pool_ci.poolSizeCount = 1;
6436 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006437
6438 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006439 err =
6440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006441 ASSERT_VK_SUCCESS(err);
6442
6443 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006444 dsl_binding.binding = 0;
6445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6446 dsl_binding.descriptorCount = 1;
6447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006448
6449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6451 ds_layout_ci.bindingCount = 1;
6452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006453
6454 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6456 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006457 ASSERT_VK_SUCCESS(err);
6458
6459 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006462 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006463 alloc_info.descriptorPool = ds_pool;
6464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6466 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006467 ASSERT_VK_SUCCESS(err);
6468
6469 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006470 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6471 pipeline_layout_ci.setLayoutCount = 1;
6472 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006473
6474 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6476 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006477 ASSERT_VK_SUCCESS(err);
6478
6479 VkViewport vp = {}; // Just need dummy vp to point to
6480
6481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6483 vp_state_ci.scissorCount = 0;
6484 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6485 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006486
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006487 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6488 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6489 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6490 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6491 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6492 rs_state_ci.depthClampEnable = VK_FALSE;
6493 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6494 rs_state_ci.depthBiasEnable = VK_FALSE;
6495
Cody Northropeb3a6c12015-10-05 14:44:45 -06006496 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006497 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006498
Karl Schultz6addd812016-02-02 17:17:23 -07006499 VkShaderObj vs(m_device, bindStateVertShaderText,
6500 VK_SHADER_STAGE_VERTEX_BIT, this);
6501 VkShaderObj fs(m_device, bindStateFragShaderText,
6502 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006503 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006504 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006505 shaderStages[0] = vs.GetStageCreateInfo();
6506 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006507
6508 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6510 gp_ci.stageCount = 2;
6511 gp_ci.pStages = shaderStages;
6512 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006513 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006514 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6515 gp_ci.layout = pipeline_layout;
6516 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006517
6518 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006519 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006520
6521 VkPipeline pipeline;
6522 VkPipelineCache pipelineCache;
6523
Karl Schultz6addd812016-02-02 17:17:23 -07006524 err =
6525 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006526 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006527 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6528 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006529
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006530 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006531
Chia-I Wuf7458c52015-10-26 21:10:41 +08006532 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6533 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6535 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006536}
Karl Schultz6addd812016-02-02 17:17:23 -07006537// Don't set viewport state in PSO. This is an error b/c we always need this
6538// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06006539// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07006540TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06006541 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006542 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006543
Karl Schultz6addd812016-02-02 17:17:23 -07006544 m_errorMonitor->SetDesiredFailureMsg(
6545 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006546 "Gfx Pipeline pViewportState is null. Even if ");
6547
Tobin Ehlise68360f2015-10-01 11:15:13 -06006548 ASSERT_NO_FATAL_FAILURE(InitState());
6549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006550
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006551 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006552 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6553 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006554
6555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6557 ds_pool_ci.maxSets = 1;
6558 ds_pool_ci.poolSizeCount = 1;
6559 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006560
6561 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006562 err =
6563 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006564 ASSERT_VK_SUCCESS(err);
6565
6566 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006567 dsl_binding.binding = 0;
6568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6569 dsl_binding.descriptorCount = 1;
6570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006571
6572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6574 ds_layout_ci.bindingCount = 1;
6575 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006576
6577 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006578 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6579 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006580 ASSERT_VK_SUCCESS(err);
6581
6582 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006583 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006585 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006586 alloc_info.descriptorPool = ds_pool;
6587 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6589 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006590 ASSERT_VK_SUCCESS(err);
6591
6592 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006593 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6594 pipeline_layout_ci.setLayoutCount = 1;
6595 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006596
6597 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006598 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6599 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006600 ASSERT_VK_SUCCESS(err);
6601
6602 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6603 // Set scissor as dynamic to avoid second error
6604 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6606 dyn_state_ci.dynamicStateCount = 1;
6607 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006608
Cody Northropeb3a6c12015-10-05 14:44:45 -06006609 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006610 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006611
Karl Schultz6addd812016-02-02 17:17:23 -07006612 VkShaderObj vs(m_device, bindStateVertShaderText,
6613 VK_SHADER_STAGE_VERTEX_BIT, this);
6614 VkShaderObj fs(m_device, bindStateFragShaderText,
6615 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006616 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006617 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006618 shaderStages[0] = vs.GetStageCreateInfo();
6619 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006620
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006621
6622 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6623 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6624 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6625 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6626 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6627 rs_state_ci.depthClampEnable = VK_FALSE;
6628 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6629 rs_state_ci.depthBiasEnable = VK_FALSE;
6630
Tobin Ehlise68360f2015-10-01 11:15:13 -06006631 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006632 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6633 gp_ci.stageCount = 2;
6634 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006635 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006636 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
6637 // should cause validation error
6638 gp_ci.pDynamicState = &dyn_state_ci;
6639 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6640 gp_ci.layout = pipeline_layout;
6641 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006642
6643 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006644 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006645
6646 VkPipeline pipeline;
6647 VkPipelineCache pipelineCache;
6648
Karl Schultz6addd812016-02-02 17:17:23 -07006649 err =
6650 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006651 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6653 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006655 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006656
Chia-I Wuf7458c52015-10-26 21:10:41 +08006657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6660 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006661}
6662// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07006663// Then run second test where dynamic scissor count doesn't match PSO scissor
6664// count
6665TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
6666 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006667
Karl Schultz6addd812016-02-02 17:17:23 -07006668 m_errorMonitor->SetDesiredFailureMsg(
6669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006670 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
6671
Tobin Ehlise68360f2015-10-01 11:15:13 -06006672 ASSERT_NO_FATAL_FAILURE(InitState());
6673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006674
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006675 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006676 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6677 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006678
6679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6681 ds_pool_ci.maxSets = 1;
6682 ds_pool_ci.poolSizeCount = 1;
6683 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006684
6685 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006686 err =
6687 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006688 ASSERT_VK_SUCCESS(err);
6689
6690 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006691 dsl_binding.binding = 0;
6692 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6693 dsl_binding.descriptorCount = 1;
6694 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006695
6696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6698 ds_layout_ci.bindingCount = 1;
6699 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006700
6701 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006702 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6703 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006704 ASSERT_VK_SUCCESS(err);
6705
6706 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006707 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006709 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006710 alloc_info.descriptorPool = ds_pool;
6711 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006712 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6713 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006714 ASSERT_VK_SUCCESS(err);
6715
6716 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006717 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6718 pipeline_layout_ci.setLayoutCount = 1;
6719 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006720
6721 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006722 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6723 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006724 ASSERT_VK_SUCCESS(err);
6725
6726 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006727 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6728 vp_state_ci.viewportCount = 1;
6729 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
6730 vp_state_ci.scissorCount = 1;
6731 vp_state_ci.pScissors =
6732 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06006733
6734 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
6735 // Set scissor as dynamic to avoid that error
6736 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006737 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6738 dyn_state_ci.dynamicStateCount = 1;
6739 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006740
Cody Northropeb3a6c12015-10-05 14:44:45 -06006741 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006742 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006743
Karl Schultz6addd812016-02-02 17:17:23 -07006744 VkShaderObj vs(m_device, bindStateVertShaderText,
6745 VK_SHADER_STAGE_VERTEX_BIT, this);
6746 VkShaderObj fs(m_device, bindStateFragShaderText,
6747 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006748 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006750 shaderStages[0] = vs.GetStageCreateInfo();
6751 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006752
Cody Northropf6622dc2015-10-06 10:33:21 -06006753 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6754 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6755 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006756 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006757 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006758 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06006759 vi_ci.pVertexAttributeDescriptions = nullptr;
6760
6761 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6762 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6763 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6764
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006765 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006766 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06006767 rs_ci.pNext = nullptr;
6768
Mark Youngc89c6312016-03-31 16:03:20 -06006769 VkPipelineColorBlendAttachmentState att = {};
6770 att.blendEnable = VK_FALSE;
6771 att.colorWriteMask = 0xf;
6772
Cody Northropf6622dc2015-10-06 10:33:21 -06006773 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6774 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6775 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006776 cb_ci.attachmentCount = 1;
6777 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06006778
Tobin Ehlise68360f2015-10-01 11:15:13 -06006779 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006780 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6781 gp_ci.stageCount = 2;
6782 gp_ci.pStages = shaderStages;
6783 gp_ci.pVertexInputState = &vi_ci;
6784 gp_ci.pInputAssemblyState = &ia_ci;
6785 gp_ci.pViewportState = &vp_state_ci;
6786 gp_ci.pRasterizationState = &rs_ci;
6787 gp_ci.pColorBlendState = &cb_ci;
6788 gp_ci.pDynamicState = &dyn_state_ci;
6789 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6790 gp_ci.layout = pipeline_layout;
6791 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006792
6793 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006794 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006795
6796 VkPipeline pipeline;
6797 VkPipelineCache pipelineCache;
6798
Karl Schultz6addd812016-02-02 17:17:23 -07006799 err =
6800 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006801 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006802 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6803 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006804
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006805 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006806
Tobin Ehlisd332f282015-10-02 11:00:56 -06006807 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07006808 // First need to successfully create the PSO from above by setting
6809 // pViewports
6810 m_errorMonitor->SetDesiredFailureMsg(
6811 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6812 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
6813 "scissorCount is 1. These counts must match.");
6814
6815 VkViewport vp = {}; // Just need dummy vp to point to
6816 vp_state_ci.pViewports = &vp;
6817 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6818 &gp_ci, NULL, &pipeline);
6819 ASSERT_VK_SUCCESS(err);
6820 BeginCommandBuffer();
6821 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6822 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
6823 VkRect2D scissors[2] = {}; // don't care about data
6824 // Count of 2 doesn't match PSO count of 1
6825 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
6826 Draw(1, 0, 0, 0);
6827
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006828 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006829
6830 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006834 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006835}
6836// Create PSO w/o non-zero scissorCount but no scissor data
6837// Then run second test where dynamic viewportCount doesn't match PSO
6838// viewportCount
6839TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
6840 VkResult err;
6841
6842 m_errorMonitor->SetDesiredFailureMsg(
6843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6844 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
6845
6846 ASSERT_NO_FATAL_FAILURE(InitState());
6847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6848
6849 VkDescriptorPoolSize ds_type_count = {};
6850 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6851 ds_type_count.descriptorCount = 1;
6852
6853 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6854 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6855 ds_pool_ci.maxSets = 1;
6856 ds_pool_ci.poolSizeCount = 1;
6857 ds_pool_ci.pPoolSizes = &ds_type_count;
6858
6859 VkDescriptorPool ds_pool;
6860 err =
6861 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6862 ASSERT_VK_SUCCESS(err);
6863
6864 VkDescriptorSetLayoutBinding dsl_binding = {};
6865 dsl_binding.binding = 0;
6866 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6867 dsl_binding.descriptorCount = 1;
6868 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6869
6870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6872 ds_layout_ci.bindingCount = 1;
6873 ds_layout_ci.pBindings = &dsl_binding;
6874
6875 VkDescriptorSetLayout ds_layout;
6876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6877 &ds_layout);
6878 ASSERT_VK_SUCCESS(err);
6879
6880 VkDescriptorSet descriptorSet;
6881 VkDescriptorSetAllocateInfo alloc_info = {};
6882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6883 alloc_info.descriptorSetCount = 1;
6884 alloc_info.descriptorPool = ds_pool;
6885 alloc_info.pSetLayouts = &ds_layout;
6886 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6887 &descriptorSet);
6888 ASSERT_VK_SUCCESS(err);
6889
6890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6892 pipeline_layout_ci.setLayoutCount = 1;
6893 pipeline_layout_ci.pSetLayouts = &ds_layout;
6894
6895 VkPipelineLayout pipeline_layout;
6896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6897 &pipeline_layout);
6898 ASSERT_VK_SUCCESS(err);
6899
6900 VkPipelineViewportStateCreateInfo vp_state_ci = {};
6901 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6902 vp_state_ci.scissorCount = 1;
6903 vp_state_ci.pScissors =
6904 NULL; // Null scissor w/ count of 1 should cause error
6905 vp_state_ci.viewportCount = 1;
6906 vp_state_ci.pViewports =
6907 NULL; // vp is dynamic (below) so this won't cause error
6908
6909 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
6910 // Set scissor as dynamic to avoid that error
6911 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
6912 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
6913 dyn_state_ci.dynamicStateCount = 1;
6914 dyn_state_ci.pDynamicStates = &vp_state;
6915
6916 VkPipelineShaderStageCreateInfo shaderStages[2];
6917 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6918
6919 VkShaderObj vs(m_device, bindStateVertShaderText,
6920 VK_SHADER_STAGE_VERTEX_BIT, this);
6921 VkShaderObj fs(m_device, bindStateFragShaderText,
6922 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006923 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006924 // but add it to be able to run on more devices
6925 shaderStages[0] = vs.GetStageCreateInfo();
6926 shaderStages[1] = fs.GetStageCreateInfo();
6927
6928 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6929 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6930 vi_ci.pNext = nullptr;
6931 vi_ci.vertexBindingDescriptionCount = 0;
6932 vi_ci.pVertexBindingDescriptions = nullptr;
6933 vi_ci.vertexAttributeDescriptionCount = 0;
6934 vi_ci.pVertexAttributeDescriptions = nullptr;
6935
6936 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6937 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6938 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6939
6940 VkPipelineRasterizationStateCreateInfo rs_ci = {};
6941 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6942 rs_ci.pNext = nullptr;
6943
Mark Youngc89c6312016-03-31 16:03:20 -06006944 VkPipelineColorBlendAttachmentState att = {};
6945 att.blendEnable = VK_FALSE;
6946 att.colorWriteMask = 0xf;
6947
Karl Schultz6addd812016-02-02 17:17:23 -07006948 VkPipelineColorBlendStateCreateInfo cb_ci = {};
6949 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
6950 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06006951 cb_ci.attachmentCount = 1;
6952 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07006953
6954 VkGraphicsPipelineCreateInfo gp_ci = {};
6955 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6956 gp_ci.stageCount = 2;
6957 gp_ci.pStages = shaderStages;
6958 gp_ci.pVertexInputState = &vi_ci;
6959 gp_ci.pInputAssemblyState = &ia_ci;
6960 gp_ci.pViewportState = &vp_state_ci;
6961 gp_ci.pRasterizationState = &rs_ci;
6962 gp_ci.pColorBlendState = &cb_ci;
6963 gp_ci.pDynamicState = &dyn_state_ci;
6964 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6965 gp_ci.layout = pipeline_layout;
6966 gp_ci.renderPass = renderPass();
6967
6968 VkPipelineCacheCreateInfo pc_ci = {};
6969 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6970
6971 VkPipeline pipeline;
6972 VkPipelineCache pipelineCache;
6973
6974 err =
6975 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
6976 ASSERT_VK_SUCCESS(err);
6977 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6978 &gp_ci, NULL, &pipeline);
6979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006980 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07006981
6982 // Now hit second fail case where we set scissor w/ different count than PSO
6983 // First need to successfully create the PSO from above by setting
6984 // pViewports
6985 m_errorMonitor->SetDesiredFailureMsg(
6986 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6987 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
6988 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006989
Tobin Ehlisd332f282015-10-02 11:00:56 -06006990 VkRect2D sc = {}; // Just need dummy vp to point to
6991 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07006992 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6993 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006994 ASSERT_VK_SUCCESS(err);
6995 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006996 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6997 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006998 VkViewport viewports[2] = {}; // don't care about data
6999 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07007000 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007001 Draw(1, 0, 0, 0);
7002
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007003 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007004
Chia-I Wuf7458c52015-10-26 21:10:41 +08007005 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7008 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007009 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007010}
7011
Mark Young7394fdd2016-03-31 14:56:43 -06007012TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7013 VkResult err;
7014
7015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007016 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007017
7018 ASSERT_NO_FATAL_FAILURE(InitState());
7019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7020
7021 VkDescriptorPoolSize ds_type_count = {};
7022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7023 ds_type_count.descriptorCount = 1;
7024
7025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7027 ds_pool_ci.maxSets = 1;
7028 ds_pool_ci.poolSizeCount = 1;
7029 ds_pool_ci.pPoolSizes = &ds_type_count;
7030
7031 VkDescriptorPool ds_pool;
7032 err =
7033 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7034 ASSERT_VK_SUCCESS(err);
7035
7036 VkDescriptorSetLayoutBinding dsl_binding = {};
7037 dsl_binding.binding = 0;
7038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7039 dsl_binding.descriptorCount = 1;
7040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7041
7042 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7043 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7044 ds_layout_ci.bindingCount = 1;
7045 ds_layout_ci.pBindings = &dsl_binding;
7046
7047 VkDescriptorSetLayout ds_layout;
7048 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7049 &ds_layout);
7050 ASSERT_VK_SUCCESS(err);
7051
7052 VkDescriptorSet descriptorSet;
7053 VkDescriptorSetAllocateInfo alloc_info = {};
7054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7055 alloc_info.descriptorSetCount = 1;
7056 alloc_info.descriptorPool = ds_pool;
7057 alloc_info.pSetLayouts = &ds_layout;
7058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7059 &descriptorSet);
7060 ASSERT_VK_SUCCESS(err);
7061
7062 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7063 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7064 pipeline_layout_ci.setLayoutCount = 1;
7065 pipeline_layout_ci.pSetLayouts = &ds_layout;
7066
7067 VkPipelineLayout pipeline_layout;
7068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7069 &pipeline_layout);
7070 ASSERT_VK_SUCCESS(err);
7071
7072 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7073 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7074 vp_state_ci.scissorCount = 1;
7075 vp_state_ci.pScissors = NULL;
7076 vp_state_ci.viewportCount = 1;
7077 vp_state_ci.pViewports = NULL;
7078
7079 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
7080 VK_DYNAMIC_STATE_SCISSOR,
7081 VK_DYNAMIC_STATE_LINE_WIDTH};
7082 // Set scissor as dynamic to avoid that error
7083 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7084 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7085 dyn_state_ci.dynamicStateCount = 2;
7086 dyn_state_ci.pDynamicStates = dynamic_states;
7087
7088 VkPipelineShaderStageCreateInfo shaderStages[2];
7089 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7090
7091 VkShaderObj vs(m_device, bindStateVertShaderText,
7092 VK_SHADER_STAGE_VERTEX_BIT, this);
7093 VkShaderObj fs(m_device, bindStateFragShaderText,
7094 VK_SHADER_STAGE_FRAGMENT_BIT,
7095 this); // TODO - We shouldn't need a fragment shader
7096 // but add it to be able to run on more devices
7097 shaderStages[0] = vs.GetStageCreateInfo();
7098 shaderStages[1] = fs.GetStageCreateInfo();
7099
7100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7102 vi_ci.pNext = nullptr;
7103 vi_ci.vertexBindingDescriptionCount = 0;
7104 vi_ci.pVertexBindingDescriptions = nullptr;
7105 vi_ci.vertexAttributeDescriptionCount = 0;
7106 vi_ci.pVertexAttributeDescriptions = nullptr;
7107
7108 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7109 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7110 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7111
7112 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7113 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7114 rs_ci.pNext = nullptr;
7115
Mark Young47107952016-05-02 15:59:55 -06007116 // Check too low (line width of -1.0f).
7117 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007118
7119 VkPipelineColorBlendAttachmentState att = {};
7120 att.blendEnable = VK_FALSE;
7121 att.colorWriteMask = 0xf;
7122
7123 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7124 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7125 cb_ci.pNext = nullptr;
7126 cb_ci.attachmentCount = 1;
7127 cb_ci.pAttachments = &att;
7128
7129 VkGraphicsPipelineCreateInfo gp_ci = {};
7130 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7131 gp_ci.stageCount = 2;
7132 gp_ci.pStages = shaderStages;
7133 gp_ci.pVertexInputState = &vi_ci;
7134 gp_ci.pInputAssemblyState = &ia_ci;
7135 gp_ci.pViewportState = &vp_state_ci;
7136 gp_ci.pRasterizationState = &rs_ci;
7137 gp_ci.pColorBlendState = &cb_ci;
7138 gp_ci.pDynamicState = &dyn_state_ci;
7139 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7140 gp_ci.layout = pipeline_layout;
7141 gp_ci.renderPass = renderPass();
7142
7143 VkPipelineCacheCreateInfo pc_ci = {};
7144 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7145
7146 VkPipeline pipeline;
7147 VkPipelineCache pipelineCache;
7148
7149 err =
7150 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7151 ASSERT_VK_SUCCESS(err);
7152 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7153 &gp_ci, NULL, &pipeline);
7154
7155 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007156 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007157
7158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7159 "Attempt to set lineWidth to 65536");
7160
7161 // Check too high (line width of 65536.0f).
7162 rs_ci.lineWidth = 65536.0f;
7163
7164 err =
7165 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7166 ASSERT_VK_SUCCESS(err);
7167 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7168 &gp_ci, NULL, &pipeline);
7169
7170 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007171 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007172
7173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06007174 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007175
7176 dyn_state_ci.dynamicStateCount = 3;
7177
7178 rs_ci.lineWidth = 1.0f;
7179
7180 err =
7181 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
7182 ASSERT_VK_SUCCESS(err);
7183 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7184 &gp_ci, NULL, &pipeline);
7185 BeginCommandBuffer();
7186 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7187 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
7188
7189 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007190 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007191 m_errorMonitor->VerifyFound();
7192
7193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7194 "Attempt to set lineWidth to 65536");
7195
7196 // Check too high with dynamic setting.
7197 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7198 m_errorMonitor->VerifyFound();
7199 EndCommandBuffer();
7200
7201 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7204 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007205 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007206}
7207
Karl Schultz6addd812016-02-02 17:17:23 -07007208TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007209 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007210 m_errorMonitor->SetDesiredFailureMsg(
7211 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007212 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007213
7214 ASSERT_NO_FATAL_FAILURE(InitState());
7215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007216
Tony Barbourfe3351b2015-07-28 10:17:20 -06007217 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007218 // Don't care about RenderPass handle b/c error should be flagged before
7219 // that
7220 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
7221 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007222
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007223 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007224}
7225
Karl Schultz6addd812016-02-02 17:17:23 -07007226TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007227 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007228 m_errorMonitor->SetDesiredFailureMsg(
7229 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007230 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007231
7232 ASSERT_NO_FATAL_FAILURE(InitState());
7233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007234
Tony Barbourfe3351b2015-07-28 10:17:20 -06007235 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007236 // Just create a dummy Renderpass that's non-NULL so we can get to the
7237 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06007238 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007239 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7240 rp_begin.pNext = NULL;
7241 rp_begin.renderPass = renderPass();
7242 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007243
Karl Schultz6addd812016-02-02 17:17:23 -07007244 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7245 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007246
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007247 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007248}
7249
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007250TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7251 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7252 "the number of renderPass attachments that use loadOp"
7253 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7254
7255 ASSERT_NO_FATAL_FAILURE(InitState());
7256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7257
7258 // Create a renderPass with a single attachment that uses loadOp CLEAR
7259 VkAttachmentReference attach = {};
7260 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7261 VkSubpassDescription subpass = {};
7262 subpass.inputAttachmentCount = 1;
7263 subpass.pInputAttachments = &attach;
7264 VkRenderPassCreateInfo rpci = {};
7265 rpci.subpassCount = 1;
7266 rpci.pSubpasses = &subpass;
7267 rpci.attachmentCount = 1;
7268 VkAttachmentDescription attach_desc = {};
7269 attach_desc.format = VK_FORMAT_UNDEFINED;
7270 // Set loadOp to CLEAR
7271 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7272 rpci.pAttachments = &attach_desc;
7273 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7274 VkRenderPass rp;
7275 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7276
7277 VkCommandBufferInheritanceInfo hinfo = {};
7278 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7279 hinfo.renderPass = VK_NULL_HANDLE;
7280 hinfo.subpass = 0;
7281 hinfo.framebuffer = VK_NULL_HANDLE;
7282 hinfo.occlusionQueryEnable = VK_FALSE;
7283 hinfo.queryFlags = 0;
7284 hinfo.pipelineStatistics = 0;
7285 VkCommandBufferBeginInfo info = {};
7286 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7287 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7288 info.pInheritanceInfo = &hinfo;
7289
7290 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7291 VkRenderPassBeginInfo rp_begin = {};
7292 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7293 rp_begin.pNext = NULL;
7294 rp_begin.renderPass = renderPass();
7295 rp_begin.framebuffer = framebuffer();
7296 rp_begin.clearValueCount = 0; // Should be 1
7297
7298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7299 " has a clearValueCount of 0 but the "
7300 "actual number of attachments in "
7301 "renderPass ");
7302
7303 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
7304 VK_SUBPASS_CONTENTS_INLINE);
7305
7306 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007307
7308 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007309}
7310
Cody Northrop3bb4d962016-05-09 16:15:57 -06007311TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7312
7313 TEST_DESCRIPTION("End a command buffer with an active render pass");
7314
7315 m_errorMonitor->SetDesiredFailureMsg(
7316 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7317 "It is invalid to issue this call inside an active render pass");
7318
7319 ASSERT_NO_FATAL_FAILURE(InitState());
7320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7321
7322 // The framework's BeginCommandBuffer calls CreateRenderPass
7323 BeginCommandBuffer();
7324
7325 // Call directly into vkEndCommandBuffer instead of the
7326 // the framework's EndCommandBuffer, which inserts a
7327 // vkEndRenderPass
7328 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7329
7330 m_errorMonitor->VerifyFound();
7331
7332 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7333 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
7334}
7335
Karl Schultz6addd812016-02-02 17:17:23 -07007336TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007337 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007338 m_errorMonitor->SetDesiredFailureMsg(
7339 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007341
7342 ASSERT_NO_FATAL_FAILURE(InitState());
7343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007344
7345 // Renderpass is started here
7346 BeginCommandBuffer();
7347
7348 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007349 vk_testing::Buffer dstBuffer;
7350 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007352 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007354 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007355}
7356
Karl Schultz6addd812016-02-02 17:17:23 -07007357TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007358 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07007359 m_errorMonitor->SetDesiredFailureMsg(
7360 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007361 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007362
7363 ASSERT_NO_FATAL_FAILURE(InitState());
7364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007365
7366 // Renderpass is started here
7367 BeginCommandBuffer();
7368
7369 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007370 vk_testing::Buffer dstBuffer;
7371 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007372
Karl Schultz6addd812016-02-02 17:17:23 -07007373 VkDeviceSize dstOffset = 0;
7374 VkDeviceSize dataSize = 1024;
7375 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007376
Karl Schultz6addd812016-02-02 17:17:23 -07007377 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
7378 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007380 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007381}
7382
Karl Schultz6addd812016-02-02 17:17:23 -07007383TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007384 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007385 m_errorMonitor->SetDesiredFailureMsg(
7386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007387 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007388
7389 ASSERT_NO_FATAL_FAILURE(InitState());
7390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007391
7392 // Renderpass is started here
7393 BeginCommandBuffer();
7394
Michael Lentine0a369f62016-02-03 16:51:46 -06007395 VkClearColorValue clear_color;
7396 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7398 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7399 const int32_t tex_width = 32;
7400 const int32_t tex_height = 32;
7401 VkImageCreateInfo image_create_info = {};
7402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7403 image_create_info.pNext = NULL;
7404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7405 image_create_info.format = tex_format;
7406 image_create_info.extent.width = tex_width;
7407 image_create_info.extent.height = tex_height;
7408 image_create_info.extent.depth = 1;
7409 image_create_info.mipLevels = 1;
7410 image_create_info.arrayLayers = 1;
7411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007414
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007415 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007416 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7417 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007418
Karl Schultz6addd812016-02-02 17:17:23 -07007419 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7420 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007421
Karl Schultz6addd812016-02-02 17:17:23 -07007422 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7423 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007424
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007425 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007426}
7427
Karl Schultz6addd812016-02-02 17:17:23 -07007428TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007429 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007430 m_errorMonitor->SetDesiredFailureMsg(
7431 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007432 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007433
7434 ASSERT_NO_FATAL_FAILURE(InitState());
7435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007436
7437 // Renderpass is started here
7438 BeginCommandBuffer();
7439
7440 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007441 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007442 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7443 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7444 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7445 image_create_info.extent.width = 64;
7446 image_create_info.extent.height = 64;
7447 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7448 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007449
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007450 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07007451 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
7452 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007453
Karl Schultz6addd812016-02-02 17:17:23 -07007454 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
7455 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007456
Karl Schultz6addd812016-02-02 17:17:23 -07007457 vkCmdClearDepthStencilImage(
7458 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7459 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
7460 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007461
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007462 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007463}
7464
Karl Schultz6addd812016-02-02 17:17:23 -07007465TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007466 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007467 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007468
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007470 "vkCmdClearAttachments: This call "
7471 "must be issued inside an active "
7472 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007473
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007474 ASSERT_NO_FATAL_FAILURE(InitState());
7475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007476
7477 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007478 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007479 ASSERT_VK_SUCCESS(err);
7480
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007481 VkClearAttachment color_attachment;
7482 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7483 color_attachment.clearValue.color.float32[0] = 0;
7484 color_attachment.clearValue.color.float32[1] = 0;
7485 color_attachment.clearValue.color.float32[2] = 0;
7486 color_attachment.clearValue.color.float32[3] = 0;
7487 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007488 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
7489 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
7490 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007491
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007492 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007493}
7494
Karl Schultz9e66a292016-04-21 15:57:51 -06007495TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7496 // Try to add a buffer memory barrier with no buffer.
7497 m_errorMonitor->SetDesiredFailureMsg(
7498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7499 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
7500
7501 ASSERT_NO_FATAL_FAILURE(InitState());
7502 BeginCommandBuffer();
7503
7504 VkBufferMemoryBarrier buf_barrier = {};
7505 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7506 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7507 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7508 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7509 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7510 buf_barrier.buffer = VK_NULL_HANDLE;
7511 buf_barrier.offset = 0;
7512 buf_barrier.size = VK_WHOLE_SIZE;
7513 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7514 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
7515 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
7516
7517 m_errorMonitor->VerifyFound();
7518}
7519
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007520TEST_F(VkLayerTest, InvalidBarriers) {
7521 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7522
7523 m_errorMonitor->SetDesiredFailureMsg(
7524 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
7525
7526 ASSERT_NO_FATAL_FAILURE(InitState());
7527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7528
7529 VkMemoryBarrier mem_barrier = {};
7530 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7531 mem_barrier.pNext = NULL;
7532 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7533 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7534 BeginCommandBuffer();
7535 // BeginCommandBuffer() starts a render pass
7536 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7537 VK_PIPELINE_STAGE_HOST_BIT,
7538 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
7539 &mem_barrier, 0, nullptr, 0, nullptr);
7540 m_errorMonitor->VerifyFound();
7541
7542 m_errorMonitor->SetDesiredFailureMsg(
7543 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7544 "Image Layout cannot be transitioned to UNDEFINED");
7545 VkImageObj image(m_device);
7546 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
7547 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
7548 ASSERT_TRUE(image.initialized());
7549 VkImageMemoryBarrier img_barrier = {};
7550 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7551 img_barrier.pNext = NULL;
7552 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7553 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7554 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7555 // New layout can't be UNDEFINED
7556 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7557 img_barrier.image = image.handle();
7558 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7559 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7560 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7561 img_barrier.subresourceRange.baseArrayLayer = 0;
7562 img_barrier.subresourceRange.baseMipLevel = 0;
7563 img_barrier.subresourceRange.layerCount = 1;
7564 img_barrier.subresourceRange.levelCount = 1;
7565 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7566 VK_PIPELINE_STAGE_HOST_BIT,
7567 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7568 nullptr, 1, &img_barrier);
7569 m_errorMonitor->VerifyFound();
7570 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7571
7572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7573 "Subresource must have the sum of the "
7574 "baseArrayLayer");
7575 // baseArrayLayer + layerCount must be <= image's arrayLayers
7576 img_barrier.subresourceRange.baseArrayLayer = 1;
7577 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7578 VK_PIPELINE_STAGE_HOST_BIT,
7579 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7580 nullptr, 1, &img_barrier);
7581 m_errorMonitor->VerifyFound();
7582 img_barrier.subresourceRange.baseArrayLayer = 0;
7583
7584 m_errorMonitor->SetDesiredFailureMsg(
7585 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7586 "Subresource must have the sum of the baseMipLevel");
7587 // baseMipLevel + levelCount must be <= image's mipLevels
7588 img_barrier.subresourceRange.baseMipLevel = 1;
7589 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7590 VK_PIPELINE_STAGE_HOST_BIT,
7591 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7592 nullptr, 1, &img_barrier);
7593 m_errorMonitor->VerifyFound();
7594 img_barrier.subresourceRange.baseMipLevel = 0;
7595
7596 m_errorMonitor->SetDesiredFailureMsg(
7597 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7598 "Buffer Barriers cannot be used during a render pass");
7599 vk_testing::Buffer buffer;
7600 buffer.init(*m_device, 256);
7601 VkBufferMemoryBarrier buf_barrier = {};
7602 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7603 buf_barrier.pNext = NULL;
7604 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7605 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7606 buf_barrier.buffer = buffer.handle();
7607 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7608 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7609 buf_barrier.offset = 0;
7610 buf_barrier.size = VK_WHOLE_SIZE;
7611 // Can't send buffer barrier during a render pass
7612 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7613 VK_PIPELINE_STAGE_HOST_BIT,
7614 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7615 &buf_barrier, 0, nullptr);
7616 m_errorMonitor->VerifyFound();
7617 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7618
7619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7620 "which is not less than total size");
7621 buf_barrier.offset = 257;
7622 // Offset greater than total size
7623 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7624 VK_PIPELINE_STAGE_HOST_BIT,
7625 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7626 &buf_barrier, 0, nullptr);
7627 m_errorMonitor->VerifyFound();
7628 buf_barrier.offset = 0;
7629
7630 m_errorMonitor->SetDesiredFailureMsg(
7631 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
7632 buf_barrier.size = 257;
7633 // Size greater than total size
7634 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7635 VK_PIPELINE_STAGE_HOST_BIT,
7636 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
7637 &buf_barrier, 0, nullptr);
7638 m_errorMonitor->VerifyFound();
7639 buf_barrier.size = VK_WHOLE_SIZE;
7640
7641 m_errorMonitor->SetDesiredFailureMsg(
7642 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7643 "Image is a depth and stencil format and thus must "
7644 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
7645 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
7646 VkDepthStencilObj ds_image(m_device);
7647 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
7648 ASSERT_TRUE(ds_image.initialized());
7649 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7650 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
7651 img_barrier.image = ds_image.handle();
7652 // Leave aspectMask at COLOR on purpose
7653 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
7654 VK_PIPELINE_STAGE_HOST_BIT,
7655 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
7656 nullptr, 1, &img_barrier);
7657 m_errorMonitor->VerifyFound();
7658}
7659
Karl Schultz6addd812016-02-02 17:17:23 -07007660TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007661 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007662 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007663
Karl Schultz6addd812016-02-02 17:17:23 -07007664 m_errorMonitor->SetDesiredFailureMsg(
7665 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007666 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
7667
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007668 ASSERT_NO_FATAL_FAILURE(InitState());
7669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007670 uint32_t qfi = 0;
7671 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007672 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7673 buffCI.size = 1024;
7674 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7675 buffCI.queueFamilyIndexCount = 1;
7676 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007677
7678 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007679 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007680 ASSERT_VK_SUCCESS(err);
7681
7682 BeginCommandBuffer();
7683 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007684 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
7685 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007686 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07007687 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
7688 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007690 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007691
Chia-I Wuf7458c52015-10-26 21:10:41 +08007692 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06007693}
7694
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007695TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
7696 // Create an out-of-range queueFamilyIndex
7697 m_errorMonitor->SetDesiredFailureMsg(
7698 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Dustin Gravesde628532016-04-21 16:30:17 -06007699 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
7700 "of the indices specified when the device was created, via the "
7701 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007702
7703 ASSERT_NO_FATAL_FAILURE(InitState());
7704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7705 VkBufferCreateInfo buffCI = {};
7706 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7707 buffCI.size = 1024;
7708 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
7709 buffCI.queueFamilyIndexCount = 1;
7710 // Introduce failure by specifying invalid queue_family_index
7711 uint32_t qfi = 777;
7712 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06007713 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007714
7715 VkBuffer ib;
7716 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
7717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007718 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007719 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07007720}
7721
Karl Schultz6addd812016-02-02 17:17:23 -07007722TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
7723 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
7724 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007725
Karl Schultz6addd812016-02-02 17:17:23 -07007726 m_errorMonitor->SetDesiredFailureMsg(
7727 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007728 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007729
7730 ASSERT_NO_FATAL_FAILURE(InitState());
7731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007732
7733 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007734 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007735 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
7736 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007737
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007738 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06007739}
7740
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007741TEST_F(VkLayerTest, DSUsageBitsErrors) {
7742 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
7743 "that do not have correct usage bits sets.");
7744 VkResult err;
7745
7746 ASSERT_NO_FATAL_FAILURE(InitState());
7747 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7748 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7749 ds_type_count[i].type = VkDescriptorType(i);
7750 ds_type_count[i].descriptorCount = 1;
7751 }
7752 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7753 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7754 ds_pool_ci.pNext = NULL;
7755 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7756 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7757 ds_pool_ci.pPoolSizes = ds_type_count;
7758
7759 VkDescriptorPool ds_pool;
7760 err =
7761 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7762 ASSERT_VK_SUCCESS(err);
7763
7764 // Create 10 layouts where each has a single descriptor of different type
7765 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] =
7766 {};
7767 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7768 dsl_binding[i].binding = 0;
7769 dsl_binding[i].descriptorType = VkDescriptorType(i);
7770 dsl_binding[i].descriptorCount = 1;
7771 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
7772 dsl_binding[i].pImmutableSamplers = NULL;
7773 }
7774
7775 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7776 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7777 ds_layout_ci.pNext = NULL;
7778 ds_layout_ci.bindingCount = 1;
7779 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
7780 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7781 ds_layout_ci.pBindings = dsl_binding + i;
7782 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci,
7783 NULL, ds_layouts + i);
7784 ASSERT_VK_SUCCESS(err);
7785 }
7786 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
7787 VkDescriptorSetAllocateInfo alloc_info = {};
7788 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7789 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
7790 alloc_info.descriptorPool = ds_pool;
7791 alloc_info.pSetLayouts = ds_layouts;
7792 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7793 descriptor_sets);
7794 ASSERT_VK_SUCCESS(err);
7795
7796 // Create a buffer & bufferView to be used for invalid updates
7797 VkBufferCreateInfo buff_ci = {};
7798 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
7799 // This usage is not valid for any descriptor type
7800 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
7801 buff_ci.size = 256;
7802 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7803 VkBuffer buffer;
7804 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
7805 ASSERT_VK_SUCCESS(err);
7806
7807 VkBufferViewCreateInfo buff_view_ci = {};
7808 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
7809 buff_view_ci.buffer = buffer;
7810 buff_view_ci.format = VK_FORMAT_R8_UNORM;
7811 buff_view_ci.range = VK_WHOLE_SIZE;
7812 VkBufferView buff_view;
7813 err =
7814 vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
7815 ASSERT_VK_SUCCESS(err);
7816
7817 // Create an image to be used for invalid updates
7818 VkImageCreateInfo image_ci = {};
7819 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7820 image_ci.imageType = VK_IMAGE_TYPE_2D;
7821 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7822 image_ci.extent.width = 64;
7823 image_ci.extent.height = 64;
7824 image_ci.extent.depth = 1;
7825 image_ci.mipLevels = 1;
7826 image_ci.arrayLayers = 1;
7827 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7828 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7829 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7830 // This usage is not valid for any descriptor type
7831 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
7832 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7833 VkImage image;
7834 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7835 ASSERT_VK_SUCCESS(err);
7836 // Bind memory to image
7837 VkMemoryRequirements mem_reqs;
7838 VkDeviceMemory image_mem;
7839 bool pass;
7840 VkMemoryAllocateInfo mem_alloc = {};
7841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7842 mem_alloc.pNext = NULL;
7843 mem_alloc.allocationSize = 0;
7844 mem_alloc.memoryTypeIndex = 0;
7845 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7846 mem_alloc.allocationSize = mem_reqs.size;
7847 pass =
7848 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
7849 ASSERT_TRUE(pass);
7850 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
7851 ASSERT_VK_SUCCESS(err);
7852 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
7853 ASSERT_VK_SUCCESS(err);
7854 // Now create view for image
7855 VkImageViewCreateInfo image_view_ci = {};
7856 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
7857 image_view_ci.image = image;
7858 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
7859 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
7860 image_view_ci.subresourceRange.layerCount = 1;
7861 image_view_ci.subresourceRange.baseArrayLayer = 0;
7862 image_view_ci.subresourceRange.levelCount = 1;
7863 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7864 VkImageView image_view;
7865 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
7866 &image_view);
7867 ASSERT_VK_SUCCESS(err);
7868
7869 VkDescriptorBufferInfo buff_info = {};
7870 buff_info.buffer = buffer;
7871 VkDescriptorImageInfo img_info = {};
7872 img_info.imageView = image_view;
7873 VkWriteDescriptorSet descriptor_write = {};
7874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7875 descriptor_write.dstBinding = 0;
7876 descriptor_write.descriptorCount = 1;
7877 descriptor_write.pTexelBufferView = &buff_view;
7878 descriptor_write.pBufferInfo = &buff_info;
7879 descriptor_write.pImageInfo = &img_info;
7880
7881 // These error messages align with VkDescriptorType struct
7882 const char *error_msgs[] = {
7883 "", // placeholder, no error for SAMPLER descriptor
7884 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7885 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
7886 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
7887 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
7888 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
7889 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7890 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7891 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
7892 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
7893 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
7894 // Start loop at 1 as SAMPLER desc type has no usage bit error
7895 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
7896 descriptor_write.descriptorType = VkDescriptorType(i);
7897 descriptor_write.dstSet = descriptor_sets[i];
7898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7899 error_msgs[i]);
7900
7901 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0,
7902 NULL);
7903
7904 m_errorMonitor->VerifyFound();
7905 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
7906 }
7907 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
7908 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007909 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06007910 vkDestroyImageView(m_device->device(), image_view, NULL);
7911 vkDestroyBuffer(m_device->device(), buffer, NULL);
7912 vkDestroyBufferView(m_device->device(), buff_view, NULL);
7913 vkFreeDescriptorSets(m_device->device(), ds_pool,
7914 VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
7915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7916}
7917
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06007918TEST_F(VkLayerTest, DSAspectBitsErrors) {
7919 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
7920 // are set, but could expand this test to hit more cases.
7921 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
7922 "that do not have correct aspect bits sets.");
7923 VkResult err;
7924
7925 ASSERT_NO_FATAL_FAILURE(InitState());
7926 VkDescriptorPoolSize ds_type_count = {};
7927 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7928 ds_type_count.descriptorCount = 1;
7929
7930 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7931 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7932 ds_pool_ci.pNext = NULL;
7933 ds_pool_ci.maxSets = 5;
7934 ds_pool_ci.poolSizeCount = 1;
7935 ds_pool_ci.pPoolSizes = &ds_type_count;
7936
7937 VkDescriptorPool ds_pool;
7938 err =
7939 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
7940 ASSERT_VK_SUCCESS(err);
7941
7942 VkDescriptorSetLayoutBinding dsl_binding = {};
7943 dsl_binding.binding = 0;
7944 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7945 dsl_binding.descriptorCount = 1;
7946 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7947 dsl_binding.pImmutableSamplers = NULL;
7948
7949 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7950 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7951 ds_layout_ci.pNext = NULL;
7952 ds_layout_ci.bindingCount = 1;
7953 ds_layout_ci.pBindings = &dsl_binding;
7954 VkDescriptorSetLayout ds_layout;
7955 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7956 &ds_layout);
7957 ASSERT_VK_SUCCESS(err);
7958
7959 VkDescriptorSet descriptor_set = {};
7960 VkDescriptorSetAllocateInfo alloc_info = {};
7961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7962 alloc_info.descriptorSetCount = 1;
7963 alloc_info.descriptorPool = ds_pool;
7964 alloc_info.pSetLayouts = &ds_layout;
7965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
7966 &descriptor_set);
7967 ASSERT_VK_SUCCESS(err);
7968
7969 // Create an image to be used for invalid updates
7970 VkImageCreateInfo image_ci = {};
7971 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7972 image_ci.imageType = VK_IMAGE_TYPE_2D;
7973 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
7974 image_ci.extent.width = 64;
7975 image_ci.extent.height = 64;
7976 image_ci.extent.depth = 1;
7977 image_ci.mipLevels = 1;
7978 image_ci.arrayLayers = 1;
7979 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
7980 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
7981 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
7982 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
7983 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
7984 VkImage image;
7985 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
7986 ASSERT_VK_SUCCESS(err);
7987 // Bind memory to image
7988 VkMemoryRequirements mem_reqs;
7989 VkDeviceMemory image_mem;
7990 bool pass;
7991 VkMemoryAllocateInfo mem_alloc = {};
7992 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
7993 mem_alloc.pNext = NULL;
7994 mem_alloc.allocationSize = 0;
7995 mem_alloc.memoryTypeIndex = 0;
7996 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
7997 mem_alloc.allocationSize = mem_reqs.size;
7998 pass =
7999 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
8000 ASSERT_TRUE(pass);
8001 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8002 ASSERT_VK_SUCCESS(err);
8003 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8004 ASSERT_VK_SUCCESS(err);
8005 // Now create view for image
8006 VkImageViewCreateInfo image_view_ci = {};
8007 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8008 image_view_ci.image = image;
8009 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8010 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8011 image_view_ci.subresourceRange.layerCount = 1;
8012 image_view_ci.subresourceRange.baseArrayLayer = 0;
8013 image_view_ci.subresourceRange.levelCount = 1;
8014 // Setting both depth & stencil aspect bits is illegal for descriptor
8015 image_view_ci.subresourceRange.aspectMask =
8016 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
8017
8018 VkImageView image_view;
8019 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL,
8020 &image_view);
8021 ASSERT_VK_SUCCESS(err);
8022
8023 VkDescriptorImageInfo img_info = {};
8024 img_info.imageView = image_view;
8025 VkWriteDescriptorSet descriptor_write = {};
8026 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8027 descriptor_write.dstBinding = 0;
8028 descriptor_write.descriptorCount = 1;
8029 descriptor_write.pTexelBufferView = NULL;
8030 descriptor_write.pBufferInfo = NULL;
8031 descriptor_write.pImageInfo = &img_info;
8032 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8033 descriptor_write.dstSet = descriptor_set;
8034 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8035 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
8036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8037 error_msg);
8038
8039 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8040
8041 m_errorMonitor->VerifyFound();
8042 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8043 vkDestroyImage(m_device->device(), image, NULL);
8044 vkFreeMemory(m_device->device(), image_mem, NULL);
8045 vkDestroyImageView(m_device->device(), image_view, NULL);
8046 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8047 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8048}
8049
Karl Schultz6addd812016-02-02 17:17:23 -07008050TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008051 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008052 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008053
Karl Schultz6addd812016-02-02 17:17:23 -07008054 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008055 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8056 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8057 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008058
Tobin Ehlis3b780662015-05-28 12:11:26 -06008059 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008060 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008061 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008062 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8063 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008064
8065 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008066 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8067 ds_pool_ci.pNext = NULL;
8068 ds_pool_ci.maxSets = 1;
8069 ds_pool_ci.poolSizeCount = 1;
8070 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008071
Tobin Ehlis3b780662015-05-28 12:11:26 -06008072 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008073 err =
8074 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008075 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008076 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008077 dsl_binding.binding = 0;
8078 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8079 dsl_binding.descriptorCount = 1;
8080 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8081 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008082
Tony Barboureb254902015-07-15 12:50:33 -06008083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8085 ds_layout_ci.pNext = NULL;
8086 ds_layout_ci.bindingCount = 1;
8087 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008088
Tobin Ehlis3b780662015-05-28 12:11:26 -06008089 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008090 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8091 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008092 ASSERT_VK_SUCCESS(err);
8093
8094 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008095 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008097 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008098 alloc_info.descriptorPool = ds_pool;
8099 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8101 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008102 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008103
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008104 VkSamplerCreateInfo sampler_ci = {};
8105 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8106 sampler_ci.pNext = NULL;
8107 sampler_ci.magFilter = VK_FILTER_NEAREST;
8108 sampler_ci.minFilter = VK_FILTER_NEAREST;
8109 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8110 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8111 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8112 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8113 sampler_ci.mipLodBias = 1.0;
8114 sampler_ci.anisotropyEnable = VK_FALSE;
8115 sampler_ci.maxAnisotropy = 1;
8116 sampler_ci.compareEnable = VK_FALSE;
8117 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8118 sampler_ci.minLod = 1.0;
8119 sampler_ci.maxLod = 1.0;
8120 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8121 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8122 VkSampler sampler;
8123 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8124 ASSERT_VK_SUCCESS(err);
8125
8126 VkDescriptorImageInfo info = {};
8127 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008128
8129 VkWriteDescriptorSet descriptor_write;
8130 memset(&descriptor_write, 0, sizeof(descriptor_write));
8131 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008132 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008133 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008134 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008135 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008136 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008137
8138 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8139
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008140 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008141
Chia-I Wuf7458c52015-10-26 21:10:41 +08008142 vkDestroySampler(m_device->device(), sampler, NULL);
8143 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8144 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008145}
8146
Karl Schultz6addd812016-02-02 17:17:23 -07008147TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008148 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008149 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008150
Karl Schultz6addd812016-02-02 17:17:23 -07008151 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008152 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8153 " binding #0 with 1 total descriptors but update of 1 descriptors "
8154 "starting at binding offset of 0 combined with update array element "
8155 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008156
Tobin Ehlis3b780662015-05-28 12:11:26 -06008157 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008158 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008159 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008160 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8161 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008162
8163 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008164 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8165 ds_pool_ci.pNext = NULL;
8166 ds_pool_ci.maxSets = 1;
8167 ds_pool_ci.poolSizeCount = 1;
8168 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008169
Tobin Ehlis3b780662015-05-28 12:11:26 -06008170 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008171 err =
8172 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008173 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008174
Tony Barboureb254902015-07-15 12:50:33 -06008175 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008176 dsl_binding.binding = 0;
8177 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8178 dsl_binding.descriptorCount = 1;
8179 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8180 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008181
8182 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008183 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8184 ds_layout_ci.pNext = NULL;
8185 ds_layout_ci.bindingCount = 1;
8186 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008187
Tobin Ehlis3b780662015-05-28 12:11:26 -06008188 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008189 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8190 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008191 ASSERT_VK_SUCCESS(err);
8192
8193 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008194 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008196 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008197 alloc_info.descriptorPool = ds_pool;
8198 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8200 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008201 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008202
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008203 // Correctly update descriptor to avoid "NOT_UPDATED" error
8204 VkDescriptorBufferInfo buff_info = {};
8205 buff_info.buffer =
8206 VkBuffer(0); // Don't care about buffer handle for this test
8207 buff_info.offset = 0;
8208 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008209
8210 VkWriteDescriptorSet descriptor_write;
8211 memset(&descriptor_write, 0, sizeof(descriptor_write));
8212 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008213 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008214 descriptor_write.dstArrayElement =
8215 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008216 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008217 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8218 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008219
8220 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8221
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008222 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008223
Chia-I Wuf7458c52015-10-26 21:10:41 +08008224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008226}
8227
Karl Schultz6addd812016-02-02 17:17:23 -07008228TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8229 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8230 // index 2
8231 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008232
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8234 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008235
Tobin Ehlis3b780662015-05-28 12:11:26 -06008236 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008237 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008238 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008239 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8240 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008241
8242 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008243 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8244 ds_pool_ci.pNext = NULL;
8245 ds_pool_ci.maxSets = 1;
8246 ds_pool_ci.poolSizeCount = 1;
8247 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008248
Tobin Ehlis3b780662015-05-28 12:11:26 -06008249 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008250 err =
8251 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008252 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008253
Tony Barboureb254902015-07-15 12:50:33 -06008254 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008255 dsl_binding.binding = 0;
8256 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8257 dsl_binding.descriptorCount = 1;
8258 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8259 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008260
8261 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008262 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8263 ds_layout_ci.pNext = NULL;
8264 ds_layout_ci.bindingCount = 1;
8265 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008266 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8268 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008269 ASSERT_VK_SUCCESS(err);
8270
8271 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008272 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008274 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008275 alloc_info.descriptorPool = ds_pool;
8276 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008277 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8278 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008279 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008280
Tony Barboureb254902015-07-15 12:50:33 -06008281 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008282 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8283 sampler_ci.pNext = NULL;
8284 sampler_ci.magFilter = VK_FILTER_NEAREST;
8285 sampler_ci.minFilter = VK_FILTER_NEAREST;
8286 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8287 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8288 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8289 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8290 sampler_ci.mipLodBias = 1.0;
8291 sampler_ci.anisotropyEnable = VK_FALSE;
8292 sampler_ci.maxAnisotropy = 1;
8293 sampler_ci.compareEnable = VK_FALSE;
8294 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8295 sampler_ci.minLod = 1.0;
8296 sampler_ci.maxLod = 1.0;
8297 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8298 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008299
Tobin Ehlis3b780662015-05-28 12:11:26 -06008300 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008301 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008302 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008303
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008304 VkDescriptorImageInfo info = {};
8305 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008306
8307 VkWriteDescriptorSet descriptor_write;
8308 memset(&descriptor_write, 0, sizeof(descriptor_write));
8309 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008310 descriptor_write.dstSet = descriptorSet;
8311 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008312 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008313 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008314 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008315 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008316
8317 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8318
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008319 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008320
Chia-I Wuf7458c52015-10-26 21:10:41 +08008321 vkDestroySampler(m_device->device(), sampler, NULL);
8322 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8323 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008324}
8325
Karl Schultz6addd812016-02-02 17:17:23 -07008326TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8327 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8328 // types
8329 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008330
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis660bcdc2016-05-17 10:39:46 -06008332 ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008333
Tobin Ehlis3b780662015-05-28 12:11:26 -06008334 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008335
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008336 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008337 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8338 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008339
8340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8342 ds_pool_ci.pNext = NULL;
8343 ds_pool_ci.maxSets = 1;
8344 ds_pool_ci.poolSizeCount = 1;
8345 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008346
Tobin Ehlis3b780662015-05-28 12:11:26 -06008347 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008348 err =
8349 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008350 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008351 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008352 dsl_binding.binding = 0;
8353 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8354 dsl_binding.descriptorCount = 1;
8355 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8356 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008357
Tony Barboureb254902015-07-15 12:50:33 -06008358 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008359 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8360 ds_layout_ci.pNext = NULL;
8361 ds_layout_ci.bindingCount = 1;
8362 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008363
Tobin Ehlis3b780662015-05-28 12:11:26 -06008364 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8366 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008367 ASSERT_VK_SUCCESS(err);
8368
8369 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008370 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008371 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008372 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008373 alloc_info.descriptorPool = ds_pool;
8374 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008375 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8376 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008377 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008378
Tony Barboureb254902015-07-15 12:50:33 -06008379 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008380 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8381 sampler_ci.pNext = NULL;
8382 sampler_ci.magFilter = VK_FILTER_NEAREST;
8383 sampler_ci.minFilter = VK_FILTER_NEAREST;
8384 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8385 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8386 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8387 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8388 sampler_ci.mipLodBias = 1.0;
8389 sampler_ci.anisotropyEnable = VK_FALSE;
8390 sampler_ci.maxAnisotropy = 1;
8391 sampler_ci.compareEnable = VK_FALSE;
8392 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8393 sampler_ci.minLod = 1.0;
8394 sampler_ci.maxLod = 1.0;
8395 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8396 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008397 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008398 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008399 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008400
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008401 VkDescriptorImageInfo info = {};
8402 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008403
8404 VkWriteDescriptorSet descriptor_write;
8405 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07008406 descriptor_write.sType =
8407 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008408 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008409 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008410 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008411 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008412 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008413
8414 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8415
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008416 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008417
Chia-I Wuf7458c52015-10-26 21:10:41 +08008418 vkDestroySampler(m_device->device(), sampler, NULL);
8419 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8420 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008421}
8422
Karl Schultz6addd812016-02-02 17:17:23 -07008423TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008424 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07008425 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008426
Karl Schultz6addd812016-02-02 17:17:23 -07008427 m_errorMonitor->SetDesiredFailureMsg(
8428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008429 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008430
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008432 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
8433 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008434 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008435 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
8436 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008437
8438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8440 ds_pool_ci.pNext = NULL;
8441 ds_pool_ci.maxSets = 1;
8442 ds_pool_ci.poolSizeCount = 1;
8443 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008444
8445 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008446 err =
8447 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008448 ASSERT_VK_SUCCESS(err);
8449
8450 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008451 dsl_binding.binding = 0;
8452 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8453 dsl_binding.descriptorCount = 1;
8454 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8455 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008456
8457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8459 ds_layout_ci.pNext = NULL;
8460 ds_layout_ci.bindingCount = 1;
8461 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008462 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8464 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008465 ASSERT_VK_SUCCESS(err);
8466
8467 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008468 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008469 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008470 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008471 alloc_info.descriptorPool = ds_pool;
8472 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008473 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8474 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008475 ASSERT_VK_SUCCESS(err);
8476
Karl Schultz6addd812016-02-02 17:17:23 -07008477 VkSampler sampler =
8478 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008479
8480 VkDescriptorImageInfo descriptor_info;
8481 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8482 descriptor_info.sampler = sampler;
8483
8484 VkWriteDescriptorSet descriptor_write;
8485 memset(&descriptor_write, 0, sizeof(descriptor_write));
8486 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008487 descriptor_write.dstSet = descriptorSet;
8488 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008489 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008490 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8491 descriptor_write.pImageInfo = &descriptor_info;
8492
8493 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8494
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008495 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008496
Chia-I Wuf7458c52015-10-26 21:10:41 +08008497 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8498 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008499}
8500
Karl Schultz6addd812016-02-02 17:17:23 -07008501TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
8502 // Create a single combined Image/Sampler descriptor and send it an invalid
8503 // imageView
8504 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008505
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8507 "Attempted write update to combined "
8508 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06008509 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008510
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008511 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008512 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008513 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8514 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008515
8516 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008517 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8518 ds_pool_ci.pNext = NULL;
8519 ds_pool_ci.maxSets = 1;
8520 ds_pool_ci.poolSizeCount = 1;
8521 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008522
8523 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008524 err =
8525 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008526 ASSERT_VK_SUCCESS(err);
8527
8528 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008529 dsl_binding.binding = 0;
8530 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8531 dsl_binding.descriptorCount = 1;
8532 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8533 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008534
8535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8537 ds_layout_ci.pNext = NULL;
8538 ds_layout_ci.bindingCount = 1;
8539 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008540 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008541 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8542 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008543 ASSERT_VK_SUCCESS(err);
8544
8545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008548 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008549 alloc_info.descriptorPool = ds_pool;
8550 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8552 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008553 ASSERT_VK_SUCCESS(err);
8554
8555 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008556 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8557 sampler_ci.pNext = NULL;
8558 sampler_ci.magFilter = VK_FILTER_NEAREST;
8559 sampler_ci.minFilter = VK_FILTER_NEAREST;
8560 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8561 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8562 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8563 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8564 sampler_ci.mipLodBias = 1.0;
8565 sampler_ci.anisotropyEnable = VK_FALSE;
8566 sampler_ci.maxAnisotropy = 1;
8567 sampler_ci.compareEnable = VK_FALSE;
8568 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8569 sampler_ci.minLod = 1.0;
8570 sampler_ci.maxLod = 1.0;
8571 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8572 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008573
8574 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008575 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008576 ASSERT_VK_SUCCESS(err);
8577
Karl Schultz6addd812016-02-02 17:17:23 -07008578 VkImageView view =
8579 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008580
8581 VkDescriptorImageInfo descriptor_info;
8582 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
8583 descriptor_info.sampler = sampler;
8584 descriptor_info.imageView = view;
8585
8586 VkWriteDescriptorSet descriptor_write;
8587 memset(&descriptor_write, 0, sizeof(descriptor_write));
8588 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008589 descriptor_write.dstSet = descriptorSet;
8590 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008591 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008592 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
8593 descriptor_write.pImageInfo = &descriptor_info;
8594
8595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8596
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008597 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008598
Chia-I Wuf7458c52015-10-26 21:10:41 +08008599 vkDestroySampler(m_device->device(), sampler, NULL);
8600 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06008602}
8603
Karl Schultz6addd812016-02-02 17:17:23 -07008604TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
8605 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
8606 // into the other
8607 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008608
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8610 " binding #1 with type "
8611 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
8612 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008613
Tobin Ehlis04356f92015-10-27 16:35:27 -06008614 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008615 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008616 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008617 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8618 ds_type_count[0].descriptorCount = 1;
8619 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
8620 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008621
8622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8624 ds_pool_ci.pNext = NULL;
8625 ds_pool_ci.maxSets = 1;
8626 ds_pool_ci.poolSizeCount = 2;
8627 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008628
8629 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008630 err =
8631 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008632 ASSERT_VK_SUCCESS(err);
8633 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008634 dsl_binding[0].binding = 0;
8635 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8636 dsl_binding[0].descriptorCount = 1;
8637 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
8638 dsl_binding[0].pImmutableSamplers = NULL;
8639 dsl_binding[1].binding = 1;
8640 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8641 dsl_binding[1].descriptorCount = 1;
8642 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
8643 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008644
8645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8647 ds_layout_ci.pNext = NULL;
8648 ds_layout_ci.bindingCount = 2;
8649 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008650
8651 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8653 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008654 ASSERT_VK_SUCCESS(err);
8655
8656 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008657 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008658 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008659 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008660 alloc_info.descriptorPool = ds_pool;
8661 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008662 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8663 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008664 ASSERT_VK_SUCCESS(err);
8665
8666 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008667 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8668 sampler_ci.pNext = NULL;
8669 sampler_ci.magFilter = VK_FILTER_NEAREST;
8670 sampler_ci.minFilter = VK_FILTER_NEAREST;
8671 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8672 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8673 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8674 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8675 sampler_ci.mipLodBias = 1.0;
8676 sampler_ci.anisotropyEnable = VK_FALSE;
8677 sampler_ci.maxAnisotropy = 1;
8678 sampler_ci.compareEnable = VK_FALSE;
8679 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8680 sampler_ci.minLod = 1.0;
8681 sampler_ci.maxLod = 1.0;
8682 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8683 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008684
8685 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008686 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008687 ASSERT_VK_SUCCESS(err);
8688
8689 VkDescriptorImageInfo info = {};
8690 info.sampler = sampler;
8691
8692 VkWriteDescriptorSet descriptor_write;
8693 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
8694 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008695 descriptor_write.dstSet = descriptorSet;
8696 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08008697 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06008698 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
8699 descriptor_write.pImageInfo = &info;
8700 // This write update should succeed
8701 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8702 // Now perform a copy update that fails due to type mismatch
8703 VkCopyDescriptorSet copy_ds_update;
8704 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8705 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8706 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06008707 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008708 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008709 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08008710 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008711 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008713 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008714 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008715 m_errorMonitor->SetDesiredFailureMsg(
8716 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008717 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06008718 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8719 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8720 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07008721 copy_ds_update.srcBinding =
8722 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008723 copy_ds_update.dstSet = descriptorSet;
8724 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06008725 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06008726 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8727
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008728 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008729
Tobin Ehlis04356f92015-10-27 16:35:27 -06008730 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07008731 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008732 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
8733 "update array offset of 0 and update of "
8734 "5 descriptors oversteps total number "
8735 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008736
Tobin Ehlis04356f92015-10-27 16:35:27 -06008737 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
8738 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
8739 copy_ds_update.srcSet = descriptorSet;
8740 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008741 copy_ds_update.dstSet = descriptorSet;
8742 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008743 copy_ds_update.descriptorCount =
8744 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06008745 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
8746
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008747 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06008748
Chia-I Wuf7458c52015-10-26 21:10:41 +08008749 vkDestroySampler(m_device->device(), sampler, NULL);
8750 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06008752}
8753
Karl Schultz6addd812016-02-02 17:17:23 -07008754TEST_F(VkLayerTest, NumSamplesMismatch) {
8755 // Create CommandBuffer where MSAA samples doesn't match RenderPass
8756 // sampleCount
8757 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008758
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008760 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008761
Tobin Ehlis3b780662015-05-28 12:11:26 -06008762 ASSERT_NO_FATAL_FAILURE(InitState());
8763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008764 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06008765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008767
8768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8770 ds_pool_ci.pNext = NULL;
8771 ds_pool_ci.maxSets = 1;
8772 ds_pool_ci.poolSizeCount = 1;
8773 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008774
Tobin Ehlis3b780662015-05-28 12:11:26 -06008775 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07008776 err =
8777 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008778 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008779
Tony Barboureb254902015-07-15 12:50:33 -06008780 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08008781 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06008782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08008783 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8785 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008786
Tony Barboureb254902015-07-15 12:50:33 -06008787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8789 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008790 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07008791 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008792
Tobin Ehlis3b780662015-05-28 12:11:26 -06008793 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8795 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008796 ASSERT_VK_SUCCESS(err);
8797
8798 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008799 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008800 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008801 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008802 alloc_info.descriptorPool = ds_pool;
8803 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008804 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
8805 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008806 ASSERT_VK_SUCCESS(err);
8807
Tony Barboureb254902015-07-15 12:50:33 -06008808 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008809 pipe_ms_state_ci.sType =
8810 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8811 pipe_ms_state_ci.pNext = NULL;
8812 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8813 pipe_ms_state_ci.sampleShadingEnable = 0;
8814 pipe_ms_state_ci.minSampleShading = 1.0;
8815 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008816
Tony Barboureb254902015-07-15 12:50:33 -06008817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008818 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8819 pipeline_layout_ci.pNext = NULL;
8820 pipeline_layout_ci.setLayoutCount = 1;
8821 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822
8823 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07008824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8825 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008826 ASSERT_VK_SUCCESS(err);
8827
Karl Schultz6addd812016-02-02 17:17:23 -07008828 VkShaderObj vs(m_device, bindStateVertShaderText,
8829 VK_SHADER_STAGE_VERTEX_BIT, this);
8830 VkShaderObj fs(m_device, bindStateFragShaderText,
8831 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06008832 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07008833 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008834 VkPipelineObj pipe(m_device);
8835 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06008836 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06008837 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06008838 pipe.SetMSAA(&pipe_ms_state_ci);
8839 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840
Tony Barbourfe3351b2015-07-28 10:17:20 -06008841 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008842 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8843 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844
Mark Young29927482016-05-04 14:38:51 -06008845 // Render triangle (the error should trigger on the attempt to draw).
8846 Draw(3, 1, 0, 0);
8847
8848 // Finalize recording of the command buffer
8849 EndCommandBuffer();
8850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008852
Chia-I Wuf7458c52015-10-26 21:10:41 +08008853 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8854 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8855 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008856}
Mark Young29927482016-05-04 14:38:51 -06008857
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06008858TEST_F(VkLayerTest, RenderPassIncompatible) {
8859 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
8860 "Initial case is drawing with an active renderpass that's "
8861 "not compatible with the bound PSO's creation renderpass");
8862 VkResult err;
8863
8864 ASSERT_NO_FATAL_FAILURE(InitState());
8865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8866
8867 VkDescriptorSetLayoutBinding dsl_binding = {};
8868 dsl_binding.binding = 0;
8869 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8870 dsl_binding.descriptorCount = 1;
8871 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8872 dsl_binding.pImmutableSamplers = NULL;
8873
8874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8876 ds_layout_ci.pNext = NULL;
8877 ds_layout_ci.bindingCount = 1;
8878 ds_layout_ci.pBindings = &dsl_binding;
8879
8880 VkDescriptorSetLayout ds_layout;
8881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
8882 &ds_layout);
8883 ASSERT_VK_SUCCESS(err);
8884
8885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8887 pipeline_layout_ci.pNext = NULL;
8888 pipeline_layout_ci.setLayoutCount = 1;
8889 pipeline_layout_ci.pSetLayouts = &ds_layout;
8890
8891 VkPipelineLayout pipeline_layout;
8892 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
8893 &pipeline_layout);
8894 ASSERT_VK_SUCCESS(err);
8895
8896 VkShaderObj vs(m_device, bindStateVertShaderText,
8897 VK_SHADER_STAGE_VERTEX_BIT, this);
8898 VkShaderObj fs(m_device, bindStateFragShaderText,
8899 VK_SHADER_STAGE_FRAGMENT_BIT,
8900 this); // We shouldn't need a fragment shader
8901 // but add it to be able to run on more devices
8902 // Create a renderpass that will be incompatible with default renderpass
8903 VkAttachmentReference attach = {};
8904 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
8905 VkAttachmentReference color_att = {};
8906 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8907 VkSubpassDescription subpass = {};
8908 subpass.inputAttachmentCount = 1;
8909 subpass.pInputAttachments = &attach;
8910 subpass.colorAttachmentCount = 1;
8911 subpass.pColorAttachments = &color_att;
8912 VkRenderPassCreateInfo rpci = {};
8913 rpci.subpassCount = 1;
8914 rpci.pSubpasses = &subpass;
8915 rpci.attachmentCount = 1;
8916 VkAttachmentDescription attach_desc = {};
8917 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
8918 // Format incompatible with PSO RP color attach format RGBA8_UNORM
8919 attach_desc.format = VK_FORMAT_UNDEFINED;
8920 rpci.pAttachments = &attach_desc;
8921 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8922 VkRenderPass rp;
8923 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8924 VkPipelineObj pipe(m_device);
8925 pipe.AddShader(&vs);
8926 pipe.AddShader(&fs);
8927 pipe.AddColorAttachment();
8928 VkViewport view_port = {};
8929 m_viewports.push_back(view_port);
8930 pipe.SetViewport(m_viewports);
8931 VkRect2D rect = {};
8932 m_scissors.push_back(rect);
8933 pipe.SetScissor(m_scissors);
8934 pipe.CreateVKPipeline(pipeline_layout, renderPass());
8935
8936 VkCommandBufferInheritanceInfo cbii = {};
8937 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8938 cbii.renderPass = rp;
8939 cbii.subpass = 0;
8940 VkCommandBufferBeginInfo cbbi = {};
8941 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8942 cbbi.pInheritanceInfo = &cbii;
8943 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
8944 VkRenderPassBeginInfo rpbi = {};
8945 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8946 rpbi.framebuffer = m_framebuffer;
8947 rpbi.renderPass = rp;
8948 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi,
8949 VK_SUBPASS_CONTENTS_INLINE);
8950 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8951 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
8952
8953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8954 " is incompatible w/ gfx pipeline ");
8955 // Render triangle (the error should trigger on the attempt to draw).
8956 Draw(3, 1, 0, 0);
8957
8958 // Finalize recording of the command buffer
8959 EndCommandBuffer();
8960
8961 m_errorMonitor->VerifyFound();
8962
8963 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8964 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8965 vkDestroyRenderPass(m_device->device(), rp, NULL);
8966}
8967
Mark Youngc89c6312016-03-31 16:03:20 -06008968TEST_F(VkLayerTest, NumBlendAttachMismatch) {
8969 // Create Pipeline where the number of blend attachments doesn't match the
8970 // number of color attachments. In this case, we don't add any color
8971 // blend attachments even though we have a color attachment.
8972 VkResult err;
8973
8974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06008975 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06008976
8977 ASSERT_NO_FATAL_FAILURE(InitState());
8978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8979 VkDescriptorPoolSize ds_type_count = {};
8980 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8981 ds_type_count.descriptorCount = 1;
8982
8983 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8984 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8985 ds_pool_ci.pNext = NULL;
8986 ds_pool_ci.maxSets = 1;
8987 ds_pool_ci.poolSizeCount = 1;
8988 ds_pool_ci.pPoolSizes = &ds_type_count;
8989
8990 VkDescriptorPool ds_pool;
8991 err =
8992 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
8993 ASSERT_VK_SUCCESS(err);
8994
8995 VkDescriptorSetLayoutBinding dsl_binding = {};
8996 dsl_binding.binding = 0;
8997 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8998 dsl_binding.descriptorCount = 1;
8999 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9000 dsl_binding.pImmutableSamplers = NULL;
9001
9002 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9003 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9004 ds_layout_ci.pNext = NULL;
9005 ds_layout_ci.bindingCount = 1;
9006 ds_layout_ci.pBindings = &dsl_binding;
9007
9008 VkDescriptorSetLayout ds_layout;
9009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9010 &ds_layout);
9011 ASSERT_VK_SUCCESS(err);
9012
9013 VkDescriptorSet descriptorSet;
9014 VkDescriptorSetAllocateInfo alloc_info = {};
9015 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9016 alloc_info.descriptorSetCount = 1;
9017 alloc_info.descriptorPool = ds_pool;
9018 alloc_info.pSetLayouts = &ds_layout;
9019 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9020 &descriptorSet);
9021 ASSERT_VK_SUCCESS(err);
9022
9023 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
9024 pipe_ms_state_ci.sType =
9025 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9026 pipe_ms_state_ci.pNext = NULL;
9027 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9028 pipe_ms_state_ci.sampleShadingEnable = 0;
9029 pipe_ms_state_ci.minSampleShading = 1.0;
9030 pipe_ms_state_ci.pSampleMask = NULL;
9031
9032 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9033 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9034 pipeline_layout_ci.pNext = NULL;
9035 pipeline_layout_ci.setLayoutCount = 1;
9036 pipeline_layout_ci.pSetLayouts = &ds_layout;
9037
9038 VkPipelineLayout pipeline_layout;
9039 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9040 &pipeline_layout);
9041 ASSERT_VK_SUCCESS(err);
9042
9043 VkShaderObj vs(m_device, bindStateVertShaderText,
9044 VK_SHADER_STAGE_VERTEX_BIT, this);
9045 VkShaderObj fs(m_device, bindStateFragShaderText,
9046 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009047 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06009048 // but add it to be able to run on more devices
9049 VkPipelineObj pipe(m_device);
9050 pipe.AddShader(&vs);
9051 pipe.AddShader(&fs);
9052 pipe.SetMSAA(&pipe_ms_state_ci);
9053 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9054
9055 BeginCommandBuffer();
9056 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9057 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
9058
Mark Young29927482016-05-04 14:38:51 -06009059 // Render triangle (the error should trigger on the attempt to draw).
9060 Draw(3, 1, 0, 0);
9061
9062 // Finalize recording of the command buffer
9063 EndCommandBuffer();
9064
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009065 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009066
9067 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9070}
Mark Young29927482016-05-04 14:38:51 -06009071
Mark Muellerd4914412016-06-13 17:52:06 -06009072TEST_F(VkLayerTest, MissingClearAttachment) {
9073 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9074 "structure passed to vkCmdClearAttachments");
9075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9076 "vkCmdClearAttachments() attachment index 1 not found in attachment "
9077 "reference array of active subpass 0");
9078
9079 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9080 m_errorMonitor->VerifyFound();
9081}
9082
Karl Schultz6addd812016-02-02 17:17:23 -07009083TEST_F(VkLayerTest, ClearCmdNoDraw) {
9084 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9085 // to issuing a Draw
9086 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009087
Karl Schultz6addd812016-02-02 17:17:23 -07009088 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07009089 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009090 "vkCmdClearAttachments() issued on CB object ");
9091
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009092 ASSERT_NO_FATAL_FAILURE(InitState());
9093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009094
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009095 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009096 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9097 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009098
9099 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009100 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9101 ds_pool_ci.pNext = NULL;
9102 ds_pool_ci.maxSets = 1;
9103 ds_pool_ci.poolSizeCount = 1;
9104 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009105
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009106 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009107 err =
9108 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009109 ASSERT_VK_SUCCESS(err);
9110
Tony Barboureb254902015-07-15 12:50:33 -06009111 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009112 dsl_binding.binding = 0;
9113 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9114 dsl_binding.descriptorCount = 1;
9115 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9116 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009117
Tony Barboureb254902015-07-15 12:50:33 -06009118 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009119 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9120 ds_layout_ci.pNext = NULL;
9121 ds_layout_ci.bindingCount = 1;
9122 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009123
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009124 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9126 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009127 ASSERT_VK_SUCCESS(err);
9128
9129 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009130 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009131 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009132 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009133 alloc_info.descriptorPool = ds_pool;
9134 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9136 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009137 ASSERT_VK_SUCCESS(err);
9138
Tony Barboureb254902015-07-15 12:50:33 -06009139 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009140 pipe_ms_state_ci.sType =
9141 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9142 pipe_ms_state_ci.pNext = NULL;
9143 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9144 pipe_ms_state_ci.sampleShadingEnable = 0;
9145 pipe_ms_state_ci.minSampleShading = 1.0;
9146 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009147
Tony Barboureb254902015-07-15 12:50:33 -06009148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9150 pipeline_layout_ci.pNext = NULL;
9151 pipeline_layout_ci.setLayoutCount = 1;
9152 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009153
9154 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9156 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009157 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009158
Karl Schultz6addd812016-02-02 17:17:23 -07009159 VkShaderObj vs(m_device, bindStateVertShaderText,
9160 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009161 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009162 // on more devices
9163 VkShaderObj fs(m_device, bindStateFragShaderText,
9164 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009165
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009166 VkPipelineObj pipe(m_device);
9167 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009168 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009169 pipe.SetMSAA(&pipe_ms_state_ci);
9170 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009171
9172 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009173
Karl Schultz6addd812016-02-02 17:17:23 -07009174 // Main thing we care about for this test is that the VkImage obj we're
9175 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009176 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009177 VkClearAttachment color_attachment;
9178 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9179 color_attachment.clearValue.color.float32[0] = 1.0;
9180 color_attachment.clearValue.color.float32[1] = 1.0;
9181 color_attachment.clearValue.color.float32[2] = 1.0;
9182 color_attachment.clearValue.color.float32[3] = 1.0;
9183 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009184 VkClearRect clear_rect = {
9185 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009186
Karl Schultz6addd812016-02-02 17:17:23 -07009187 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
9188 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009189
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009190 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009191
Chia-I Wuf7458c52015-10-26 21:10:41 +08009192 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9193 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9194 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009195}
9196
Karl Schultz6addd812016-02-02 17:17:23 -07009197TEST_F(VkLayerTest, VtxBufferBadIndex) {
9198 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009199
Karl Schultz6addd812016-02-02 17:17:23 -07009200 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009201 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07009202 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009203
Tobin Ehlis502480b2015-06-24 15:53:07 -06009204 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009205 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009207
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009208 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009209 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9210 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009211
9212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9214 ds_pool_ci.pNext = NULL;
9215 ds_pool_ci.maxSets = 1;
9216 ds_pool_ci.poolSizeCount = 1;
9217 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009218
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009219 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009220 err =
9221 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009222 ASSERT_VK_SUCCESS(err);
9223
Tony Barboureb254902015-07-15 12:50:33 -06009224 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009225 dsl_binding.binding = 0;
9226 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9227 dsl_binding.descriptorCount = 1;
9228 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9229 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009230
Tony Barboureb254902015-07-15 12:50:33 -06009231 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009232 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9233 ds_layout_ci.pNext = NULL;
9234 ds_layout_ci.bindingCount = 1;
9235 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009236
Tobin Ehlis502480b2015-06-24 15:53:07 -06009237 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009238 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9239 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009240 ASSERT_VK_SUCCESS(err);
9241
9242 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009243 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009244 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009245 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009246 alloc_info.descriptorPool = ds_pool;
9247 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9249 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009250 ASSERT_VK_SUCCESS(err);
9251
Tony Barboureb254902015-07-15 12:50:33 -06009252 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009253 pipe_ms_state_ci.sType =
9254 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9255 pipe_ms_state_ci.pNext = NULL;
9256 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9257 pipe_ms_state_ci.sampleShadingEnable = 0;
9258 pipe_ms_state_ci.minSampleShading = 1.0;
9259 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009260
Tony Barboureb254902015-07-15 12:50:33 -06009261 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009262 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9263 pipeline_layout_ci.pNext = NULL;
9264 pipeline_layout_ci.setLayoutCount = 1;
9265 pipeline_layout_ci.pSetLayouts = &ds_layout;
9266 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009267
Karl Schultz6addd812016-02-02 17:17:23 -07009268 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
9269 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009270 ASSERT_VK_SUCCESS(err);
9271
Karl Schultz6addd812016-02-02 17:17:23 -07009272 VkShaderObj vs(m_device, bindStateVertShaderText,
9273 VK_SHADER_STAGE_VERTEX_BIT, this);
9274 VkShaderObj fs(m_device, bindStateFragShaderText,
9275 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06009276 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07009277 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009278 VkPipelineObj pipe(m_device);
9279 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009280 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009281 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009282 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009283 pipe.SetViewport(m_viewports);
9284 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009285 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009286
9287 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9289 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009290 // Don't care about actual data, just need to get to draw to flag error
9291 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07009292 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
9293 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009294 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009295 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009297 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009298
Chia-I Wuf7458c52015-10-26 21:10:41 +08009299 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009302}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009303// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
9304TEST_F(VkLayerTest, InvalidImageLayout) {
9305 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
9306 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
9307 "images in the wrong layout when they're copied or transitioned.");
9308 // 3 in ValidateCmdBufImageLayouts
9309 // * -1 Attempt to submit cmd buf w/ deleted image
9310 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
9311 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
9312 m_errorMonitor->SetDesiredFailureMsg(
9313 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9314 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
9315
9316 ASSERT_NO_FATAL_FAILURE(InitState());
9317 // Create src & dst images to use for copy operations
9318 VkImage src_image;
9319 VkImage dst_image;
9320
9321 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9322 const int32_t tex_width = 32;
9323 const int32_t tex_height = 32;
9324
9325 VkImageCreateInfo image_create_info = {};
9326 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9327 image_create_info.pNext = NULL;
9328 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9329 image_create_info.format = tex_format;
9330 image_create_info.extent.width = tex_width;
9331 image_create_info.extent.height = tex_height;
9332 image_create_info.extent.depth = 1;
9333 image_create_info.mipLevels = 1;
9334 image_create_info.arrayLayers = 4;
9335 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9336 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9337 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9338 image_create_info.flags = 0;
9339
9340 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
9341 ASSERT_VK_SUCCESS(err);
9342 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
9343 ASSERT_VK_SUCCESS(err);
9344
9345 BeginCommandBuffer();
9346 VkImageCopy copyRegion;
9347 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9348 copyRegion.srcSubresource.mipLevel = 0;
9349 copyRegion.srcSubresource.baseArrayLayer = 0;
9350 copyRegion.srcSubresource.layerCount = 1;
9351 copyRegion.srcOffset.x = 0;
9352 copyRegion.srcOffset.y = 0;
9353 copyRegion.srcOffset.z = 0;
9354 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9355 copyRegion.dstSubresource.mipLevel = 0;
9356 copyRegion.dstSubresource.baseArrayLayer = 0;
9357 copyRegion.dstSubresource.layerCount = 1;
9358 copyRegion.dstOffset.x = 0;
9359 copyRegion.dstOffset.y = 0;
9360 copyRegion.dstOffset.z = 0;
9361 copyRegion.extent.width = 1;
9362 copyRegion.extent.height = 1;
9363 copyRegion.extent.depth = 1;
9364 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9365 m_errorMonitor->VerifyFound();
9366 // Now cause error due to src image layout changing
9367 m_errorMonitor->SetDesiredFailureMsg(
9368 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9369 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9370 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9371 m_errorMonitor->VerifyFound();
9372 // Final src error is due to bad layout type
9373 m_errorMonitor->SetDesiredFailureMsg(
9374 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9375 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
9376 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9377 m_errorMonitor->VerifyFound();
9378 // Now verify same checks for dst
9379 m_errorMonitor->SetDesiredFailureMsg(
9380 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9381 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
9382 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9383 m_errorMonitor->VerifyFound();
9384 // Now cause error due to src image layout changing
9385 m_errorMonitor->SetDesiredFailureMsg(
9386 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9387 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
9388 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9389 m_errorMonitor->VerifyFound();
9390 m_errorMonitor->SetDesiredFailureMsg(
9391 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9392 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
9393 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
9394 m_errorMonitor->VerifyFound();
9395 // Now cause error due to bad image layout transition in PipelineBarrier
9396 VkImageMemoryBarrier image_barrier[1] = {};
9397 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9398 image_barrier[0].image = src_image;
9399 image_barrier[0].subresourceRange.layerCount = 2;
9400 image_barrier[0].subresourceRange.levelCount = 2;
9401 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9402 m_errorMonitor->SetDesiredFailureMsg(
9403 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9404 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
9405 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
9406 m_errorMonitor->VerifyFound();
9407
9408 // Finally some layout errors at RenderPass create time
9409 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
9410 VkAttachmentReference attach = {};
9411 // perf warning for GENERAL layout w/ non-DS input attachment
9412 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9413 VkSubpassDescription subpass = {};
9414 subpass.inputAttachmentCount = 1;
9415 subpass.pInputAttachments = &attach;
9416 VkRenderPassCreateInfo rpci = {};
9417 rpci.subpassCount = 1;
9418 rpci.pSubpasses = &subpass;
9419 rpci.attachmentCount = 1;
9420 VkAttachmentDescription attach_desc = {};
9421 attach_desc.format = VK_FORMAT_UNDEFINED;
9422 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06009423 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009424 VkRenderPass rp;
9425 m_errorMonitor->SetDesiredFailureMsg(
9426 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9427 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
9428 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9429 m_errorMonitor->VerifyFound();
9430 // error w/ non-general layout
9431 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9432
9433 m_errorMonitor->SetDesiredFailureMsg(
9434 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9435 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
9436 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9437 m_errorMonitor->VerifyFound();
9438 subpass.inputAttachmentCount = 0;
9439 subpass.colorAttachmentCount = 1;
9440 subpass.pColorAttachments = &attach;
9441 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9442 // perf warning for GENERAL layout on color attachment
9443 m_errorMonitor->SetDesiredFailureMsg(
9444 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9445 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
9446 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9447 m_errorMonitor->VerifyFound();
9448 // error w/ non-color opt or GENERAL layout for color attachment
9449 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9450 m_errorMonitor->SetDesiredFailureMsg(
9451 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9452 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
9453 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9454 m_errorMonitor->VerifyFound();
9455 subpass.colorAttachmentCount = 0;
9456 subpass.pDepthStencilAttachment = &attach;
9457 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9458 // perf warning for GENERAL layout on DS attachment
9459 m_errorMonitor->SetDesiredFailureMsg(
9460 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9461 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
9462 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9463 m_errorMonitor->VerifyFound();
9464 // error w/ non-ds opt or GENERAL layout for color attachment
9465 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
9466 m_errorMonitor->SetDesiredFailureMsg(
9467 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9468 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
9469 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9470 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06009471 // For this error we need a valid renderpass so create default one
9472 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9473 attach.attachment = 0;
9474 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
9475 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
9476 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
9477 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
9478 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
9479 // Can't do a CLEAR load on READ_ONLY initialLayout
9480 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9481 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
9482 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9484 " with invalid first layout "
9485 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
9486 "ONLY_OPTIMAL");
9487 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9488 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06009489
9490 vkDestroyImage(m_device->device(), src_image, NULL);
9491 vkDestroyImage(m_device->device(), dst_image, NULL);
9492}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009493#endif // DRAW_STATE_TESTS
9494
Tobin Ehlis0788f522015-05-26 16:11:58 -06009495#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06009496#if GTEST_IS_THREADSAFE
9497struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009498 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009499 VkEvent event;
9500 bool bailout;
9501};
9502
Karl Schultz6addd812016-02-02 17:17:23 -07009503extern "C" void *AddToCommandBuffer(void *arg) {
9504 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009505
Karl Schultz6addd812016-02-02 17:17:23 -07009506 for (int i = 0; i < 10000; i++) {
9507 vkCmdSetEvent(data->commandBuffer, data->event,
9508 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009509 if (data->bailout) {
9510 break;
9511 }
9512 }
9513 return NULL;
9514}
9515
Karl Schultz6addd812016-02-02 17:17:23 -07009516TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009517 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009518
Karl Schultz6addd812016-02-02 17:17:23 -07009519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9520 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009521
Mike Stroyanaccf7692015-05-12 16:00:45 -06009522 ASSERT_NO_FATAL_FAILURE(InitState());
9523 ASSERT_NO_FATAL_FAILURE(InitViewport());
9524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9525
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009526 // Calls AllocateCommandBuffers
9527 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009528
9529 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009530 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009531
9532 VkEventCreateInfo event_info;
9533 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06009534 VkResult err;
9535
9536 memset(&event_info, 0, sizeof(event_info));
9537 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9538
Chia-I Wuf7458c52015-10-26 21:10:41 +08009539 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009540 ASSERT_VK_SUCCESS(err);
9541
Mike Stroyanaccf7692015-05-12 16:00:45 -06009542 err = vkResetEvent(device(), event);
9543 ASSERT_VK_SUCCESS(err);
9544
9545 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009546 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009547 data.event = event;
9548 data.bailout = false;
9549 m_errorMonitor->SetBailout(&data.bailout);
9550 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009551 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009552 // Add many entries to command buffer from this thread at the same time.
9553 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06009554
Mike Stroyan4268d1f2015-07-13 14:45:35 -06009555 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009556 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009557
Mike Stroyan10b8cb72016-01-22 15:22:03 -07009558 m_errorMonitor->SetBailout(NULL);
9559
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009560 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06009561
Chia-I Wuf7458c52015-10-26 21:10:41 +08009562 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06009563}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009564#endif // GTEST_IS_THREADSAFE
9565#endif // THREADING_TESTS
9566
Chris Forbes9f7ff632015-05-25 11:13:08 +12009567#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07009568TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009570 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009571
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009572 ASSERT_NO_FATAL_FAILURE(InitState());
9573 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9574
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009575 VkShaderModule module;
9576 VkShaderModuleCreateInfo moduleCreateInfo;
9577 struct icd_spv_header spv;
9578
9579 spv.magic = ICD_SPV_MAGIC;
9580 spv.version = ICD_SPV_VERSION;
9581 spv.gen_magic = 0;
9582
9583 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9584 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009585 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009586 moduleCreateInfo.codeSize = 4;
9587 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009588 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009589
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009590 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009591}
9592
Karl Schultz6addd812016-02-02 17:17:23 -07009593TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009595 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009596
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009597 ASSERT_NO_FATAL_FAILURE(InitState());
9598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9599
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009600 VkShaderModule module;
9601 VkShaderModuleCreateInfo moduleCreateInfo;
9602 struct icd_spv_header spv;
9603
9604 spv.magic = ~ICD_SPV_MAGIC;
9605 spv.version = ICD_SPV_VERSION;
9606 spv.gen_magic = 0;
9607
9608 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9609 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07009610 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009611 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9612 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009613 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009614
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009615 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009616}
9617
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009618#if 0
9619// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07009620TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009622 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009623
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009624 ASSERT_NO_FATAL_FAILURE(InitState());
9625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9626
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009627 VkShaderModule module;
9628 VkShaderModuleCreateInfo moduleCreateInfo;
9629 struct icd_spv_header spv;
9630
9631 spv.magic = ICD_SPV_MAGIC;
9632 spv.version = ~ICD_SPV_VERSION;
9633 spv.gen_magic = 0;
9634
9635 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
9636 moduleCreateInfo.pNext = NULL;
9637
Karl Schultz6addd812016-02-02 17:17:23 -07009638 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009639 moduleCreateInfo.codeSize = sizeof(spv) + 10;
9640 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009641 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009643 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009644}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12009645#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06009646
Karl Schultz6addd812016-02-02 17:17:23 -07009647TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009649 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009650
Chris Forbes9f7ff632015-05-25 11:13:08 +12009651 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009653
9654 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009655 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009656 "\n"
9657 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009658 "out gl_PerVertex {\n"
9659 " vec4 gl_Position;\n"
9660 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009661 "void main(){\n"
9662 " gl_Position = vec4(1);\n"
9663 " x = 0;\n"
9664 "}\n";
9665 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009666 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12009667 "\n"
9668 "layout(location=0) out vec4 color;\n"
9669 "void main(){\n"
9670 " color = vec4(1);\n"
9671 "}\n";
9672
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009673 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9674 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009675
9676 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009677 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009678 pipe.AddShader(&vs);
9679 pipe.AddShader(&fs);
9680
Chris Forbes9f7ff632015-05-25 11:13:08 +12009681 VkDescriptorSetObj descriptorSet(m_device);
9682 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12009684
Tony Barbour5781e8f2015-08-04 16:23:11 -06009685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12009686
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009687 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12009688}
Chris Forbes9f7ff632015-05-25 11:13:08 +12009689
Karl Schultz6addd812016-02-02 17:17:23 -07009690TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009692 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009693
Chris Forbes59cb88d2015-05-25 11:13:13 +12009694 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009696
9697 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009698 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009699 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07009700 "out gl_PerVertex {\n"
9701 " vec4 gl_Position;\n"
9702 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009703 "void main(){\n"
9704 " gl_Position = vec4(1);\n"
9705 "}\n";
9706 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009707 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12009708 "\n"
9709 "layout(location=0) in float x;\n"
9710 "layout(location=0) out vec4 color;\n"
9711 "void main(){\n"
9712 " color = vec4(x);\n"
9713 "}\n";
9714
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009717
9718 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009719 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009720 pipe.AddShader(&vs);
9721 pipe.AddShader(&fs);
9722
Chris Forbes59cb88d2015-05-25 11:13:13 +12009723 VkDescriptorSetObj descriptorSet(m_device);
9724 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12009726
Tony Barbour5781e8f2015-08-04 16:23:11 -06009727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12009728
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009729 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12009730}
9731
Karl Schultz6addd812016-02-02 17:17:23 -07009732TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009734 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009735
9736 ASSERT_NO_FATAL_FAILURE(InitState());
9737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9738
9739 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009740 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009741 "\n"
9742 "out gl_PerVertex {\n"
9743 " vec4 gl_Position;\n"
9744 "};\n"
9745 "void main(){\n"
9746 " gl_Position = vec4(1);\n"
9747 "}\n";
9748 char const *fsSource =
9749 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009750 "\n"
9751 "in block { layout(location=0) float x; } ins;\n"
9752 "layout(location=0) out vec4 color;\n"
9753 "void main(){\n"
9754 " color = vec4(ins.x);\n"
9755 "}\n";
9756
9757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9759
9760 VkPipelineObj pipe(m_device);
9761 pipe.AddColorAttachment();
9762 pipe.AddShader(&vs);
9763 pipe.AddShader(&fs);
9764
9765 VkDescriptorSetObj descriptorSet(m_device);
9766 descriptorSet.AppendDummy();
9767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9768
9769 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009771 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009772}
9773
Karl Schultz6addd812016-02-02 17:17:23 -07009774TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13009775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13009776 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07009777 "output arr[2] of float32' vs 'ptr to "
9778 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13009779
9780 ASSERT_NO_FATAL_FAILURE(InitState());
9781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9782
9783 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009784 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009785 "\n"
9786 "layout(location=0) out float x[2];\n"
9787 "out gl_PerVertex {\n"
9788 " vec4 gl_Position;\n"
9789 "};\n"
9790 "void main(){\n"
9791 " x[0] = 0; x[1] = 0;\n"
9792 " gl_Position = vec4(1);\n"
9793 "}\n";
9794 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009795 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13009796 "\n"
9797 "layout(location=0) in float x[3];\n"
9798 "layout(location=0) out vec4 color;\n"
9799 "void main(){\n"
9800 " color = vec4(x[0] + x[1] + x[2]);\n"
9801 "}\n";
9802
9803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9805
9806 VkPipelineObj pipe(m_device);
9807 pipe.AddColorAttachment();
9808 pipe.AddShader(&vs);
9809 pipe.AddShader(&fs);
9810
9811 VkDescriptorSetObj descriptorSet(m_device);
9812 descriptorSet.AppendDummy();
9813 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9814
9815 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009817 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13009818}
9819
Karl Schultz6addd812016-02-02 17:17:23 -07009820TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07009821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009822 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009823
Chris Forbesb56af562015-05-25 11:13:17 +12009824 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06009825 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12009826
9827 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009828 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009829 "\n"
9830 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07009831 "out gl_PerVertex {\n"
9832 " vec4 gl_Position;\n"
9833 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009834 "void main(){\n"
9835 " x = 0;\n"
9836 " gl_Position = vec4(1);\n"
9837 "}\n";
9838 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12009839 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12009840 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009841 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12009842 "layout(location=0) out vec4 color;\n"
9843 "void main(){\n"
9844 " color = vec4(x);\n"
9845 "}\n";
9846
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06009847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12009849
9850 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08009851 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12009852 pipe.AddShader(&vs);
9853 pipe.AddShader(&fs);
9854
Chris Forbesb56af562015-05-25 11:13:17 +12009855 VkDescriptorSetObj descriptorSet(m_device);
9856 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12009858
Tony Barbour5781e8f2015-08-04 16:23:11 -06009859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12009860
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009861 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12009862}
9863
Karl Schultz6addd812016-02-02 17:17:23 -07009864TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13009865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009866 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13009867
9868 ASSERT_NO_FATAL_FAILURE(InitState());
9869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9870
9871 char const *vsSource =
9872 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009873 "\n"
9874 "out block { layout(location=0) int x; } outs;\n"
9875 "out gl_PerVertex {\n"
9876 " vec4 gl_Position;\n"
9877 "};\n"
9878 "void main(){\n"
9879 " outs.x = 0;\n"
9880 " gl_Position = vec4(1);\n"
9881 "}\n";
9882 char const *fsSource =
9883 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13009884 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07009885 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13009886 "layout(location=0) out vec4 color;\n"
9887 "void main(){\n"
9888 " color = vec4(ins.x);\n"
9889 "}\n";
9890
9891 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9892 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9893
9894 VkPipelineObj pipe(m_device);
9895 pipe.AddColorAttachment();
9896 pipe.AddShader(&vs);
9897 pipe.AddShader(&fs);
9898
9899 VkDescriptorSetObj descriptorSet(m_device);
9900 descriptorSet.AppendDummy();
9901 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9902
9903 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9904
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009905 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009906}
9907
9908TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
9909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9910 "location 0.0 which is not written by vertex shader");
9911
9912 ASSERT_NO_FATAL_FAILURE(InitState());
9913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9914
9915 char const *vsSource =
9916 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009917 "\n"
9918 "out block { layout(location=1) float x; } outs;\n"
9919 "out gl_PerVertex {\n"
9920 " vec4 gl_Position;\n"
9921 "};\n"
9922 "void main(){\n"
9923 " outs.x = 0;\n"
9924 " gl_Position = vec4(1);\n"
9925 "}\n";
9926 char const *fsSource =
9927 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009928 "\n"
9929 "in block { layout(location=0) float x; } ins;\n"
9930 "layout(location=0) out vec4 color;\n"
9931 "void main(){\n"
9932 " color = vec4(ins.x);\n"
9933 "}\n";
9934
9935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9937
9938 VkPipelineObj pipe(m_device);
9939 pipe.AddColorAttachment();
9940 pipe.AddShader(&vs);
9941 pipe.AddShader(&fs);
9942
9943 VkDescriptorSetObj descriptorSet(m_device);
9944 descriptorSet.AppendDummy();
9945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9946
9947 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9948
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009949 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13009950}
9951
9952TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
9953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9954 "location 0.1 which is not written by vertex shader");
9955
9956 ASSERT_NO_FATAL_FAILURE(InitState());
9957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9958
9959 char const *vsSource =
9960 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009961 "\n"
9962 "out block { layout(location=0, component=0) float x; } outs;\n"
9963 "out gl_PerVertex {\n"
9964 " vec4 gl_Position;\n"
9965 "};\n"
9966 "void main(){\n"
9967 " outs.x = 0;\n"
9968 " gl_Position = vec4(1);\n"
9969 "}\n";
9970 char const *fsSource =
9971 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13009972 "\n"
9973 "in block { layout(location=0, component=1) float x; } ins;\n"
9974 "layout(location=0) out vec4 color;\n"
9975 "void main(){\n"
9976 " color = vec4(ins.x);\n"
9977 "}\n";
9978
9979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
9980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9981
9982 VkPipelineObj pipe(m_device);
9983 pipe.AddColorAttachment();
9984 pipe.AddShader(&vs);
9985 pipe.AddShader(&fs);
9986
9987 VkDescriptorSetObj descriptorSet(m_device);
9988 descriptorSet.AppendDummy();
9989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
9990
9991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
9992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009993 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13009994}
9995
Karl Schultz6addd812016-02-02 17:17:23 -07009996TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07009997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07009998 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009999
Chris Forbesde136e02015-05-25 11:13:28 +120010000 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120010002
10003 VkVertexInputBindingDescription input_binding;
10004 memset(&input_binding, 0, sizeof(input_binding));
10005
10006 VkVertexInputAttributeDescription input_attrib;
10007 memset(&input_attrib, 0, sizeof(input_attrib));
10008 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10009
10010 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010011 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010012 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010013 "out gl_PerVertex {\n"
10014 " vec4 gl_Position;\n"
10015 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010016 "void main(){\n"
10017 " gl_Position = vec4(1);\n"
10018 "}\n";
10019 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010020 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +120010021 "\n"
10022 "layout(location=0) out vec4 color;\n"
10023 "void main(){\n"
10024 " color = vec4(1);\n"
10025 "}\n";
10026
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120010029
10030 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010031 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120010032 pipe.AddShader(&vs);
10033 pipe.AddShader(&fs);
10034
10035 pipe.AddVertexInputBindings(&input_binding, 1);
10036 pipe.AddVertexInputAttribs(&input_attrib, 1);
10037
Chris Forbesde136e02015-05-25 11:13:28 +120010038 VkDescriptorSetObj descriptorSet(m_device);
10039 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120010041
Tony Barbour5781e8f2015-08-04 16:23:11 -060010042 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120010043
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010044 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120010045}
10046
Karl Schultz6addd812016-02-02 17:17:23 -070010047TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010049 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +130010050
10051 ASSERT_NO_FATAL_FAILURE(InitState());
10052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10053
10054 VkVertexInputBindingDescription input_binding;
10055 memset(&input_binding, 0, sizeof(input_binding));
10056
10057 VkVertexInputAttributeDescription input_attrib;
10058 memset(&input_attrib, 0, sizeof(input_attrib));
10059 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10060
10061 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010062 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010063 "\n"
10064 "layout(location=1) in float x;\n"
10065 "out gl_PerVertex {\n"
10066 " vec4 gl_Position;\n"
10067 "};\n"
10068 "void main(){\n"
10069 " gl_Position = vec4(x);\n"
10070 "}\n";
10071 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010072 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +130010073 "\n"
10074 "layout(location=0) out vec4 color;\n"
10075 "void main(){\n"
10076 " color = vec4(1);\n"
10077 "}\n";
10078
10079 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10080 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10081
10082 VkPipelineObj pipe(m_device);
10083 pipe.AddColorAttachment();
10084 pipe.AddShader(&vs);
10085 pipe.AddShader(&fs);
10086
10087 pipe.AddVertexInputBindings(&input_binding, 1);
10088 pipe.AddVertexInputAttribs(&input_attrib, 1);
10089
10090 VkDescriptorSetObj descriptorSet(m_device);
10091 descriptorSet.AppendDummy();
10092 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10093
10094 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10095
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010096 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130010097}
10098
Karl Schultz6addd812016-02-02 17:17:23 -070010099TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
10100 m_errorMonitor->SetDesiredFailureMsg(
10101 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010102 "VS consumes input at location 0 but not provided");
10103
Chris Forbes62e8e502015-05-25 11:13:29 +120010104 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120010106
10107 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010108 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010109 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010110 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -070010111 "out gl_PerVertex {\n"
10112 " vec4 gl_Position;\n"
10113 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010114 "void main(){\n"
10115 " gl_Position = x;\n"
10116 "}\n";
10117 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010118 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +120010119 "\n"
10120 "layout(location=0) out vec4 color;\n"
10121 "void main(){\n"
10122 " color = vec4(1);\n"
10123 "}\n";
10124
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010125 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10126 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120010127
10128 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010129 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120010130 pipe.AddShader(&vs);
10131 pipe.AddShader(&fs);
10132
Chris Forbes62e8e502015-05-25 11:13:29 +120010133 VkDescriptorSetObj descriptorSet(m_device);
10134 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010135 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120010136
Tony Barbour5781e8f2015-08-04 16:23:11 -060010137 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120010138
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010139 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120010140}
10141
Karl Schultz6addd812016-02-02 17:17:23 -070010142TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
10143 m_errorMonitor->SetDesiredFailureMsg(
10144 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010145 "location 0 does not match VS input type");
10146
Chris Forbesc97d98e2015-05-25 11:13:31 +120010147 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010149
10150 VkVertexInputBindingDescription input_binding;
10151 memset(&input_binding, 0, sizeof(input_binding));
10152
10153 VkVertexInputAttributeDescription input_attrib;
10154 memset(&input_attrib, 0, sizeof(input_attrib));
10155 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10156
10157 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010158 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010159 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010160 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010161 "out gl_PerVertex {\n"
10162 " vec4 gl_Position;\n"
10163 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010164 "void main(){\n"
10165 " gl_Position = vec4(x);\n"
10166 "}\n";
10167 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010168 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +120010169 "\n"
10170 "layout(location=0) out vec4 color;\n"
10171 "void main(){\n"
10172 " color = vec4(1);\n"
10173 "}\n";
10174
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010175 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10176 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010177
10178 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010179 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010180 pipe.AddShader(&vs);
10181 pipe.AddShader(&fs);
10182
10183 pipe.AddVertexInputBindings(&input_binding, 1);
10184 pipe.AddVertexInputAttribs(&input_attrib, 1);
10185
Chris Forbesc97d98e2015-05-25 11:13:31 +120010186 VkDescriptorSetObj descriptorSet(m_device);
10187 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010188 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120010189
Tony Barbour5781e8f2015-08-04 16:23:11 -060010190 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120010191
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010192 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120010193}
10194
Chris Forbesc68b43c2016-04-06 11:18:47 +120010195TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
10196 m_errorMonitor->SetDesiredFailureMsg(
10197 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10198 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
10199
10200 ASSERT_NO_FATAL_FAILURE(InitState());
10201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10202
10203 char const *vsSource =
10204 "#version 450\n"
10205 "\n"
10206 "out gl_PerVertex {\n"
10207 " vec4 gl_Position;\n"
10208 "};\n"
10209 "void main(){\n"
10210 " gl_Position = vec4(1);\n"
10211 "}\n";
10212 char const *fsSource =
10213 "#version 450\n"
10214 "\n"
10215 "layout(location=0) out vec4 color;\n"
10216 "void main(){\n"
10217 " color = vec4(1);\n"
10218 "}\n";
10219
10220 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10221 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10222
10223 VkPipelineObj pipe(m_device);
10224 pipe.AddColorAttachment();
10225 pipe.AddShader(&vs);
10226 pipe.AddShader(&vs);
10227 pipe.AddShader(&fs);
10228
10229 VkDescriptorSetObj descriptorSet(m_device);
10230 descriptorSet.AppendDummy();
10231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10232
10233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010235 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120010236}
10237
Karl Schultz6addd812016-02-02 17:17:23 -070010238TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010239 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010240
10241 ASSERT_NO_FATAL_FAILURE(InitState());
10242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10243
10244 VkVertexInputBindingDescription input_binding;
10245 memset(&input_binding, 0, sizeof(input_binding));
10246
10247 VkVertexInputAttributeDescription input_attribs[2];
10248 memset(input_attribs, 0, sizeof(input_attribs));
10249
10250 for (int i = 0; i < 2; i++) {
10251 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10252 input_attribs[i].location = i;
10253 }
10254
10255 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010256 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010257 "\n"
10258 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -070010259 "out gl_PerVertex {\n"
10260 " vec4 gl_Position;\n"
10261 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010262 "void main(){\n"
10263 " gl_Position = x[0] + x[1];\n"
10264 "}\n";
10265 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010266 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010267 "\n"
10268 "layout(location=0) out vec4 color;\n"
10269 "void main(){\n"
10270 " color = vec4(1);\n"
10271 "}\n";
10272
10273 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10274 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10275
10276 VkPipelineObj pipe(m_device);
10277 pipe.AddColorAttachment();
10278 pipe.AddShader(&vs);
10279 pipe.AddShader(&fs);
10280
10281 pipe.AddVertexInputBindings(&input_binding, 1);
10282 pipe.AddVertexInputAttribs(input_attribs, 2);
10283
10284 VkDescriptorSetObj descriptorSet(m_device);
10285 descriptorSet.AppendDummy();
10286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10287
10288 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10289
10290 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010291 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010292}
10293
Chris Forbes2682b242015-11-24 11:13:14 +130010294TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
10295{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010296 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +130010297
10298 ASSERT_NO_FATAL_FAILURE(InitState());
10299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10300
10301 VkVertexInputBindingDescription input_binding;
10302 memset(&input_binding, 0, sizeof(input_binding));
10303
10304 VkVertexInputAttributeDescription input_attribs[2];
10305 memset(input_attribs, 0, sizeof(input_attribs));
10306
10307 for (int i = 0; i < 2; i++) {
10308 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
10309 input_attribs[i].location = i;
10310 }
10311
10312 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010313 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010314 "\n"
10315 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -070010316 "out gl_PerVertex {\n"
10317 " vec4 gl_Position;\n"
10318 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010319 "void main(){\n"
10320 " gl_Position = x[0] + x[1];\n"
10321 "}\n";
10322 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010323 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +130010324 "\n"
10325 "layout(location=0) out vec4 color;\n"
10326 "void main(){\n"
10327 " color = vec4(1);\n"
10328 "}\n";
10329
10330 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10331 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10332
10333 VkPipelineObj pipe(m_device);
10334 pipe.AddColorAttachment();
10335 pipe.AddShader(&vs);
10336 pipe.AddShader(&fs);
10337
10338 pipe.AddVertexInputBindings(&input_binding, 1);
10339 pipe.AddVertexInputAttribs(input_attribs, 2);
10340
10341 VkDescriptorSetObj descriptorSet(m_device);
10342 descriptorSet.AppendDummy();
10343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10344
10345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010347 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +130010348}
Chris Forbes2682b242015-11-24 11:13:14 +130010349
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010350TEST_F(VkLayerTest, CreatePipelineSimplePositive)
10351{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010352 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010353
10354 ASSERT_NO_FATAL_FAILURE(InitState());
10355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10356
10357 char const *vsSource =
10358 "#version 450\n"
10359 "out gl_PerVertex {\n"
10360 " vec4 gl_Position;\n"
10361 "};\n"
10362 "void main(){\n"
10363 " gl_Position = vec4(0);\n"
10364 "}\n";
10365 char const *fsSource =
10366 "#version 450\n"
10367 "\n"
10368 "layout(location=0) out vec4 color;\n"
10369 "void main(){\n"
10370 " color = vec4(1);\n"
10371 "}\n";
10372
10373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10375
10376 VkPipelineObj pipe(m_device);
10377 pipe.AddColorAttachment();
10378 pipe.AddShader(&vs);
10379 pipe.AddShader(&fs);
10380
10381 VkDescriptorSetObj descriptorSet(m_device);
10382 descriptorSet.AppendDummy();
10383 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10384
10385 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10386
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010387 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010388}
10389
Chris Forbes912c9192016-04-05 17:50:35 +120010390TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
10391{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010392 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +120010393
10394 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
10395
10396 ASSERT_NO_FATAL_FAILURE(InitState());
10397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10398
10399 char const *vsSource =
10400 "#version 450\n"
10401 "out gl_PerVertex {\n"
10402 " vec4 gl_Position;\n"
10403 "};\n"
10404 "layout(location=0) out vec3 x;\n"
10405 "layout(location=1) out ivec3 y;\n"
10406 "layout(location=2) out vec3 z;\n"
10407 "void main(){\n"
10408 " gl_Position = vec4(0);\n"
10409 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
10410 "}\n";
10411 char const *fsSource =
10412 "#version 450\n"
10413 "\n"
10414 "layout(location=0) out vec4 color;\n"
10415 "layout(location=0) in float x;\n"
10416 "layout(location=1) flat in int y;\n"
10417 "layout(location=2) in vec2 z;\n"
10418 "void main(){\n"
10419 " color = vec4(1 + x + y + z.x);\n"
10420 "}\n";
10421
10422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10424
10425 VkPipelineObj pipe(m_device);
10426 pipe.AddColorAttachment();
10427 pipe.AddShader(&vs);
10428 pipe.AddShader(&fs);
10429
10430 VkDescriptorSetObj descriptorSet(m_device);
10431 descriptorSet.AppendDummy();
10432 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10433
10434 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010436 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +120010437}
10438
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010439TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
10440{
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010441 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010442
10443 ASSERT_NO_FATAL_FAILURE(InitState());
10444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10445
Chris Forbesc1e852d2016-04-04 19:26:42 +120010446 if (!m_device->phy().features().tessellationShader) {
10447 printf("Device does not support tessellation shaders; skipped.\n");
10448 return;
10449 }
10450
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010451 char const *vsSource =
10452 "#version 450\n"
10453 "void main(){}\n";
10454 char const *tcsSource =
10455 "#version 450\n"
10456 "layout(location=0) out int x[];\n"
10457 "layout(vertices=3) out;\n"
10458 "void main(){\n"
10459 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10460 " gl_TessLevelInner[0] = 1;\n"
10461 " x[gl_InvocationID] = gl_InvocationID;\n"
10462 "}\n";
10463 char const *tesSource =
10464 "#version 450\n"
10465 "layout(triangles, equal_spacing, cw) in;\n"
10466 "layout(location=0) in int x[];\n"
10467 "out gl_PerVertex { vec4 gl_Position; };\n"
10468 "void main(){\n"
10469 " gl_Position.xyz = gl_TessCoord;\n"
10470 " gl_Position.w = x[0] + x[1] + x[2];\n"
10471 "}\n";
10472 char const *fsSource =
10473 "#version 450\n"
10474 "layout(location=0) out vec4 color;\n"
10475 "void main(){\n"
10476 " color = vec4(1);\n"
10477 "}\n";
10478
10479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10480 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10481 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10483
10484 VkPipelineInputAssemblyStateCreateInfo iasci{
10485 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10486 nullptr,
10487 0,
10488 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10489 VK_FALSE};
10490
Chris Forbesb4cacb62016-04-04 19:15:00 +120010491 VkPipelineTessellationStateCreateInfo tsci{
10492 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10493 nullptr,
10494 0,
10495 3};
10496
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010497 VkPipelineObj pipe(m_device);
10498 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +120010499 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010500 pipe.AddColorAttachment();
10501 pipe.AddShader(&vs);
10502 pipe.AddShader(&tcs);
10503 pipe.AddShader(&tes);
10504 pipe.AddShader(&fs);
10505
10506 VkDescriptorSetObj descriptorSet(m_device);
10507 descriptorSet.AppendDummy();
10508 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10509
10510 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10511
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010512 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +120010513}
10514
Chris Forbesa0ab8152016-04-20 13:34:27 +120010515TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
10516{
10517 m_errorMonitor->ExpectSuccess();
10518
10519 ASSERT_NO_FATAL_FAILURE(InitState());
10520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10521
10522 if (!m_device->phy().features().geometryShader) {
10523 printf("Device does not support geometry shaders; skipped.\n");
10524 return;
10525 }
10526
10527 char const *vsSource =
10528 "#version 450\n"
10529 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
10530 "void main(){\n"
10531 " vs_out.x = vec4(1);\n"
10532 "}\n";
10533 char const *gsSource =
10534 "#version 450\n"
10535 "layout(triangles) in;\n"
10536 "layout(triangle_strip, max_vertices=3) out;\n"
10537 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
10538 "out gl_PerVertex { vec4 gl_Position; };\n"
10539 "void main() {\n"
10540 " gl_Position = gs_in[0].x;\n"
10541 " EmitVertex();\n"
10542 "}\n";
10543 char const *fsSource =
10544 "#version 450\n"
10545 "layout(location=0) out vec4 color;\n"
10546 "void main(){\n"
10547 " color = vec4(1);\n"
10548 "}\n";
10549
10550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10551 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
10552 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10553
10554 VkPipelineObj pipe(m_device);
10555 pipe.AddColorAttachment();
10556 pipe.AddShader(&vs);
10557 pipe.AddShader(&gs);
10558 pipe.AddShader(&fs);
10559
10560 VkDescriptorSetObj descriptorSet(m_device);
10561 descriptorSet.AppendDummy();
10562 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10563
10564 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10565
10566 m_errorMonitor->VerifyNotFound();
10567}
10568
Chris Forbesa0193bc2016-04-04 19:19:47 +120010569TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
10570{
10571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10572 "is per-vertex in tessellation control shader stage "
10573 "but per-patch in tessellation evaluation shader stage");
10574
10575 ASSERT_NO_FATAL_FAILURE(InitState());
10576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10577
Chris Forbesc1e852d2016-04-04 19:26:42 +120010578 if (!m_device->phy().features().tessellationShader) {
10579 printf("Device does not support tessellation shaders; skipped.\n");
10580 return;
10581 }
10582
Chris Forbesa0193bc2016-04-04 19:19:47 +120010583 char const *vsSource =
10584 "#version 450\n"
10585 "void main(){}\n";
10586 char const *tcsSource =
10587 "#version 450\n"
10588 "layout(location=0) out int x[];\n"
10589 "layout(vertices=3) out;\n"
10590 "void main(){\n"
10591 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
10592 " gl_TessLevelInner[0] = 1;\n"
10593 " x[gl_InvocationID] = gl_InvocationID;\n"
10594 "}\n";
10595 char const *tesSource =
10596 "#version 450\n"
10597 "layout(triangles, equal_spacing, cw) in;\n"
10598 "layout(location=0) patch in int x;\n"
10599 "out gl_PerVertex { vec4 gl_Position; };\n"
10600 "void main(){\n"
10601 " gl_Position.xyz = gl_TessCoord;\n"
10602 " gl_Position.w = x;\n"
10603 "}\n";
10604 char const *fsSource =
10605 "#version 450\n"
10606 "layout(location=0) out vec4 color;\n"
10607 "void main(){\n"
10608 " color = vec4(1);\n"
10609 "}\n";
10610
10611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10612 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
10613 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
10614 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10615
10616 VkPipelineInputAssemblyStateCreateInfo iasci{
10617 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
10618 nullptr,
10619 0,
10620 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
10621 VK_FALSE};
10622
10623 VkPipelineTessellationStateCreateInfo tsci{
10624 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
10625 nullptr,
10626 0,
10627 3};
10628
10629 VkPipelineObj pipe(m_device);
10630 pipe.SetInputAssembly(&iasci);
10631 pipe.SetTessellation(&tsci);
10632 pipe.AddColorAttachment();
10633 pipe.AddShader(&vs);
10634 pipe.AddShader(&tcs);
10635 pipe.AddShader(&tes);
10636 pipe.AddShader(&fs);
10637
10638 VkDescriptorSetObj descriptorSet(m_device);
10639 descriptorSet.AppendDummy();
10640 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10641
10642 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010644 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120010645}
10646
Karl Schultz6addd812016-02-02 17:17:23 -070010647TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
10648 m_errorMonitor->SetDesiredFailureMsg(
10649 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010650 "Duplicate vertex input binding descriptions for binding 0");
10651
Chris Forbes280ba2c2015-06-12 11:16:41 +120010652 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060010653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010654
10655 /* Two binding descriptions for binding 0 */
10656 VkVertexInputBindingDescription input_bindings[2];
10657 memset(input_bindings, 0, sizeof(input_bindings));
10658
10659 VkVertexInputAttributeDescription input_attrib;
10660 memset(&input_attrib, 0, sizeof(input_attrib));
10661 input_attrib.format = VK_FORMAT_R32_SFLOAT;
10662
10663 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010664 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010665 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010666 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -070010667 "out gl_PerVertex {\n"
10668 " vec4 gl_Position;\n"
10669 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010670 "void main(){\n"
10671 " gl_Position = vec4(x);\n"
10672 "}\n";
10673 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010674 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +120010675 "\n"
10676 "layout(location=0) out vec4 color;\n"
10677 "void main(){\n"
10678 " color = vec4(1);\n"
10679 "}\n";
10680
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010681 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10682 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010683
10684 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080010685 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010686 pipe.AddShader(&vs);
10687 pipe.AddShader(&fs);
10688
10689 pipe.AddVertexInputBindings(input_bindings, 2);
10690 pipe.AddVertexInputAttribs(&input_attrib, 1);
10691
Chris Forbes280ba2c2015-06-12 11:16:41 +120010692 VkDescriptorSetObj descriptorSet(m_device);
10693 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010694 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120010695
Tony Barbour5781e8f2015-08-04 16:23:11 -060010696 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120010697
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010698 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120010699}
Chris Forbes8f68b562015-05-25 11:13:32 +120010700
Chris Forbes35efec72016-04-21 14:32:08 +120010701TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
10702 m_errorMonitor->ExpectSuccess();
10703
10704 ASSERT_NO_FATAL_FAILURE(InitState());
10705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10706
10707 if (!m_device->phy().features().tessellationShader) {
10708 printf("Device does not support 64bit vertex attributes; skipped.\n");
10709 return;
10710 }
10711
10712 VkVertexInputBindingDescription input_bindings[1];
10713 memset(input_bindings, 0, sizeof(input_bindings));
10714
10715 VkVertexInputAttributeDescription input_attribs[4];
10716 memset(input_attribs, 0, sizeof(input_attribs));
10717 input_attribs[0].location = 0;
10718 input_attribs[0].offset = 0;
10719 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10720 input_attribs[1].location = 2;
10721 input_attribs[1].offset = 32;
10722 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10723 input_attribs[2].location = 4;
10724 input_attribs[2].offset = 64;
10725 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10726 input_attribs[3].location = 6;
10727 input_attribs[3].offset = 96;
10728 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
10729
10730 char const *vsSource =
10731 "#version 450\n"
10732 "\n"
10733 "layout(location=0) in dmat4 x;\n"
10734 "out gl_PerVertex {\n"
10735 " vec4 gl_Position;\n"
10736 "};\n"
10737 "void main(){\n"
10738 " gl_Position = vec4(x[0][0]);\n"
10739 "}\n";
10740 char const *fsSource =
10741 "#version 450\n"
10742 "\n"
10743 "layout(location=0) out vec4 color;\n"
10744 "void main(){\n"
10745 " color = vec4(1);\n"
10746 "}\n";
10747
10748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10750
10751 VkPipelineObj pipe(m_device);
10752 pipe.AddColorAttachment();
10753 pipe.AddShader(&vs);
10754 pipe.AddShader(&fs);
10755
10756 pipe.AddVertexInputBindings(input_bindings, 1);
10757 pipe.AddVertexInputAttribs(input_attribs, 4);
10758
10759 VkDescriptorSetObj descriptorSet(m_device);
10760 descriptorSet.AppendDummy();
10761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10762
10763 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10764
10765 m_errorMonitor->VerifyNotFound();
10766}
10767
Karl Schultz6addd812016-02-02 17:17:23 -070010768TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010770 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010771
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010772 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010773
10774 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010775 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010776 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010777 "out gl_PerVertex {\n"
10778 " vec4 gl_Position;\n"
10779 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010780 "void main(){\n"
10781 " gl_Position = vec4(1);\n"
10782 "}\n";
10783 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010784 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010785 "\n"
10786 "void main(){\n"
10787 "}\n";
10788
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010789 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10790 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010791
10792 VkPipelineObj pipe(m_device);
10793 pipe.AddShader(&vs);
10794 pipe.AddShader(&fs);
10795
Chia-I Wu08accc62015-07-07 11:50:03 +080010796 /* set up CB 0, not written */
10797 pipe.AddColorAttachment();
10798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010799
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010800 VkDescriptorSetObj descriptorSet(m_device);
10801 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010802 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010803
Tony Barbour5781e8f2015-08-04 16:23:11 -060010804 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010805
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010806 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120010807}
10808
Karl Schultz6addd812016-02-02 17:17:23 -070010809TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -070010810 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -070010811 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010812 "FS writes to output location 1 with no matching attachment");
10813
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010814 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010815
10816 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010817 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010818 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010819 "out gl_PerVertex {\n"
10820 " vec4 gl_Position;\n"
10821 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010822 "void main(){\n"
10823 " gl_Position = vec4(1);\n"
10824 "}\n";
10825 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010826 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010827 "\n"
10828 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010829 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010830 "void main(){\n"
10831 " x = vec4(1);\n"
10832 " y = vec4(1);\n"
10833 "}\n";
10834
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010835 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10836 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010837
10838 VkPipelineObj pipe(m_device);
10839 pipe.AddShader(&vs);
10840 pipe.AddShader(&fs);
10841
Chia-I Wu08accc62015-07-07 11:50:03 +080010842 /* set up CB 0, not written */
10843 pipe.AddColorAttachment();
10844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010845 /* FS writes CB 1, but we don't configure it */
10846
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010847 VkDescriptorSetObj descriptorSet(m_device);
10848 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010849 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010850
Tony Barbour5781e8f2015-08-04 16:23:11 -060010851 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010852
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010853 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120010854}
10855
Karl Schultz6addd812016-02-02 17:17:23 -070010856TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010858 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010859
Chris Forbesa36d69e2015-05-25 11:13:44 +120010860 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010861
10862 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010863 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010864 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010865 "out gl_PerVertex {\n"
10866 " vec4 gl_Position;\n"
10867 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010868 "void main(){\n"
10869 " gl_Position = vec4(1);\n"
10870 "}\n";
10871 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010872 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +120010873 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -070010874 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +120010875 "void main(){\n"
10876 " x = ivec4(1);\n"
10877 "}\n";
10878
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010881
10882 VkPipelineObj pipe(m_device);
10883 pipe.AddShader(&vs);
10884 pipe.AddShader(&fs);
10885
Chia-I Wu08accc62015-07-07 11:50:03 +080010886 /* set up CB 0; type is UNORM by default */
10887 pipe.AddColorAttachment();
10888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010889
Chris Forbesa36d69e2015-05-25 11:13:44 +120010890 VkDescriptorSetObj descriptorSet(m_device);
10891 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010892 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120010893
Tony Barbour5781e8f2015-08-04 16:23:11 -060010894 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120010895
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010896 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120010897}
Chris Forbes7b1b8932015-06-05 14:43:36 +120010898
Karl Schultz6addd812016-02-02 17:17:23 -070010899TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070010900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070010901 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010902
Chris Forbes556c76c2015-08-14 12:04:59 +120010903 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120010904
10905 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010906 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010907 "\n"
Tony Barboure804d202016-01-05 13:37:45 -070010908 "out gl_PerVertex {\n"
10909 " vec4 gl_Position;\n"
10910 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010911 "void main(){\n"
10912 " gl_Position = vec4(1);\n"
10913 "}\n";
10914 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +120010915 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +120010916 "\n"
10917 "layout(location=0) out vec4 x;\n"
10918 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
10919 "void main(){\n"
10920 " x = vec4(bar.y);\n"
10921 "}\n";
10922
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060010923 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10924 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120010925
Chris Forbes556c76c2015-08-14 12:04:59 +120010926 VkPipelineObj pipe(m_device);
10927 pipe.AddShader(&vs);
10928 pipe.AddShader(&fs);
10929
10930 /* set up CB 0; type is UNORM by default */
10931 pipe.AddColorAttachment();
10932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10933
10934 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010935 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120010936
10937 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10938
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010939 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120010940}
10941
Chris Forbes5c59e902016-02-26 16:56:09 +130010942TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
10943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10944 "not declared in layout");
10945
10946 ASSERT_NO_FATAL_FAILURE(InitState());
10947
10948 char const *vsSource =
10949 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010950 "\n"
10951 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
10952 "out gl_PerVertex {\n"
10953 " vec4 gl_Position;\n"
10954 "};\n"
10955 "void main(){\n"
10956 " gl_Position = vec4(consts.x);\n"
10957 "}\n";
10958 char const *fsSource =
10959 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +130010960 "\n"
10961 "layout(location=0) out vec4 x;\n"
10962 "void main(){\n"
10963 " x = vec4(1);\n"
10964 "}\n";
10965
10966 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10968
10969 VkPipelineObj pipe(m_device);
10970 pipe.AddShader(&vs);
10971 pipe.AddShader(&fs);
10972
10973 /* set up CB 0; type is UNORM by default */
10974 pipe.AddColorAttachment();
10975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10976
10977 VkDescriptorSetObj descriptorSet(m_device);
10978 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
10979
10980 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
10981
10982 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010983 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130010984}
10985
Chris Forbes10eb9ae2016-05-31 16:09:42 +120010986TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
10987 m_errorMonitor->SetDesiredFailureMsg(
10988 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10989 "Shader uses descriptor slot 0.0");
10990
10991 ASSERT_NO_FATAL_FAILURE(InitState());
10992
10993 char const *csSource =
10994 "#version 450\n"
10995 "\n"
10996 "layout(local_size_x=1) in;\n"
10997 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
10998 "void main(){\n"
10999 " x = vec4(1);\n"
11000 "}\n";
11001
11002 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11003
11004 VkDescriptorSetObj descriptorSet(m_device);
11005 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11006
11007 VkComputePipelineCreateInfo cpci = {
11008 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11009 nullptr, 0, {
11010 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11011 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11012 cs.handle(), "main", nullptr
11013 },
11014 descriptorSet.GetPipelineLayout(),
11015 VK_NULL_HANDLE, -1
11016 };
11017
11018 VkPipeline pipe;
11019 VkResult err = vkCreateComputePipelines(
11020 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11021
11022 m_errorMonitor->VerifyFound();
11023
11024 if (err == VK_SUCCESS) {
11025 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11026 }
11027}
11028
11029TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
11030 m_errorMonitor->ExpectSuccess();
11031
11032 ASSERT_NO_FATAL_FAILURE(InitState());
11033
11034 char const *csSource =
11035 "#version 450\n"
11036 "\n"
11037 "layout(local_size_x=1) in;\n"
11038 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
11039 "void main(){\n"
11040 " // x is not used.\n"
11041 "}\n";
11042
11043 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
11044
11045 VkDescriptorSetObj descriptorSet(m_device);
11046 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
11047
11048 VkComputePipelineCreateInfo cpci = {
11049 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
11050 nullptr, 0, {
11051 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
11052 nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT,
11053 cs.handle(), "main", nullptr
11054 },
11055 descriptorSet.GetPipelineLayout(),
11056 VK_NULL_HANDLE, -1
11057 };
11058
11059 VkPipeline pipe;
11060 VkResult err = vkCreateComputePipelines(
11061 m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
11062
11063 m_errorMonitor->VerifyNotFound();
11064
11065 if (err == VK_SUCCESS) {
11066 vkDestroyPipeline(m_device->device(), pipe, nullptr);
11067 }
11068}
11069
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011070#endif // SHADER_CHECKER_TESTS
11071
11072#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060011073TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -070011074 m_errorMonitor->SetDesiredFailureMsg(
11075 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011076 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011077
11078 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011079
11080 // Create an image
11081 VkImage image;
11082
Karl Schultz6addd812016-02-02 17:17:23 -070011083 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11084 const int32_t tex_width = 32;
11085 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011086
11087 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011088 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11089 image_create_info.pNext = NULL;
11090 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11091 image_create_info.format = tex_format;
11092 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011093 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070011094 image_create_info.extent.depth = 1;
11095 image_create_info.mipLevels = 1;
11096 image_create_info.arrayLayers = 1;
11097 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11098 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11099 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11100 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011101
11102 // Introduce error by sending down a bogus width extent
11103 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011104 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011105
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011106 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060011107}
11108
Mark Youngc48c4c12016-04-11 14:26:49 -060011109TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
11110 m_errorMonitor->SetDesiredFailureMsg(
11111 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11112 "CreateImage extents is 0 for at least one required dimension");
11113
11114 ASSERT_NO_FATAL_FAILURE(InitState());
11115
11116 // Create an image
11117 VkImage image;
11118
11119 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11120 const int32_t tex_width = 32;
11121 const int32_t tex_height = 32;
11122
11123 VkImageCreateInfo image_create_info = {};
11124 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11125 image_create_info.pNext = NULL;
11126 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11127 image_create_info.format = tex_format;
11128 image_create_info.extent.width = tex_width;
11129 image_create_info.extent.height = tex_height;
11130 image_create_info.extent.depth = 1;
11131 image_create_info.mipLevels = 1;
11132 image_create_info.arrayLayers = 1;
11133 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11134 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11135 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11136 image_create_info.flags = 0;
11137
11138 // Introduce error by sending down a bogus width extent
11139 image_create_info.extent.width = 0;
11140 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
11141
11142 m_errorMonitor->VerifyFound();
11143}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011144#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120011145
Tobin Ehliscde08892015-09-22 10:11:37 -060011146#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011147TEST_F(VkLayerTest, InvalidImageView) {
11148 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060011149
Karl Schultz6addd812016-02-02 17:17:23 -070011150 m_errorMonitor->SetDesiredFailureMsg(
11151 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011152 "vkCreateImageView called with baseMipLevel 10 ");
11153
Tobin Ehliscde08892015-09-22 10:11:37 -060011154 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060011155
Mike Stroyana3082432015-09-25 13:39:21 -060011156 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070011157 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060011158
Karl Schultz6addd812016-02-02 17:17:23 -070011159 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11160 const int32_t tex_width = 32;
11161 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060011162
11163 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011164 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11165 image_create_info.pNext = NULL;
11166 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11167 image_create_info.format = tex_format;
11168 image_create_info.extent.width = tex_width;
11169 image_create_info.extent.height = tex_height;
11170 image_create_info.extent.depth = 1;
11171 image_create_info.mipLevels = 1;
11172 image_create_info.arrayLayers = 1;
11173 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11174 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11175 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
11176 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060011177
Chia-I Wuf7458c52015-10-26 21:10:41 +080011178 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060011179 ASSERT_VK_SUCCESS(err);
11180
11181 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011182 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11183 image_view_create_info.image = image;
11184 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11185 image_view_create_info.format = tex_format;
11186 image_view_create_info.subresourceRange.layerCount = 1;
11187 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
11188 image_view_create_info.subresourceRange.levelCount = 1;
11189 image_view_create_info.subresourceRange.aspectMask =
11190 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060011191
11192 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070011193 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
11194 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060011195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011196 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060011197 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060011198}
Mike Stroyana3082432015-09-25 13:39:21 -060011199
Karl Schultz6addd812016-02-02 17:17:23 -070011200TEST_F(VkLayerTest, InvalidImageViewAspect) {
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011201 TEST_DESCRIPTION(
11202 "Create an image and try to create a view with an invalid aspectMask");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -070011204 "vkCreateImageView: Color image "
11205 "formats must have ONLY the "
11206 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011207
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011208 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011209
Karl Schultz6addd812016-02-02 17:17:23 -070011210 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011211 VkImageObj image(m_device);
11212 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT,
11213 VK_IMAGE_TILING_LINEAR, 0);
11214 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011215
11216 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011217 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011218 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070011219 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
11220 image_view_create_info.format = tex_format;
11221 image_view_create_info.subresourceRange.baseMipLevel = 0;
11222 image_view_create_info.subresourceRange.levelCount = 1;
11223 // Cause an error by setting an invalid image aspect
11224 image_view_create_info.subresourceRange.aspectMask =
11225 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011226
11227 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060011228 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011230 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060011231}
11232
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011233TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070011234 VkResult err;
11235 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011236
Karl Schultz6addd812016-02-02 17:17:23 -070011237 m_errorMonitor->SetDesiredFailureMsg(
11238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011239 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011240
Mike Stroyana3082432015-09-25 13:39:21 -060011241 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011242
11243 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011244 VkImage srcImage;
11245 VkImage dstImage;
11246 VkDeviceMemory srcMem;
11247 VkDeviceMemory destMem;
11248 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011249
11250 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011251 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11252 image_create_info.pNext = NULL;
11253 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11254 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11255 image_create_info.extent.width = 32;
11256 image_create_info.extent.height = 32;
11257 image_create_info.extent.depth = 1;
11258 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011259 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070011260 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11261 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11262 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11263 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011264
Karl Schultz6addd812016-02-02 17:17:23 -070011265 err =
11266 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011267 ASSERT_VK_SUCCESS(err);
11268
Karl Schultz6addd812016-02-02 17:17:23 -070011269 err =
11270 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011271 ASSERT_VK_SUCCESS(err);
11272
11273 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011274 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011275 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11276 memAlloc.pNext = NULL;
11277 memAlloc.allocationSize = 0;
11278 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011279
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011280 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011281 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011282 pass =
11283 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011284 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011285 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011286 ASSERT_VK_SUCCESS(err);
11287
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011288 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011289 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011290 pass =
11291 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011292 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011293 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011294 ASSERT_VK_SUCCESS(err);
11295
11296 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11297 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011298 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011299 ASSERT_VK_SUCCESS(err);
11300
11301 BeginCommandBuffer();
11302 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011303 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011304 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011305 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011306 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060011307 copyRegion.srcOffset.x = 0;
11308 copyRegion.srcOffset.y = 0;
11309 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011310 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011311 copyRegion.dstSubresource.mipLevel = 0;
11312 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011313 // Introduce failure by forcing the dst layerCount to differ from src
11314 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011315 copyRegion.dstOffset.x = 0;
11316 copyRegion.dstOffset.y = 0;
11317 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011318 copyRegion.extent.width = 1;
11319 copyRegion.extent.height = 1;
11320 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011321 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11322 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011323 EndCommandBuffer();
11324
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011325 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011326
Chia-I Wuf7458c52015-10-26 21:10:41 +080011327 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011328 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011329 vkFreeMemory(m_device->device(), srcMem, NULL);
11330 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011331}
11332
Tony Barbourd6673642016-05-05 14:46:39 -060011333TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
11334
11335 TEST_DESCRIPTION("Creating images with unsuported formats ");
11336
11337 ASSERT_NO_FATAL_FAILURE(InitState());
11338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11339 VkImageObj image(m_device);
11340 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11341 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11342 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11343 VK_IMAGE_TILING_OPTIMAL, 0);
11344 ASSERT_TRUE(image.initialized());
11345
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011346 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
11347 VkImageCreateInfo image_create_info;
11348 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11349 image_create_info.pNext = NULL;
11350 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11351 image_create_info.format = VK_FORMAT_UNDEFINED;
11352 image_create_info.extent.width = 32;
11353 image_create_info.extent.height = 32;
11354 image_create_info.extent.depth = 1;
11355 image_create_info.mipLevels = 1;
11356 image_create_info.arrayLayers = 1;
11357 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11358 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11360 image_create_info.flags = 0;
11361
11362 m_errorMonitor->SetDesiredFailureMsg(
11363 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11364 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
11365
11366 VkImage localImage;
11367 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
11368 m_errorMonitor->VerifyFound();
11369
Tony Barbourd6673642016-05-05 14:46:39 -060011370 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011371 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060011372 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
11373 VkFormat format = static_cast<VkFormat>(f);
11374 VkFormatProperties fProps = m_device->format_properties(format);
11375 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
11376 fProps.optimalTilingFeatures == 0) {
11377 unsupported = format;
11378 break;
11379 }
11380 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011381
Tony Barbourd6673642016-05-05 14:46:39 -060011382 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060011383 image_create_info.format = unsupported;
Tony Barbourd6673642016-05-05 14:46:39 -060011384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011385 "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060011386
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060011387 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060011388 m_errorMonitor->VerifyFound();
11389 }
11390}
11391
11392TEST_F(VkLayerTest, ImageLayerViewTests) {
11393 VkResult ret;
11394 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
11395
11396 ASSERT_NO_FATAL_FAILURE(InitState());
11397
11398 VkImageObj image(m_device);
11399 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11400 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11401 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11402 VK_IMAGE_TILING_OPTIMAL, 0);
11403 ASSERT_TRUE(image.initialized());
11404
11405 VkImageView imgView;
11406 VkImageViewCreateInfo imgViewInfo = {};
11407 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11408 imgViewInfo.image = image.handle();
11409 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
11410 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11411 imgViewInfo.subresourceRange.layerCount = 1;
11412 imgViewInfo.subresourceRange.baseMipLevel = 0;
11413 imgViewInfo.subresourceRange.levelCount = 1;
11414 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11415
11416 m_errorMonitor->SetDesiredFailureMsg(
11417 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11418 "vkCreateImageView called with baseMipLevel");
11419 // View can't have baseMipLevel >= image's mipLevels - Expect
11420 // VIEW_CREATE_ERROR
11421 imgViewInfo.subresourceRange.baseMipLevel = 1;
11422 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11423 m_errorMonitor->VerifyFound();
11424 imgViewInfo.subresourceRange.baseMipLevel = 0;
11425
11426 m_errorMonitor->SetDesiredFailureMsg(
11427 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11428 "vkCreateImageView called with baseArrayLayer");
11429 // View can't have baseArrayLayer >= image's arraySize - Expect
11430 // VIEW_CREATE_ERROR
11431 imgViewInfo.subresourceRange.baseArrayLayer = 1;
11432 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11433 m_errorMonitor->VerifyFound();
11434 imgViewInfo.subresourceRange.baseArrayLayer = 0;
11435
11436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11437 "vkCreateImageView called with 0 in "
11438 "pCreateInfo->subresourceRange."
11439 "levelCount");
11440 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
11441 imgViewInfo.subresourceRange.levelCount = 0;
11442 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11443 m_errorMonitor->VerifyFound();
11444 imgViewInfo.subresourceRange.levelCount = 1;
11445
11446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11447 "vkCreateImageView called with 0 in "
11448 "pCreateInfo->subresourceRange."
11449 "layerCount");
11450 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
11451 imgViewInfo.subresourceRange.layerCount = 0;
11452 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11453 m_errorMonitor->VerifyFound();
11454 imgViewInfo.subresourceRange.layerCount = 1;
11455
11456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11457 "but both must be color formats");
11458 // Can't use depth format for view into color image - Expect INVALID_FORMAT
11459 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
11460 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11461 m_errorMonitor->VerifyFound();
11462 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11463
11464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11465 "Formats MUST be IDENTICAL unless "
11466 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
11467 "was set on image creation.");
11468 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
11469 // VIEW_CREATE_ERROR
11470 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
11471 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11472 m_errorMonitor->VerifyFound();
11473 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
11474
11475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11476 "can support ImageViews with "
11477 "differing formats but they must be "
11478 "in the same compatibility class.");
11479 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
11480 // VIEW_CREATE_ERROR
11481 VkImageCreateInfo mutImgInfo = image.create_info();
11482 VkImage mutImage;
11483 mutImgInfo.format = VK_FORMAT_R8_UINT;
11484 assert(
11485 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
11486 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
11487 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
11488 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
11489 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
11490 ASSERT_VK_SUCCESS(ret);
11491 imgViewInfo.image = mutImage;
11492 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
11493 m_errorMonitor->VerifyFound();
11494 imgViewInfo.image = image.handle();
11495 vkDestroyImage(m_device->handle(), mutImage, NULL);
11496}
11497
11498TEST_F(VkLayerTest, MiscImageLayerTests) {
11499
11500 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
11501
11502 ASSERT_NO_FATAL_FAILURE(InitState());
11503
11504 VkImageObj image(m_device);
11505 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
11506 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
11507 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
11508 VK_IMAGE_TILING_OPTIMAL, 0);
11509 ASSERT_TRUE(image.initialized());
11510
11511 m_errorMonitor->SetDesiredFailureMsg(
11512 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11513 "number of layers in image subresource is zero");
11514 vk_testing::Buffer buffer;
11515 VkMemoryPropertyFlags reqs = 0;
11516 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
11517 VkBufferImageCopy region = {};
11518 region.bufferRowLength = 128;
11519 region.bufferImageHeight = 128;
11520 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11521 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
11522 region.imageSubresource.layerCount = 0;
11523 region.imageExtent.height = 4;
11524 region.imageExtent.width = 4;
11525 region.imageExtent.depth = 1;
11526 m_commandBuffer->BeginCommandBuffer();
11527 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11528 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11529 1, &region);
11530 m_errorMonitor->VerifyFound();
11531 region.imageSubresource.layerCount = 1;
11532
11533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11534 "aspectMasks for each region must "
11535 "specify only COLOR or DEPTH or "
11536 "STENCIL");
11537 // Expect MISMATCHED_IMAGE_ASPECT
11538 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
11539 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
11540 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
11541 1, &region);
11542 m_errorMonitor->VerifyFound();
11543 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11544
11545 m_errorMonitor->SetDesiredFailureMsg(
11546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11547 "If the format of srcImage is a depth, stencil, depth stencil or "
11548 "integer-based format then filter must be VK_FILTER_NEAREST");
11549 // Expect INVALID_FILTER
11550 VkImageObj intImage1(m_device);
11551 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
11552 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11553 0);
11554 VkImageObj intImage2(m_device);
11555 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
11556 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
11557 0);
11558 VkImageBlit blitRegion = {};
11559 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11560 blitRegion.srcSubresource.baseArrayLayer = 0;
11561 blitRegion.srcSubresource.layerCount = 1;
11562 blitRegion.srcSubresource.mipLevel = 0;
11563 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11564 blitRegion.dstSubresource.baseArrayLayer = 0;
11565 blitRegion.dstSubresource.layerCount = 1;
11566 blitRegion.dstSubresource.mipLevel = 0;
11567
11568 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
11569 intImage1.layout(), intImage2.handle(), intImage2.layout(),
11570 16, &blitRegion, VK_FILTER_LINEAR);
11571 m_errorMonitor->VerifyFound();
11572
11573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11574 "called with 0 in ppMemoryBarriers");
11575 VkImageMemoryBarrier img_barrier;
11576 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11577 img_barrier.pNext = NULL;
11578 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11579 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11580 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11581 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11582 img_barrier.image = image.handle();
11583 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11584 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
11585 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11586 img_barrier.subresourceRange.baseArrayLayer = 0;
11587 img_barrier.subresourceRange.baseMipLevel = 0;
11588 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
11589 img_barrier.subresourceRange.layerCount = 0;
11590 img_barrier.subresourceRange.levelCount = 1;
11591 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
11592 VK_PIPELINE_STAGE_HOST_BIT,
11593 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
11594 nullptr, 1, &img_barrier);
11595 m_errorMonitor->VerifyFound();
11596 img_barrier.subresourceRange.layerCount = 1;
11597}
11598
11599TEST_F(VkLayerTest, ImageFormatLimits) {
11600
11601 TEST_DESCRIPTION("Exceed the limits of image format ");
11602
11603 m_errorMonitor->SetDesiredFailureMsg(
11604 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11605 "CreateImage extents exceed allowable limits for format");
11606 VkImageCreateInfo image_create_info = {};
11607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11608 image_create_info.pNext = NULL;
11609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11610 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11611 image_create_info.extent.width = 32;
11612 image_create_info.extent.height = 32;
11613 image_create_info.extent.depth = 1;
11614 image_create_info.mipLevels = 1;
11615 image_create_info.arrayLayers = 1;
11616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11617 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11618 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11619 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11620 image_create_info.flags = 0;
11621
11622 VkImage nullImg;
11623 VkImageFormatProperties imgFmtProps;
11624 vkGetPhysicalDeviceImageFormatProperties(
11625 gpu(), image_create_info.format, image_create_info.imageType,
11626 image_create_info.tiling, image_create_info.usage,
11627 image_create_info.flags, &imgFmtProps);
11628 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
11629 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11630 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11631 m_errorMonitor->VerifyFound();
11632 image_create_info.extent.depth = 1;
11633
11634 m_errorMonitor->SetDesiredFailureMsg(
11635 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11636 "exceeds allowable maximum supported by format of");
11637 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
11638 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11639 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11640 m_errorMonitor->VerifyFound();
11641 image_create_info.mipLevels = 1;
11642
11643 m_errorMonitor->SetDesiredFailureMsg(
11644 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11645 "exceeds allowable maximum supported by format of");
11646 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
11647 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11648 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11649 m_errorMonitor->VerifyFound();
11650 image_create_info.arrayLayers = 1;
11651
11652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11653 "is not supported by format");
11654 int samples = imgFmtProps.sampleCounts >> 1;
11655 image_create_info.samples = (VkSampleCountFlagBits)samples;
11656 // Expect INVALID_FORMAT_LIMITS_VIOLATION
11657 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11658 m_errorMonitor->VerifyFound();
11659 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11660
11661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11662 "pCreateInfo->initialLayout, must be "
11663 "VK_IMAGE_LAYOUT_UNDEFINED or "
11664 "VK_IMAGE_LAYOUT_PREINITIALIZED");
11665 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11666 // Expect INVALID_LAYOUT
11667 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
11668 m_errorMonitor->VerifyFound();
11669 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11670}
11671
Karl Schultz6addd812016-02-02 17:17:23 -070011672TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060011673 VkResult err;
11674 bool pass;
11675
11676 // Create color images with different format sizes and try to copy between them
11677 m_errorMonitor->SetDesiredFailureMsg(
11678 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11679 "vkCmdCopyImage called with unmatched source and dest image format sizes");
11680
11681 ASSERT_NO_FATAL_FAILURE(InitState());
11682
11683 // Create two images of different types and try to copy between them
11684 VkImage srcImage;
11685 VkImage dstImage;
11686 VkDeviceMemory srcMem;
11687 VkDeviceMemory destMem;
11688 VkMemoryRequirements memReqs;
11689
11690 VkImageCreateInfo image_create_info = {};
11691 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11692 image_create_info.pNext = NULL;
11693 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11694 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11695 image_create_info.extent.width = 32;
11696 image_create_info.extent.height = 32;
11697 image_create_info.extent.depth = 1;
11698 image_create_info.mipLevels = 1;
11699 image_create_info.arrayLayers = 1;
11700 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11701 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11702 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11703 image_create_info.flags = 0;
11704
11705 err =
11706 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
11707 ASSERT_VK_SUCCESS(err);
11708
11709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11710 // Introduce failure by creating second image with a different-sized format.
11711 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
11712
11713 err =
11714 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
11715 ASSERT_VK_SUCCESS(err);
11716
11717 // Allocate memory
11718 VkMemoryAllocateInfo memAlloc = {};
11719 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11720 memAlloc.pNext = NULL;
11721 memAlloc.allocationSize = 0;
11722 memAlloc.memoryTypeIndex = 0;
11723
11724 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
11725 memAlloc.allocationSize = memReqs.size;
11726 pass =
11727 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11728 ASSERT_TRUE(pass);
11729 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
11730 ASSERT_VK_SUCCESS(err);
11731
11732 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
11733 memAlloc.allocationSize = memReqs.size;
11734 pass =
11735 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
11736 ASSERT_TRUE(pass);
11737 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
11738 ASSERT_VK_SUCCESS(err);
11739
11740 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11741 ASSERT_VK_SUCCESS(err);
11742 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
11743 ASSERT_VK_SUCCESS(err);
11744
11745 BeginCommandBuffer();
11746 VkImageCopy copyRegion;
11747 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11748 copyRegion.srcSubresource.mipLevel = 0;
11749 copyRegion.srcSubresource.baseArrayLayer = 0;
11750 copyRegion.srcSubresource.layerCount = 0;
11751 copyRegion.srcOffset.x = 0;
11752 copyRegion.srcOffset.y = 0;
11753 copyRegion.srcOffset.z = 0;
11754 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11755 copyRegion.dstSubresource.mipLevel = 0;
11756 copyRegion.dstSubresource.baseArrayLayer = 0;
11757 copyRegion.dstSubresource.layerCount = 0;
11758 copyRegion.dstOffset.x = 0;
11759 copyRegion.dstOffset.y = 0;
11760 copyRegion.dstOffset.z = 0;
11761 copyRegion.extent.width = 1;
11762 copyRegion.extent.height = 1;
11763 copyRegion.extent.depth = 1;
11764 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11765 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
11766 EndCommandBuffer();
11767
11768 m_errorMonitor->VerifyFound();
11769
11770 vkDestroyImage(m_device->device(), srcImage, NULL);
11771 vkDestroyImage(m_device->device(), dstImage, NULL);
11772 vkFreeMemory(m_device->device(), srcMem, NULL);
11773 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011774}
11775
Karl Schultz6addd812016-02-02 17:17:23 -070011776TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
11777 VkResult err;
11778 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011779
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011780 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011781 m_errorMonitor->SetDesiredFailureMsg(
11782 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011783 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011784
Mike Stroyana3082432015-09-25 13:39:21 -060011785 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011786
11787 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070011788 VkImage srcImage;
11789 VkImage dstImage;
11790 VkDeviceMemory srcMem;
11791 VkDeviceMemory destMem;
11792 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011793
11794 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011795 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11796 image_create_info.pNext = NULL;
11797 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11798 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11799 image_create_info.extent.width = 32;
11800 image_create_info.extent.height = 32;
11801 image_create_info.extent.depth = 1;
11802 image_create_info.mipLevels = 1;
11803 image_create_info.arrayLayers = 1;
11804 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11805 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
11806 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11807 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011808
Karl Schultz6addd812016-02-02 17:17:23 -070011809 err =
11810 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011811 ASSERT_VK_SUCCESS(err);
11812
Karl Schultzbdb75952016-04-19 11:36:49 -060011813 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
11814
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011815 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070011816 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060011817 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
11818 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011819
Karl Schultz6addd812016-02-02 17:17:23 -070011820 err =
11821 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011822 ASSERT_VK_SUCCESS(err);
11823
11824 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011825 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011826 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11827 memAlloc.pNext = NULL;
11828 memAlloc.allocationSize = 0;
11829 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011830
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011831 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011832 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011833 pass =
11834 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011835 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011836 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011837 ASSERT_VK_SUCCESS(err);
11838
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011839 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011840 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011841 pass =
11842 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011843 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011844 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011845 ASSERT_VK_SUCCESS(err);
11846
11847 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11848 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011849 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011850 ASSERT_VK_SUCCESS(err);
11851
11852 BeginCommandBuffer();
11853 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011854 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011855 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011856 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011857 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011858 copyRegion.srcOffset.x = 0;
11859 copyRegion.srcOffset.y = 0;
11860 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011861 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011862 copyRegion.dstSubresource.mipLevel = 0;
11863 copyRegion.dstSubresource.baseArrayLayer = 0;
11864 copyRegion.dstSubresource.layerCount = 0;
11865 copyRegion.dstOffset.x = 0;
11866 copyRegion.dstOffset.y = 0;
11867 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011868 copyRegion.extent.width = 1;
11869 copyRegion.extent.height = 1;
11870 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011871 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11872 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011873 EndCommandBuffer();
11874
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011875 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011876
Chia-I Wuf7458c52015-10-26 21:10:41 +080011877 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011878 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011879 vkFreeMemory(m_device->device(), srcMem, NULL);
11880 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011881}
11882
Karl Schultz6addd812016-02-02 17:17:23 -070011883TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
11884 VkResult err;
11885 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011886
Karl Schultz6addd812016-02-02 17:17:23 -070011887 m_errorMonitor->SetDesiredFailureMsg(
11888 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011889 "vkCmdResolveImage called with source sample count less than 2.");
11890
Mike Stroyana3082432015-09-25 13:39:21 -060011891 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011892
11893 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011894 VkImage srcImage;
11895 VkImage dstImage;
11896 VkDeviceMemory srcMem;
11897 VkDeviceMemory destMem;
11898 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060011899
11900 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011901 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11902 image_create_info.pNext = NULL;
11903 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11904 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
11905 image_create_info.extent.width = 32;
11906 image_create_info.extent.height = 1;
11907 image_create_info.extent.depth = 1;
11908 image_create_info.mipLevels = 1;
11909 image_create_info.arrayLayers = 1;
11910 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11911 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11912 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
11913 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011914
Karl Schultz6addd812016-02-02 17:17:23 -070011915 err =
11916 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011917 ASSERT_VK_SUCCESS(err);
11918
Karl Schultz6addd812016-02-02 17:17:23 -070011919 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011920
Karl Schultz6addd812016-02-02 17:17:23 -070011921 err =
11922 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060011923 ASSERT_VK_SUCCESS(err);
11924
11925 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011926 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011927 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11928 memAlloc.pNext = NULL;
11929 memAlloc.allocationSize = 0;
11930 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011931
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060011932 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011933 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011934 pass =
11935 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011936 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011937 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011938 ASSERT_VK_SUCCESS(err);
11939
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011940 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060011941 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070011942 pass =
11943 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060011944 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011945 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060011946 ASSERT_VK_SUCCESS(err);
11947
11948 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
11949 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011950 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060011951 ASSERT_VK_SUCCESS(err);
11952
11953 BeginCommandBuffer();
11954 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070011955 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
11956 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060011957 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011958 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060011959 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060011960 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011961 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011962 resolveRegion.srcOffset.x = 0;
11963 resolveRegion.srcOffset.y = 0;
11964 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080011965 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011966 resolveRegion.dstSubresource.mipLevel = 0;
11967 resolveRegion.dstSubresource.baseArrayLayer = 0;
11968 resolveRegion.dstSubresource.layerCount = 0;
11969 resolveRegion.dstOffset.x = 0;
11970 resolveRegion.dstOffset.y = 0;
11971 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060011972 resolveRegion.extent.width = 1;
11973 resolveRegion.extent.height = 1;
11974 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070011975 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
11976 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060011977 EndCommandBuffer();
11978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011979 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060011980
Chia-I Wuf7458c52015-10-26 21:10:41 +080011981 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011982 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080011983 vkFreeMemory(m_device->device(), srcMem, NULL);
11984 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060011985}
11986
Karl Schultz6addd812016-02-02 17:17:23 -070011987TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
11988 VkResult err;
11989 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060011990
Karl Schultz6addd812016-02-02 17:17:23 -070011991 m_errorMonitor->SetDesiredFailureMsg(
11992 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011993 "vkCmdResolveImage called with dest sample count greater than 1.");
11994
Mike Stroyana3082432015-09-25 13:39:21 -060011995 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060011996
Chris Forbesa7530692016-05-08 12:35:39 +120011997 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070011998 VkImage srcImage;
11999 VkImage dstImage;
12000 VkDeviceMemory srcMem;
12001 VkDeviceMemory destMem;
12002 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012003
12004 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012005 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12006 image_create_info.pNext = NULL;
12007 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12008 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12009 image_create_info.extent.width = 32;
12010 image_create_info.extent.height = 1;
12011 image_create_info.extent.depth = 1;
12012 image_create_info.mipLevels = 1;
12013 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120012014 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070012015 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12016 // Note: Some implementations expect color attachment usage for any
12017 // multisample surface
12018 image_create_info.usage =
12019 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12020 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012021
Karl Schultz6addd812016-02-02 17:17:23 -070012022 err =
12023 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012024 ASSERT_VK_SUCCESS(err);
12025
Karl Schultz6addd812016-02-02 17:17:23 -070012026 // Note: Some implementations expect color attachment usage for any
12027 // multisample surface
12028 image_create_info.usage =
12029 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012030
Karl Schultz6addd812016-02-02 17:17:23 -070012031 err =
12032 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012033 ASSERT_VK_SUCCESS(err);
12034
12035 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012036 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012037 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12038 memAlloc.pNext = NULL;
12039 memAlloc.allocationSize = 0;
12040 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012041
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012042 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012043 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012044 pass =
12045 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012046 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012047 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012048 ASSERT_VK_SUCCESS(err);
12049
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012050 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012051 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012052 pass =
12053 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012054 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012055 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012056 ASSERT_VK_SUCCESS(err);
12057
12058 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12059 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012060 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012061 ASSERT_VK_SUCCESS(err);
12062
12063 BeginCommandBuffer();
12064 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012065 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12066 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012067 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012068 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012069 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012070 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012071 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012072 resolveRegion.srcOffset.x = 0;
12073 resolveRegion.srcOffset.y = 0;
12074 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012075 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012076 resolveRegion.dstSubresource.mipLevel = 0;
12077 resolveRegion.dstSubresource.baseArrayLayer = 0;
12078 resolveRegion.dstSubresource.layerCount = 0;
12079 resolveRegion.dstOffset.x = 0;
12080 resolveRegion.dstOffset.y = 0;
12081 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012082 resolveRegion.extent.width = 1;
12083 resolveRegion.extent.height = 1;
12084 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012085 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12086 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012087 EndCommandBuffer();
12088
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012089 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012090
Chia-I Wuf7458c52015-10-26 21:10:41 +080012091 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012092 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012093 vkFreeMemory(m_device->device(), srcMem, NULL);
12094 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012095}
12096
Karl Schultz6addd812016-02-02 17:17:23 -070012097TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
12098 VkResult err;
12099 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012100
Karl Schultz6addd812016-02-02 17:17:23 -070012101 m_errorMonitor->SetDesiredFailureMsg(
12102 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012103 "vkCmdResolveImage called with unmatched source and dest formats.");
12104
Mike Stroyana3082432015-09-25 13:39:21 -060012105 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012106
12107 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012108 VkImage srcImage;
12109 VkImage dstImage;
12110 VkDeviceMemory srcMem;
12111 VkDeviceMemory destMem;
12112 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012113
12114 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012115 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12116 image_create_info.pNext = NULL;
12117 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12118 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12119 image_create_info.extent.width = 32;
12120 image_create_info.extent.height = 1;
12121 image_create_info.extent.depth = 1;
12122 image_create_info.mipLevels = 1;
12123 image_create_info.arrayLayers = 1;
12124 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12125 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12126 // Note: Some implementations expect color attachment usage for any
12127 // multisample surface
12128 image_create_info.usage =
12129 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12130 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012131
Karl Schultz6addd812016-02-02 17:17:23 -070012132 err =
12133 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012134 ASSERT_VK_SUCCESS(err);
12135
Karl Schultz6addd812016-02-02 17:17:23 -070012136 // Set format to something other than source image
12137 image_create_info.format = VK_FORMAT_R32_SFLOAT;
12138 // Note: Some implementations expect color attachment usage for any
12139 // multisample surface
12140 image_create_info.usage =
12141 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12142 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012143
Karl Schultz6addd812016-02-02 17:17:23 -070012144 err =
12145 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012146 ASSERT_VK_SUCCESS(err);
12147
12148 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012149 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012150 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12151 memAlloc.pNext = NULL;
12152 memAlloc.allocationSize = 0;
12153 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012154
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012155 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012156 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012157 pass =
12158 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012159 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012160 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012161 ASSERT_VK_SUCCESS(err);
12162
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012163 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012164 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012165 pass =
12166 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012167 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012168 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012169 ASSERT_VK_SUCCESS(err);
12170
12171 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12172 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012173 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012174 ASSERT_VK_SUCCESS(err);
12175
12176 BeginCommandBuffer();
12177 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012178 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12179 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012180 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012181 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012182 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012183 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012184 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012185 resolveRegion.srcOffset.x = 0;
12186 resolveRegion.srcOffset.y = 0;
12187 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012188 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012189 resolveRegion.dstSubresource.mipLevel = 0;
12190 resolveRegion.dstSubresource.baseArrayLayer = 0;
12191 resolveRegion.dstSubresource.layerCount = 0;
12192 resolveRegion.dstOffset.x = 0;
12193 resolveRegion.dstOffset.y = 0;
12194 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012195 resolveRegion.extent.width = 1;
12196 resolveRegion.extent.height = 1;
12197 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012198 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12199 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012200 EndCommandBuffer();
12201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012202 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012203
Chia-I Wuf7458c52015-10-26 21:10:41 +080012204 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012205 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012206 vkFreeMemory(m_device->device(), srcMem, NULL);
12207 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012208}
12209
Karl Schultz6addd812016-02-02 17:17:23 -070012210TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
12211 VkResult err;
12212 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060012213
Karl Schultz6addd812016-02-02 17:17:23 -070012214 m_errorMonitor->SetDesiredFailureMsg(
12215 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012216 "vkCmdResolveImage called with unmatched source and dest image types.");
12217
Mike Stroyana3082432015-09-25 13:39:21 -060012218 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060012219
12220 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070012221 VkImage srcImage;
12222 VkImage dstImage;
12223 VkDeviceMemory srcMem;
12224 VkDeviceMemory destMem;
12225 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060012226
12227 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012228 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12229 image_create_info.pNext = NULL;
12230 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12231 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
12232 image_create_info.extent.width = 32;
12233 image_create_info.extent.height = 1;
12234 image_create_info.extent.depth = 1;
12235 image_create_info.mipLevels = 1;
12236 image_create_info.arrayLayers = 1;
12237 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
12238 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12239 // Note: Some implementations expect color attachment usage for any
12240 // multisample surface
12241 image_create_info.usage =
12242 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12243 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012244
Karl Schultz6addd812016-02-02 17:17:23 -070012245 err =
12246 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012247 ASSERT_VK_SUCCESS(err);
12248
Karl Schultz6addd812016-02-02 17:17:23 -070012249 image_create_info.imageType = VK_IMAGE_TYPE_1D;
12250 // Note: Some implementations expect color attachment usage for any
12251 // multisample surface
12252 image_create_info.usage =
12253 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12254 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012255
Karl Schultz6addd812016-02-02 17:17:23 -070012256 err =
12257 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060012258 ASSERT_VK_SUCCESS(err);
12259
12260 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012261 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012262 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12263 memAlloc.pNext = NULL;
12264 memAlloc.allocationSize = 0;
12265 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012266
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060012267 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012268 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012269 pass =
12270 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012271 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012272 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012273 ASSERT_VK_SUCCESS(err);
12274
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012275 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060012276 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -070012277 pass =
12278 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060012279 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060012281 ASSERT_VK_SUCCESS(err);
12282
12283 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
12284 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012285 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060012286 ASSERT_VK_SUCCESS(err);
12287
12288 BeginCommandBuffer();
12289 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070012290 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
12291 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060012292 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012293 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060012294 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060012295 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012296 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012297 resolveRegion.srcOffset.x = 0;
12298 resolveRegion.srcOffset.y = 0;
12299 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080012300 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012301 resolveRegion.dstSubresource.mipLevel = 0;
12302 resolveRegion.dstSubresource.baseArrayLayer = 0;
12303 resolveRegion.dstSubresource.layerCount = 0;
12304 resolveRegion.dstOffset.x = 0;
12305 resolveRegion.dstOffset.y = 0;
12306 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060012307 resolveRegion.extent.width = 1;
12308 resolveRegion.extent.height = 1;
12309 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070012310 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
12311 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060012312 EndCommandBuffer();
12313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012314 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060012315
Chia-I Wuf7458c52015-10-26 21:10:41 +080012316 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012317 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012318 vkFreeMemory(m_device->device(), srcMem, NULL);
12319 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060012320}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012321
Karl Schultz6addd812016-02-02 17:17:23 -070012322TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012323 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070012324 // to using a DS format, then cause it to hit error due to COLOR_BIT not
12325 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012326 // The image format check comes 2nd in validation so we trigger it first,
12327 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070012328 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012329
Karl Schultz6addd812016-02-02 17:17:23 -070012330 m_errorMonitor->SetDesiredFailureMsg(
12331 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012332 "Combination depth/stencil image formats can have only the ");
12333
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012334 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012335
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012336 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012337 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12338 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012339
12340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12342 ds_pool_ci.pNext = NULL;
12343 ds_pool_ci.maxSets = 1;
12344 ds_pool_ci.poolSizeCount = 1;
12345 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012346
12347 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -070012348 err =
12349 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012350 ASSERT_VK_SUCCESS(err);
12351
12352 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012353 dsl_binding.binding = 0;
12354 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
12355 dsl_binding.descriptorCount = 1;
12356 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12357 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012358
12359 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012360 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12361 ds_layout_ci.pNext = NULL;
12362 ds_layout_ci.bindingCount = 1;
12363 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012364 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012365 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
12366 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012367 ASSERT_VK_SUCCESS(err);
12368
12369 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012370 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012371 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012372 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012373 alloc_info.descriptorPool = ds_pool;
12374 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -070012375 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
12376 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012377 ASSERT_VK_SUCCESS(err);
12378
Karl Schultz6addd812016-02-02 17:17:23 -070012379 VkImage image_bad;
12380 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012381 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060012382 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012383 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070012384 const int32_t tex_width = 32;
12385 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012386
12387 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12389 image_create_info.pNext = NULL;
12390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12391 image_create_info.format = tex_format_bad;
12392 image_create_info.extent.width = tex_width;
12393 image_create_info.extent.height = tex_height;
12394 image_create_info.extent.depth = 1;
12395 image_create_info.mipLevels = 1;
12396 image_create_info.arrayLayers = 1;
12397 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12398 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12399 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
12400 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12401 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012402
Karl Schultz6addd812016-02-02 17:17:23 -070012403 err =
12404 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012405 ASSERT_VK_SUCCESS(err);
12406 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -070012407 image_create_info.usage =
12408 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
12409 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
12410 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012411 ASSERT_VK_SUCCESS(err);
12412
12413 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012414 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12415 image_view_create_info.image = image_bad;
12416 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
12417 image_view_create_info.format = tex_format_bad;
12418 image_view_create_info.subresourceRange.baseArrayLayer = 0;
12419 image_view_create_info.subresourceRange.baseMipLevel = 0;
12420 image_view_create_info.subresourceRange.layerCount = 1;
12421 image_view_create_info.subresourceRange.levelCount = 1;
12422 image_view_create_info.subresourceRange.aspectMask =
12423 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012424
12425 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -070012426 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
12427 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012428
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012429 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012430
Chia-I Wuf7458c52015-10-26 21:10:41 +080012431 vkDestroyImage(m_device->device(), image_bad, NULL);
12432 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080012433 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060012435}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012436
12437TEST_F(VkLayerTest, ClearImageErrors) {
12438 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
12439 "ClearDepthStencilImage with a color image.");
12440
12441 ASSERT_NO_FATAL_FAILURE(InitState());
12442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12443
12444 // Renderpass is started here so end it as Clear cmds can't be in renderpass
12445 BeginCommandBuffer();
12446 m_commandBuffer->EndRenderPass();
12447
12448 // Color image
12449 VkClearColorValue clear_color;
12450 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
12451 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
12452 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
12453 const int32_t img_width = 32;
12454 const int32_t img_height = 32;
12455 VkImageCreateInfo image_create_info = {};
12456 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12457 image_create_info.pNext = NULL;
12458 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12459 image_create_info.format = color_format;
12460 image_create_info.extent.width = img_width;
12461 image_create_info.extent.height = img_height;
12462 image_create_info.extent.depth = 1;
12463 image_create_info.mipLevels = 1;
12464 image_create_info.arrayLayers = 1;
12465 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12466 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
12467 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
12468
12469 vk_testing::Image color_image;
12470 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info,
12471 reqs);
12472
12473 const VkImageSubresourceRange color_range =
12474 vk_testing::Image::subresource_range(image_create_info,
12475 VK_IMAGE_ASPECT_COLOR_BIT);
12476
12477 // Depth/Stencil image
12478 VkClearDepthStencilValue clear_value = {0};
12479 reqs = 0; // don't need HOST_VISIBLE DS image
12480 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
12481 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
12482 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
12483 ds_image_create_info.extent.width = 64;
12484 ds_image_create_info.extent.height = 64;
12485 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12486 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12487
12488 vk_testing::Image ds_image;
12489 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info,
12490 reqs);
12491
12492 const VkImageSubresourceRange ds_range =
12493 vk_testing::Image::subresource_range(ds_image_create_info,
12494 VK_IMAGE_ASPECT_DEPTH_BIT);
12495
12496 m_errorMonitor->SetDesiredFailureMsg(
12497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12498 "vkCmdClearColorImage called with depth/stencil image.");
12499
12500 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12501 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12502 &color_range);
12503
12504 m_errorMonitor->VerifyFound();
12505
Tony Barbour26434b92016-06-02 09:43:50 -060012506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12507 "vkCmdClearColorImage called with "
12508 "image created without "
12509 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
12510
12511 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(),
12512 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
12513 &color_range);
12514
12515 m_errorMonitor->VerifyFound();
12516
Tobin Ehlis6e23d772016-05-19 11:08:34 -060012517 // Call CmdClearDepthStencilImage with color image
12518 m_errorMonitor->SetDesiredFailureMsg(
12519 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12520 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
12521
12522 vkCmdClearDepthStencilImage(
12523 m_commandBuffer->GetBufferHandle(), color_image.handle(),
12524 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
12525 &ds_range);
12526
12527 m_errorMonitor->VerifyFound();
12528}
Tobin Ehliscde08892015-09-22 10:11:37 -060012529#endif // IMAGE_TESTS
12530
Tony Barbour300a6082015-04-07 13:44:53 -060012531int main(int argc, char **argv) {
12532 int result;
12533
Cody Northrop8e54a402016-03-08 22:25:52 -070012534#ifdef ANDROID
12535 int vulkanSupport = InitVulkan();
12536 if (vulkanSupport == 0)
12537 return 1;
12538#endif
12539
Tony Barbour300a6082015-04-07 13:44:53 -060012540 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060012541 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060012542
12543 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
12544
12545 result = RUN_ALL_TESTS();
12546
Tony Barbour6918cd52015-04-09 12:58:51 -060012547 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060012548 return result;
12549}