blob: dd5304702e158ebe778de9ce97e25a2b9c4340e6 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 */
Tony Barbour65c48b32015-11-17 10:02:56 -070021
Cody Northrop8e54a402016-03-08 22:25:52 -070022#ifdef ANDROID
23#include "vulkan_wrapper.h"
24#else
David Pinedo9316d3b2015-11-06 12:54:48 -070025#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070026#endif
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -060027#include "test_common.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060028#include "vkrenderframework.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060029#include "vk_layer_config.h"
Jon Ashburn7fa7e222016-02-02 12:08:10 -070030#include "icd-spv.h"
Tony Barbour300a6082015-04-07 13:44:53 -060031
Mark Lobodzinski3780e142015-05-14 15:08:13 -050032#define GLM_FORCE_RADIANS
33#include "glm/glm.hpp"
34#include <glm/gtc/matrix_transform.hpp>
35
Dustin Gravesffa90fa2016-05-06 11:20:38 -060036#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060037#define MEM_TRACKER_TESTS 1
38#define OBJ_TRACKER_TESTS 1
39#define DRAW_STATE_TESTS 1
40#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120041#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060042#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060043#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045//--------------------------------------------------------------------------------------
46// Mesh and VertexFormat Data
47//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070048struct Vertex {
49 float posX, posY, posZ, posW; // Position data
50 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050051};
52
Karl Schultz6addd812016-02-02 17:17:23 -070053#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054
55typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070056 BsoFailNone = 0x00000000,
57 BsoFailLineWidth = 0x00000001,
58 BsoFailDepthBias = 0x00000002,
59 BsoFailViewport = 0x00000004,
60 BsoFailScissor = 0x00000008,
61 BsoFailBlend = 0x00000010,
62 BsoFailDepthBounds = 0x00000020,
63 BsoFailStencilReadMask = 0x00000040,
64 BsoFailStencilWriteMask = 0x00000080,
65 BsoFailStencilReference = 0x00000100,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050066} BsoFailSelect;
67
68struct vktriangle_vs_uniform {
69 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070070 float mvp[4][4];
71 float position[3][4];
72 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073};
74
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050075static const char bindStateVertShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120076 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070077 "vec2 vertices[3];\n"
78 "out gl_PerVertex {\n"
79 " vec4 gl_Position;\n"
80 "};\n"
81 "void main() {\n"
82 " vertices[0] = vec2(-1.0, -1.0);\n"
83 " vertices[1] = vec2( 1.0, -1.0);\n"
84 " vertices[2] = vec2( 0.0, 1.0);\n"
85 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
86 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050087
Mark Lobodzinski75a97e62015-06-02 09:41:30 -050088static const char bindStateFragShaderText[] =
Chris Forbes7b342802016-04-07 13:20:10 +120089 "#version 450\n"
Karl Schultz6addd812016-02-02 17:17:23 -070090 "\n"
91 "layout(location = 0) out vec4 uFragColor;\n"
92 "void main(){\n"
93 " uFragColor = vec4(0,1,0,1);\n"
94 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050095
Karl Schultz6addd812016-02-02 17:17:23 -070096static VKAPI_ATTR VkBool32 VKAPI_CALL
97myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
98 uint64_t srcObject, size_t location, int32_t msgCode,
99 const char *pLayerPrefix, const char *pMsg, void *pUserData);
Tony Barbour300a6082015-04-07 13:44:53 -0600100
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600101// ********************************************************
102// ErrorMonitor Usage:
103//
104// Call SetDesiredFailureMsg with a string to be compared against all
105// encountered log messages. Passing NULL will match all log messages.
106// logMsg will return true for skipCall only if msg is matched or NULL.
107//
108// Call DesiredMsgFound to determine if the desired failure message
109// was encountered.
110
Tony Barbour300a6082015-04-07 13:44:53 -0600111class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700112 public:
113 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600114 test_platform_thread_create_mutex(&m_mutex);
115 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700116 m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700117 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600118 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600119 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600120
Dustin Graves48458142016-04-29 16:11:55 -0600121 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
122
Karl Schultz6addd812016-02-02 17:17:23 -0700123 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200124 // also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600125 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600126 m_failureMsg.clear();
127 m_otherMsgs.clear();
128 m_desiredMsg = msgString;
Karl Schultz6addd812016-02-02 17:17:23 -0700129 m_msgFound = VK_FALSE;
130 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600131 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600132 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600133
Karl Schultz6addd812016-02-02 17:17:23 -0700134 VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600135 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600136 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600137 if (m_bailout != NULL) {
138 *m_bailout = true;
139 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600140 string errorString(msgString);
141 if (msgFlags & m_msgFlags) {
142 if (errorString.find(m_desiredMsg) != string::npos) {
Chris Forbesc7b8ad72016-04-04 18:50:38 +1200143 if (m_msgFound) { /* if multiple matches, don't lose all but the last! */
144 m_otherMsgs.push_back(m_failureMsg);
145 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600146 m_failureMsg = errorString;
Karl Schultz6addd812016-02-02 17:17:23 -0700147 m_msgFound = VK_TRUE;
148 result = VK_TRUE;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149 } else {
150 m_otherMsgs.push_back(errorString);
151 }
152 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600153 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600155 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600156
Karl Schultz6addd812016-02-02 17:17:23 -0700157 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600158
Karl Schultz6addd812016-02-02 17:17:23 -0700159 string GetFailureMsg(void) { return m_failureMsg; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600160
Karl Schultz6addd812016-02-02 17:17:23 -0700161 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600162
Karl Schultz6addd812016-02-02 17:17:23 -0700163 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600164
Karl Schultz6addd812016-02-02 17:17:23 -0700165 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 vector<string> otherMsgs = GetOtherFailureMsgs();
167 cout << "Other error messages logged for this test were:" << endl;
168 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
169 cout << " " << *iter << endl;
170 }
171 }
172
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200173 /* helpers */
174
175 void ExpectSuccess() {
176 // match anything
177 SetDesiredFailureMsg(~0u, "");
178 }
179
180 void VerifyFound() {
181 // Not seeing the desired message is a failure. /Before/ throwing, dump
182 // any other messages.
183 if (!DesiredMsgFound()) {
184 DumpFailureMsgs();
185 FAIL() << "Did not receive expected error '" << m_desiredMsg << "'";
186 }
187 }
188
189 void VerifyNotFound() {
190 // ExpectSuccess() configured us to match anything. Any error is a
191 // failure.
192 if (DesiredMsgFound()) {
193 DumpFailureMsgs();
194 FAIL() << "Expected to succeed but got error: " << GetFailureMsg();
195 }
196 }
197
Karl Schultz6addd812016-02-02 17:17:23 -0700198 private:
199 VkFlags m_msgFlags;
200 string m_desiredMsg;
201 string m_failureMsg;
202 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600203 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700204 bool *m_bailout;
205 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600206};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500207
Karl Schultz6addd812016-02-02 17:17:23 -0700208static VKAPI_ATTR VkBool32 VKAPI_CALL
209myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType,
210 uint64_t srcObject, size_t location, int32_t msgCode,
211 const char *pLayerPrefix, const char *pMsg, void *pUserData) {
212 if (msgFlags &
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700213 (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
Karl Schultz6addd812016-02-02 17:17:23 -0700214 VK_DEBUG_REPORT_ERROR_BIT_EXT)) {
Tony Barbour0b4d9562015-04-09 10:48:04 -0600215 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216 return errMonitor->CheckForDesiredMsg(msgFlags, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600217 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600218 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600219}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500220
Karl Schultz6addd812016-02-02 17:17:23 -0700221class VkLayerTest : public VkRenderFramework {
222 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800223 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
224 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700225 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText,
226 BsoFailSelect failMask);
227 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
228 VkPipelineObj &pipelineobj,
229 VkDescriptorSetObj &descriptorSet,
230 BsoFailSelect failMask);
231 void GenericDrawPreparation(VkPipelineObj &pipelineobj,
232 VkDescriptorSetObj &descriptorSet,
233 BsoFailSelect failMask) {
234 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet,
235 failMask);
236 }
Tony Barbour300a6082015-04-07 13:44:53 -0600237
Tony Barbourfe3351b2015-07-28 10:17:20 -0600238 /* Convenience functions that use built-in command buffer */
Karl Schultz6addd812016-02-02 17:17:23 -0700239 VkResult BeginCommandBuffer() {
240 return BeginCommandBuffer(*m_commandBuffer);
241 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800242 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Karl Schultz6addd812016-02-02 17:17:23 -0700243 void Draw(uint32_t vertexCount, uint32_t instanceCount,
244 uint32_t firstVertex, uint32_t firstInstance) {
245 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex,
246 firstInstance);
247 }
248 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
249 uint32_t firstIndex, int32_t vertexOffset,
250 uint32_t firstInstance) {
251 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex,
252 vertexOffset, firstInstance);
253 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800254 void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); }
Karl Schultz6addd812016-02-02 17:17:23 -0700255 void QueueCommandBuffer(const VkFence &fence) {
256 m_commandBuffer->QueueCommandBuffer(fence);
257 }
258 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer,
259 VkDeviceSize offset, uint32_t binding) {
260 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
261 }
262 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
263 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
264 }
265
266 protected:
267 ErrorMonitor *m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600268
269 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600270 std::vector<const char *> instance_layer_names;
271 std::vector<const char *> device_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600272 std::vector<const char *> instance_extension_names;
273 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600274
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700275 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600276 /*
277 * Since CreateDbgMsgCallback is an instance level extension call
278 * any extension / layer that utilizes that feature also needs
279 * to be enabled at create instance time.
280 */
Karl Schultz6addd812016-02-02 17:17:23 -0700281 // Use Threading layer first to protect others from
282 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700283 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600284 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800285 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700286 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800287 instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
288 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600289 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700290 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600291
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700292 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600293 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800294 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700295 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800296 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
297 device_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600298 device_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700299 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Tony Barbour300a6082015-04-07 13:44:53 -0600300
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600301 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600302 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800303 this->app_info.pApplicationName = "layer_tests";
304 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600305 this->app_info.pEngineName = "unittest";
306 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600307 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600308
Tony Barbour15524c32015-04-29 17:34:29 -0600309 m_errorMonitor = new ErrorMonitor;
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600310 InitFramework(instance_layer_names, device_layer_names,
311 instance_extension_names, device_extension_names,
312 myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600313 }
314
315 virtual void TearDown() {
316 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600317 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600318 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600319 }
320};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500321
Karl Schultz6addd812016-02-02 17:17:23 -0700322VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600323 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600324
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800325 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600326
327 /*
328 * For render test all drawing happens in a single render pass
329 * on a single command buffer.
330 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200331 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800332 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600333 }
334
335 return result;
336}
337
Karl Schultz6addd812016-02-02 17:17:23 -0700338VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600339 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600340
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200341 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800342 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200343 }
Tony Barbour300a6082015-04-07 13:44:53 -0600344
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800345 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600346
347 return result;
348}
349
Karl Schultz6addd812016-02-02 17:17:23 -0700350void VkLayerTest::VKTriangleTest(const char *vertShaderText,
351 const char *fragShaderText,
352 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500353 // Create identity matrix
354 int i;
355 struct vktriangle_vs_uniform data;
356
357 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700358 glm::mat4 View = glm::mat4(1.0f);
359 glm::mat4 Model = glm::mat4(1.0f);
360 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500361 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700362 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500363
364 memcpy(&data.mvp, &MVP[0][0], matrixSize);
365
Karl Schultz6addd812016-02-02 17:17:23 -0700366 static const Vertex tri_data[] = {
367 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)},
368 {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)},
369 {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500370 };
371
Karl Schultz6addd812016-02-02 17:17:23 -0700372 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500373 data.position[i][0] = tri_data[i].posX;
374 data.position[i][1] = tri_data[i].posY;
375 data.position[i][2] = tri_data[i].posZ;
376 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700377 data.color[i][0] = tri_data[i].r;
378 data.color[i][1] = tri_data[i].g;
379 data.color[i][2] = tri_data[i].b;
380 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500381 }
382
383 ASSERT_NO_FATAL_FAILURE(InitState());
384 ASSERT_NO_FATAL_FAILURE(InitViewport());
385
Karl Schultz6addd812016-02-02 17:17:23 -0700386 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float),
387 (const void *)&data);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500388
Karl Schultz6addd812016-02-02 17:17:23 -0700389 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
390 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
391 this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
393 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800394 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500395 pipelineobj.AddShader(&vs);
396 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600397 if (failMask & BsoFailLineWidth) {
398 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600399 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
400 ia_state.sType =
401 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
402 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
403 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600404 }
405 if (failMask & BsoFailDepthBias) {
406 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600407 VkPipelineRasterizationStateCreateInfo rs_state = {};
408 rs_state.sType =
409 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
410 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600411 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600412 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600413 }
Karl Schultz6addd812016-02-02 17:17:23 -0700414 // Viewport and scissors must stay in synch or other errors will occur than
415 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600416 if (failMask & BsoFailViewport) {
417 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600418 m_viewports.clear();
419 m_scissors.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600420 }
421 if (failMask & BsoFailScissor) {
422 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600423 m_scissors.clear();
424 m_viewports.clear();
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600425 }
426 if (failMask & BsoFailBlend) {
427 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600428 VkPipelineColorBlendAttachmentState att_state = {};
429 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
430 att_state.blendEnable = VK_TRUE;
431 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600432 }
433 if (failMask & BsoFailDepthBounds) {
434 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
435 }
436 if (failMask & BsoFailStencilReadMask) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
438 }
439 if (failMask & BsoFailStencilWriteMask) {
440 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
441 }
442 if (failMask & BsoFailStencilReference) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
444 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500445
446 VkDescriptorSetObj descriptorSet(m_device);
Karl Schultz6addd812016-02-02 17:17:23 -0700447 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
448 constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449
450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600451 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500452
Tony Barbourfe3351b2015-07-28 10:17:20 -0600453 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500454
455 // render triangle
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -0600456 Draw(3, 1, 0, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
458 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600459 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
Tony Barbourfe3351b2015-07-28 10:17:20 -0600461 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500462}
463
Karl Schultz6addd812016-02-02 17:17:23 -0700464void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer,
465 VkPipelineObj &pipelineobj,
466 VkDescriptorSetObj &descriptorSet,
467 BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500468 if (m_depthStencil->Initialized()) {
Karl Schultz6addd812016-02-02 17:17:23 -0700469 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
470 m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500471 } else {
Karl Schultz6addd812016-02-02 17:17:23 -0700472 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
473 m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500474 }
475
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800476 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700477 // Make sure depthWriteEnable is set so that Depth fail test will work
478 // correctly
479 // Make sure stencilTestEnable is set so that Stencil fail test will work
480 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600481 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800482 stencil.failOp = VK_STENCIL_OP_KEEP;
483 stencil.passOp = VK_STENCIL_OP_KEEP;
484 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
485 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600486
487 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
488 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 ds_ci.pNext = NULL;
490 ds_ci.depthTestEnable = VK_FALSE;
491 ds_ci.depthWriteEnable = VK_TRUE;
492 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
493 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600494 if (failMask & BsoFailDepthBounds) {
495 ds_ci.depthBoundsTestEnable = VK_TRUE;
496 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600497 ds_ci.stencilTestEnable = VK_TRUE;
498 ds_ci.front = stencil;
499 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600500
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600501 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600502 pipelineobj.SetViewport(m_viewports);
503 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800504 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Karl Schultz6addd812016-02-02 17:17:23 -0700505 VkResult err = pipelineobj.CreateVKPipeline(
506 descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600507 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800508 commandBuffer->BindPipeline(pipelineobj);
509 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510}
511
512// ********************************************************************************************************************
513// ********************************************************************************************************************
514// ********************************************************************************************************************
515// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600516#if PARAMETER_VALIDATION_TESTS
517TEST_F(VkLayerTest, RequiredParameter) {
518 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
519 "pointer, array, and array count parameters");
520
521 ASSERT_NO_FATAL_FAILURE(InitState());
522
523 m_errorMonitor->SetDesiredFailureMsg(
524 VK_DEBUG_REPORT_ERROR_BIT_EXT,
525 "required parameter pFeatures specified as NULL");
526 // Specify NULL for a pointer to a handle
527 // Expected to trigger an error with
528 // parameter_validation::validate_required_pointer
529 vkGetPhysicalDeviceFeatures(gpu(), NULL);
530 m_errorMonitor->VerifyFound();
531
532 m_errorMonitor->SetDesiredFailureMsg(
533 VK_DEBUG_REPORT_ERROR_BIT_EXT,
534 "required parameter pPhysicalDeviceCount specified as NULL");
535 // Specify NULL for pointer to array count
536 // Expected to trigger an error with parameter_validation::validate_array
537 vkEnumeratePhysicalDevices(instance(), NULL, NULL);
538 m_errorMonitor->VerifyFound();
539
540 m_errorMonitor->SetDesiredFailureMsg(
541 VK_DEBUG_REPORT_ERROR_BIT_EXT,
542 "parameter viewportCount must be greater than 0");
543 // Specify 0 for a required array count
544 // Expected to trigger an error with parameter_validation::validate_array
545 VkViewport view_port = {};
546 m_commandBuffer->SetViewport(0, 0, &view_port);
547 m_errorMonitor->VerifyFound();
548
549 m_errorMonitor->SetDesiredFailureMsg(
550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
551 "required parameter pViewports specified as NULL");
552 // Specify NULL for a required array
553 // Expected to trigger an error with parameter_validation::validate_array
554 m_commandBuffer->SetViewport(0, 1, NULL);
555 m_errorMonitor->VerifyFound();
556
557 m_errorMonitor->SetDesiredFailureMsg(
558 VK_DEBUG_REPORT_ERROR_BIT_EXT,
559 "required parameter memory specified as VK_NULL_HANDLE");
560 // Specify VK_NULL_HANDLE for a required handle
561 // Expected to trigger an error with
562 // parameter_validation::validate_required_handle
563 vkUnmapMemory(device(), VK_NULL_HANDLE);
564 m_errorMonitor->VerifyFound();
565
566 m_errorMonitor->SetDesiredFailureMsg(
567 VK_DEBUG_REPORT_ERROR_BIT_EXT,
568 "required parameter pFences[0] specified as VK_NULL_HANDLE");
569 // Specify VK_NULL_HANDLE for a required handle array entry
570 // Expected to trigger an error with
571 // parameter_validation::validate_required_handle_array
572 VkFence fence = VK_NULL_HANDLE;
573 vkResetFences(device(), 1, &fence);
574 m_errorMonitor->VerifyFound();
575
576 m_errorMonitor->SetDesiredFailureMsg(
577 VK_DEBUG_REPORT_ERROR_BIT_EXT,
578 "required parameter pAllocateInfo specified as NULL");
579 // Specify NULL for a required struct pointer
580 // Expected to trigger an error with
581 // parameter_validation::validate_struct_type
582 VkDeviceMemory memory = VK_NULL_HANDLE;
583 vkAllocateMemory(device(), NULL, NULL, &memory);
584 m_errorMonitor->VerifyFound();
585
586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
587 "value of faceMask must not be 0");
588 // Specify 0 for a required VkFlags parameter
589 // Expected to trigger an error with parameter_validation::validate_flags
590 m_commandBuffer->SetStencilReference(0, 0);
591 m_errorMonitor->VerifyFound();
592
593 m_errorMonitor->SetDesiredFailureMsg(
594 VK_DEBUG_REPORT_ERROR_BIT_EXT,
595 "value of pSubmits[i].pWaitDstStageMask[0] must not be 0");
596 // Specify 0 for a required VkFlags array entry
597 // Expected to trigger an error with
598 // parameter_validation::validate_flags_array
599 VkSemaphore semaphore = VK_NULL_HANDLE;
600 VkPipelineStageFlags stageFlags = 0;
601 VkSubmitInfo submitInfo = {};
602 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
603 submitInfo.waitSemaphoreCount = 1;
604 submitInfo.pWaitSemaphores = &semaphore;
605 submitInfo.pWaitDstStageMask = &stageFlags;
606 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
607 m_errorMonitor->VerifyFound();
608}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600609
610TEST_F(VkLayerTest, InvalidStructSType) {
611 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
612 "structure's sType field");
613
614 ASSERT_NO_FATAL_FAILURE(InitState());
615
616 m_errorMonitor->SetDesiredFailureMsg(
617 VK_DEBUG_REPORT_ERROR_BIT_EXT,
618 "parameter pAllocateInfo->sType must be");
619 // Zero struct memory, effectively setting sType to
620 // VK_STRUCTURE_TYPE_APPLICATION_INFO
621 // Expected to trigger an error with
622 // parameter_validation::validate_struct_type
623 VkMemoryAllocateInfo alloc_info = {};
624 VkDeviceMemory memory = VK_NULL_HANDLE;
625 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
626 m_errorMonitor->VerifyFound();
627
628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
629 "parameter pSubmits[0].sType must be");
630 // Zero struct memory, effectively setting sType to
631 // VK_STRUCTURE_TYPE_APPLICATION_INFO
632 // Expected to trigger an error with
633 // parameter_validation::validate_struct_type_array
634 VkSubmitInfo submit_info = {};
635 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
636 m_errorMonitor->VerifyFound();
637}
638
639TEST_F(VkLayerTest, InvalidStructPNext) {
640 TEST_DESCRIPTION(
641 "Specify an invalid value for a Vulkan structure's pNext field");
642
643 ASSERT_NO_FATAL_FAILURE(InitState());
644
645 m_errorMonitor->SetDesiredFailureMsg(
646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
647 "value of pAllocateInfo->pNext must be NULL");
648 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be
649 // NULL
650 // Expected to trigger an error with
651 // parameter_validation::validate_struct_pnext
652 VkDeviceMemory memory = VK_NULL_HANDLE;
653 // Zero-initialization will provide the correct sType
654 VkApplicationInfo app_info = {};
655 VkMemoryAllocateInfo alloc_info = {};
656 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
657 alloc_info.pNext = &app_info;
658 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
659 m_errorMonitor->VerifyFound();
660
661 // TODO: Add non-NULL pNext case
662}
Dustin Graves5d33d532016-05-09 16:21:12 -0600663
664TEST_F(VkLayerTest, UnrecognizedValue) {
665 TEST_DESCRIPTION(
666 "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
667
668 ASSERT_NO_FATAL_FAILURE(InitState());
669
670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
671 "does not fall within the begin..end "
672 "range of the core VkFormat "
673 "enumeration tokens");
674 // Specify an invalid VkFormat value
675 // Expected to trigger an error with
676 // parameter_validation::validate_ranged_enum
677 VkFormatProperties format_properties;
678 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000),
679 &format_properties);
680 m_errorMonitor->VerifyFound();
681
682 m_errorMonitor->SetDesiredFailureMsg(
683 VK_DEBUG_REPORT_ERROR_BIT_EXT,
684 "contains flag bits that are not recognized members of");
685 // Specify an invalid VkFlags bitmask value
686 // Expected to trigger an error with parameter_validation::validate_flags
687 VkImageFormatProperties image_format_properties;
688 vkGetPhysicalDeviceImageFormatProperties(
689 gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
690 VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0,
691 &image_format_properties);
692 m_errorMonitor->VerifyFound();
693
694 m_errorMonitor->SetDesiredFailureMsg(
695 VK_DEBUG_REPORT_ERROR_BIT_EXT,
696 "contains flag bits that are not recognized members of");
697 // Specify an invalid VkFlags array entry
698 // Expected to trigger an error with
699 // parameter_validation::validate_flags_array
700 VkSemaphore semaphore = VK_NULL_HANDLE;
701 VkPipelineStageFlags stage_flags =
702 static_cast<VkPipelineStageFlags>(1 << 25);
703 VkSubmitInfo submit_info = {};
704 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
705 submit_info.waitSemaphoreCount = 1;
706 submit_info.pWaitSemaphores = &semaphore;
707 submit_info.pWaitDstStageMask = &stage_flags;
708 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
709 m_errorMonitor->VerifyFound();
710
711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
712 "is neither VK_TRUE nor VK_FALSE");
713 // Specify an invalid VkBool32 value
714 // Expected to trigger a warning with
715 // parameter_validation::validate_bool32
716 VkSampler sampler = VK_NULL_HANDLE;
717 VkSamplerCreateInfo sampler_info = {};
718 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
719 sampler_info.pNext = NULL;
720 sampler_info.magFilter = VK_FILTER_NEAREST;
721 sampler_info.minFilter = VK_FILTER_NEAREST;
722 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
723 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
724 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
725 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
726 sampler_info.mipLodBias = 1.0;
727 sampler_info.maxAnisotropy = 1;
728 sampler_info.compareEnable = VK_FALSE;
729 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
730 sampler_info.minLod = 1.0;
731 sampler_info.maxLod = 1.0;
732 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
733 sampler_info.unnormalizedCoordinates = VK_FALSE;
734 // Not VK_TRUE or VK_FALSE
735 sampler_info.anisotropyEnable = 3;
736 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
737 m_errorMonitor->VerifyFound();
738}
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600739#endif // PARAMETER_VALIDATION_TESTS
740
Tobin Ehlis0788f522015-05-26 16:11:58 -0600741#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700742#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800743TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500744{
745 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500746 VkFenceCreateInfo fenceInfo = {};
747 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
748 fenceInfo.pNext = NULL;
749 fenceInfo.flags = 0;
750
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600752
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500753 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600754
755 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
756 vk_testing::Buffer buffer;
757 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500758
Tony Barbourfe3351b2015-07-28 10:17:20 -0600759 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800760 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600761 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500762
763 testFence.init(*m_device, fenceInfo);
764
765 // Bypass framework since it does the waits automatically
766 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600767 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800768 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
769 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800770 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600771 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700772 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800773 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800774 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800775 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600776 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600777
778 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500779 ASSERT_VK_SUCCESS( err );
780
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500781 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800782 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500783
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200784 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500785}
786
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800787TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500788{
789 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500790 VkFenceCreateInfo fenceInfo = {};
791 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
792 fenceInfo.pNext = NULL;
793 fenceInfo.flags = 0;
794
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600796
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500797 ASSERT_NO_FATAL_FAILURE(InitState());
798 ASSERT_NO_FATAL_FAILURE(InitViewport());
799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
800
Tony Barbourfe3351b2015-07-28 10:17:20 -0600801 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800802 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600803 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500804
805 testFence.init(*m_device, fenceInfo);
806
807 // Bypass framework since it does the waits automatically
808 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600809 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800810 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
811 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800812 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600813 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700814 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800815 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800816 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800817 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600818 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600819
820 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500821 ASSERT_VK_SUCCESS( err );
822
Jon Ashburnf19916e2016-01-11 13:12:43 -0700823 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800824 VkCommandBufferBeginInfo info = {};
825 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
826 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600827 info.renderPass = VK_NULL_HANDLE;
828 info.subpass = 0;
829 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +0800830 info.occlusionQueryEnable = VK_FALSE;
831 info.queryFlags = 0;
832 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600833
834 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800835 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500836
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200837 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500838}
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700839#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200840
Mark Lobodzinski152fe252016-05-03 16:49:15 -0600841// This is a positive test. No failures are expected.
842TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
843 VkResult err;
844 bool pass;
845
846 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
847 "the buffer, create an image, and bind the same memory to "
848 "it");
849
850 m_errorMonitor->ExpectSuccess();
851
852 ASSERT_NO_FATAL_FAILURE(InitState());
853
854 VkBuffer buffer;
855 VkImage image;
856 VkDeviceMemory mem;
857 VkMemoryRequirements mem_reqs;
858
859 VkBufferCreateInfo buf_info = {};
860 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
861 buf_info.pNext = NULL;
862 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
863 buf_info.size = 256;
864 buf_info.queueFamilyIndexCount = 0;
865 buf_info.pQueueFamilyIndices = NULL;
866 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
867 buf_info.flags = 0;
868 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
869 ASSERT_VK_SUCCESS(err);
870
871 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
872
873 VkMemoryAllocateInfo alloc_info = {};
874 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
875 alloc_info.pNext = NULL;
876 alloc_info.memoryTypeIndex = 0;
877
878 // Ensure memory is big enough for both bindings
879 alloc_info.allocationSize = 0x10000;
880
881 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
882 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
883 if (!pass) {
884 vkDestroyBuffer(m_device->device(), buffer, NULL);
885 return;
886 }
887
888 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
889 ASSERT_VK_SUCCESS(err);
890
891 uint8_t *pData;
892 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
893 (void **)&pData);
894 ASSERT_VK_SUCCESS(err);
895
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600896 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -0600897
898 vkUnmapMemory(m_device->device(), mem);
899
900 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
901 ASSERT_VK_SUCCESS(err);
902
903 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
904 // memory. In fact, it was never used by the GPU.
905 // Just be be sure, wait for idle.
906 vkDestroyBuffer(m_device->device(), buffer, NULL);
907 vkDeviceWaitIdle(m_device->device());
908
909 VkImageCreateInfo image_create_info = {};
910 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
911 image_create_info.pNext = NULL;
912 image_create_info.imageType = VK_IMAGE_TYPE_2D;
913 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
914 image_create_info.extent.width = 64;
915 image_create_info.extent.height = 64;
916 image_create_info.extent.depth = 1;
917 image_create_info.mipLevels = 1;
918 image_create_info.arrayLayers = 1;
919 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
920 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
921 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
922 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
923 image_create_info.queueFamilyIndexCount = 0;
924 image_create_info.pQueueFamilyIndices = NULL;
925 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
926 image_create_info.flags = 0;
927
928 VkMemoryAllocateInfo mem_alloc = {};
929 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
930 mem_alloc.pNext = NULL;
931 mem_alloc.allocationSize = 0;
932 mem_alloc.memoryTypeIndex = 0;
933
934 /* Create a mappable image. It will be the texture if linear images are ok
935 * to be textures or it will be the staging image if they are not.
936 */
937 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
938 ASSERT_VK_SUCCESS(err);
939
940 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
941
942 mem_alloc.allocationSize = mem_reqs.size;
943
944 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
945 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
946 if (!pass) {
947 vkDestroyImage(m_device->device(), image, NULL);
948 return;
949 }
950
951 // VALDIATION FAILURE:
952 err = vkBindImageMemory(m_device->device(), image, mem, 0);
953 ASSERT_VK_SUCCESS(err);
954
955 m_errorMonitor->VerifyNotFound();
956
957 vkDestroyBuffer(m_device->device(), buffer, NULL);
958 vkDestroyImage(m_device->device(), image, NULL);
959}
960
Ian Elliott1c32c772016-04-28 14:47:13 -0600961TEST_F(VkLayerTest, EnableWsiBeforeUse) {
962 VkResult err;
963 bool pass;
964
Ian Elliott489eec02016-05-05 14:12:44 -0600965// FIXME: After we turn on this code for non-Linux platforms, uncomment the
966// following declaration (which is temporarily being moved below):
967// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -0600968 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
969 VkSwapchainCreateInfoKHR swapchain_create_info = {};
970 uint32_t swapchain_image_count = 0;
971// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
972 uint32_t image_index = 0;
973// VkPresentInfoKHR present_info = {};
974
975 ASSERT_NO_FATAL_FAILURE(InitState());
976
Ian Elliott3f06ce52016-04-29 14:46:21 -0600977#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
978#if defined(VK_USE_PLATFORM_ANDROID_KHR)
979 // Use the functions from the VK_KHR_android_surface extension without
980 // enabling that extension:
981
982 // Create a surface:
983 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
984#if 0
985#endif
986 m_errorMonitor->SetDesiredFailureMsg(
987 VK_DEBUG_REPORT_ERROR_BIT_EXT,
988 "extension was not enabled for this");
989 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
990 &surface);
991 pass = (err != VK_SUCCESS);
992 ASSERT_TRUE(pass);
993 m_errorMonitor->VerifyFound();
994#endif // VK_USE_PLATFORM_ANDROID_KHR
995
996
997#if defined(VK_USE_PLATFORM_MIR_KHR)
998 // Use the functions from the VK_KHR_mir_surface extension without enabling
999 // that extension:
1000
1001 // Create a surface:
1002 VkMirSurfaceCreateInfoKHR mir_create_info = {};
1003#if 0
1004#endif
1005 m_errorMonitor->SetDesiredFailureMsg(
1006 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1007 "extension was not enabled for this");
1008 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1009 pass = (err != VK_SUCCESS);
1010 ASSERT_TRUE(pass);
1011 m_errorMonitor->VerifyFound();
1012
1013 // Tell whether an mir_connection supports presentation:
1014 MirConnection *mir_connection = NULL;
1015 m_errorMonitor->SetDesiredFailureMsg(
1016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1017 "extension was not enabled for this");
1018 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
1019 visual_id);
1020 m_errorMonitor->VerifyFound();
1021#endif // VK_USE_PLATFORM_MIR_KHR
1022
1023
1024#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1025 // Use the functions from the VK_KHR_wayland_surface extension without
1026 // enabling that extension:
1027
1028 // Create a surface:
1029 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
1030#if 0
1031#endif
1032 m_errorMonitor->SetDesiredFailureMsg(
1033 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1034 "extension was not enabled for this");
1035 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
1036 &surface);
1037 pass = (err != VK_SUCCESS);
1038 ASSERT_TRUE(pass);
1039 m_errorMonitor->VerifyFound();
1040
1041 // Tell whether an wayland_display supports presentation:
1042 struct wl_display wayland_display = {};
1043 m_errorMonitor->SetDesiredFailureMsg(
1044 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1045 "extension was not enabled for this");
1046 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
1047 &wayland_display);
1048 m_errorMonitor->VerifyFound();
1049#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001050#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001051
1052
1053#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001054// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1055// TO NON-LINUX PLATFORMS:
1056VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001057 // Use the functions from the VK_KHR_win32_surface extension without
1058 // enabling that extension:
1059
1060 // Create a surface:
1061 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
1062#if 0
1063#endif
1064 m_errorMonitor->SetDesiredFailureMsg(
1065 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1066 "extension was not enabled for this");
1067 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
1068 &surface);
1069 pass = (err != VK_SUCCESS);
1070 ASSERT_TRUE(pass);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001074 m_errorMonitor->SetDesiredFailureMsg(
1075 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1076 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001077 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001078 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001079// Set this (for now, until all platforms are supported and tested):
1080#define NEED_TO_TEST_THIS_ON_PLATFORM
1081#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001082
1083
Ian Elliott1c32c772016-04-28 14:47:13 -06001084#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001085// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1086// TO NON-LINUX PLATFORMS:
1087VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001088 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1089 // that extension:
1090
1091 // Create a surface:
1092 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1093#if 0
1094#endif
1095 m_errorMonitor->SetDesiredFailureMsg(
1096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1097 "extension was not enabled for this");
1098 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1099 pass = (err != VK_SUCCESS);
1100 ASSERT_TRUE(pass);
1101 m_errorMonitor->VerifyFound();
1102
1103 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001104 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001105 xcb_visualid_t visual_id = 0;
1106 m_errorMonitor->SetDesiredFailureMsg(
1107 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1108 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001109 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001110 visual_id);
1111 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001112// Set this (for now, until all platforms are supported and tested):
1113#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001114#endif // VK_USE_PLATFORM_XCB_KHR
1115
1116
Ian Elliott12630812016-04-29 14:35:43 -06001117#if defined(VK_USE_PLATFORM_XLIB_KHR)
1118 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1119 // that extension:
1120
1121 // Create a surface:
1122 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
1123#if 0
1124#endif
1125 m_errorMonitor->SetDesiredFailureMsg(
1126 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1127 "extension was not enabled for this");
1128 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1129 pass = (err != VK_SUCCESS);
1130 ASSERT_TRUE(pass);
1131 m_errorMonitor->VerifyFound();
1132
1133 // Tell whether an Xlib VisualID supports presentation:
1134 Display *dpy = NULL;
1135 VisualID visual = 0;
1136 m_errorMonitor->SetDesiredFailureMsg(
1137 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1138 "extension was not enabled for this");
1139 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1140 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001141// Set this (for now, until all platforms are supported and tested):
1142#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001143#endif // VK_USE_PLATFORM_XLIB_KHR
1144
1145
Ian Elliott1c32c772016-04-28 14:47:13 -06001146 // Use the functions from the VK_KHR_surface extension without enabling
1147 // that extension:
1148
Ian Elliott489eec02016-05-05 14:12:44 -06001149#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001150 // Destroy a surface:
1151 m_errorMonitor->SetDesiredFailureMsg(
1152 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1153 "extension was not enabled for this");
1154 vkDestroySurfaceKHR(instance(), surface, NULL);
1155 m_errorMonitor->VerifyFound();
1156
1157 // Check if surface supports presentation:
1158 VkBool32 supported = false;
1159 m_errorMonitor->SetDesiredFailureMsg(
1160 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1161 "extension was not enabled for this");
1162 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1163 pass = (err != VK_SUCCESS);
1164 ASSERT_TRUE(pass);
1165 m_errorMonitor->VerifyFound();
1166
1167 // Check surface capabilities:
1168 VkSurfaceCapabilitiesKHR capabilities = {};
1169 m_errorMonitor->SetDesiredFailureMsg(
1170 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "extension was not enabled for this");
1172 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1173 &capabilities);
1174 pass = (err != VK_SUCCESS);
1175 ASSERT_TRUE(pass);
1176 m_errorMonitor->VerifyFound();
1177
1178 // Check surface formats:
1179 uint32_t format_count = 0;
1180 VkSurfaceFormatKHR *formats = NULL;
1181 m_errorMonitor->SetDesiredFailureMsg(
1182 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1183 "extension was not enabled for this");
1184 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1185 &format_count, formats);
1186 pass = (err != VK_SUCCESS);
1187 ASSERT_TRUE(pass);
1188 m_errorMonitor->VerifyFound();
1189
1190 // Check surface present modes:
1191 uint32_t present_mode_count = 0;
1192 VkSurfaceFormatKHR *present_modes = NULL;
1193 m_errorMonitor->SetDesiredFailureMsg(
1194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1195 "extension was not enabled for this");
1196 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1197 &present_mode_count, present_modes);
1198 pass = (err != VK_SUCCESS);
1199 ASSERT_TRUE(pass);
1200 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001201#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001202
1203
1204 // Use the functions from the VK_KHR_swapchain extension without enabling
1205 // that extension:
1206
1207 // Create a swapchain:
1208 m_errorMonitor->SetDesiredFailureMsg(
1209 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1210 "extension was not enabled for this");
1211 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1212 swapchain_create_info.pNext = NULL;
1213#if 0
1214 swapchain_create_info.flags = 0;
1215 swapchain_create_info.surface = 0;
1216 swapchain_create_info.minImageCount = 0;
1217 swapchain_create_info.imageFormat = 0;
1218 swapchain_create_info.imageColorSpace = 0;
1219 swapchain_create_info.imageExtent.width = 0;
1220 swapchain_create_info.imageExtent.height = 0;
1221 swapchain_create_info.imageArrayLayers = 0;
1222 swapchain_create_info.imageUsage = 0;
1223 swapchain_create_info.imageSharingMode = 0;
1224 swapchain_create_info.queueFamilyIndexCount = 0;
1225 swapchain_create_info.preTransform = 0;
1226 swapchain_create_info.compositeAlpha = 0;
1227 swapchain_create_info.presentMode = 0;
1228 swapchain_create_info.clipped = 0;
1229 swapchain_create_info.oldSwapchain = NULL;
1230#endif
1231 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1232 NULL, &swapchain);
1233 pass = (err != VK_SUCCESS);
1234 ASSERT_TRUE(pass);
1235 m_errorMonitor->VerifyFound();
1236
1237 // Get the images from the swapchain:
1238 m_errorMonitor->SetDesiredFailureMsg(
1239 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1240 "extension was not enabled for this");
1241 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1242 &swapchain_image_count, NULL);
1243 pass = (err != VK_SUCCESS);
1244 ASSERT_TRUE(pass);
1245 m_errorMonitor->VerifyFound();
1246
1247 // Try to acquire an image:
1248 m_errorMonitor->SetDesiredFailureMsg(
1249 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1250 "extension was not enabled for this");
1251 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1252 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1253 pass = (err != VK_SUCCESS);
1254 ASSERT_TRUE(pass);
1255 m_errorMonitor->VerifyFound();
1256
1257 // Try to present an image:
1258#if 0 // NOTE: Currently can't test this because a real swapchain is needed
1259 // (as opposed to the fake one we created) in order for the layer to
1260 // lookup the VkDevice used to enable the extension:
1261 m_errorMonitor->SetDesiredFailureMsg(
1262 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1263 "extension was not enabled for this");
1264 present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
1265 present_info.pNext = NULL;
1266#if 0
1267#endif
1268 err = vkQueuePresentKHR(m_device->m_queue, &present_info);
1269 pass = (err != VK_SUCCESS);
1270 ASSERT_TRUE(pass);
1271 m_errorMonitor->VerifyFound();
1272#endif
1273
1274 // Destroy the swapchain:
1275 m_errorMonitor->SetDesiredFailureMsg(
1276 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1277 "extension was not enabled for this");
1278 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1279 m_errorMonitor->VerifyFound();
1280}
1281
Karl Schultz6addd812016-02-02 17:17:23 -07001282TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1283 VkResult err;
1284 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001285
Karl Schultz6addd812016-02-02 17:17:23 -07001286 m_errorMonitor->SetDesiredFailureMsg(
1287 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001288 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
1289
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001290 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001291
1292 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001293 VkImage image;
1294 VkDeviceMemory mem;
1295 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001296
Karl Schultz6addd812016-02-02 17:17:23 -07001297 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1298 const int32_t tex_width = 32;
1299 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001300
Tony Barboureb254902015-07-15 12:50:33 -06001301 VkImageCreateInfo image_create_info = {};
1302 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001303 image_create_info.pNext = NULL;
1304 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1305 image_create_info.format = tex_format;
1306 image_create_info.extent.width = tex_width;
1307 image_create_info.extent.height = tex_height;
1308 image_create_info.extent.depth = 1;
1309 image_create_info.mipLevels = 1;
1310 image_create_info.arrayLayers = 1;
1311 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1312 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1313 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1314 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001315
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001316 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001317 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001318 mem_alloc.pNext = NULL;
1319 mem_alloc.allocationSize = 0;
1320 // Introduce failure, do NOT set memProps to
1321 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
1322 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001323
Chia-I Wuf7458c52015-10-26 21:10:41 +08001324 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001325 ASSERT_VK_SUCCESS(err);
1326
Karl Schultz6addd812016-02-02 17:17:23 -07001327 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001328
Mark Lobodzinski23065352015-05-29 09:32:35 -05001329 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001330
Karl Schultz6addd812016-02-02 17:17:23 -07001331 pass =
1332 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
1333 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1334 if (!pass) { // If we can't find any unmappable memory this test doesn't
1335 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001336 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001337 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001338 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001339
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001340 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001341 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001342 ASSERT_VK_SUCCESS(err);
1343
1344 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001345 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001346 ASSERT_VK_SUCCESS(err);
1347
1348 // Map memory as if to initialize the image
1349 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07001350 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
1351 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001352
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001353 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001354
Chia-I Wuf7458c52015-10-26 21:10:41 +08001355 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001356}
1357
Karl Schultz6addd812016-02-02 17:17:23 -07001358TEST_F(VkLayerTest, RebindMemory) {
1359 VkResult err;
1360 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001361
Karl Schultz6addd812016-02-02 17:17:23 -07001362 m_errorMonitor->SetDesiredFailureMsg(
1363 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001364 "which has already been bound to mem object");
1365
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001366 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001367
1368 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001369 VkImage image;
1370 VkDeviceMemory mem1;
1371 VkDeviceMemory mem2;
1372 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001373
Karl Schultz6addd812016-02-02 17:17:23 -07001374 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1375 const int32_t tex_width = 32;
1376 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001377
Tony Barboureb254902015-07-15 12:50:33 -06001378 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001379 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1380 image_create_info.pNext = NULL;
1381 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1382 image_create_info.format = tex_format;
1383 image_create_info.extent.width = tex_width;
1384 image_create_info.extent.height = tex_height;
1385 image_create_info.extent.depth = 1;
1386 image_create_info.mipLevels = 1;
1387 image_create_info.arrayLayers = 1;
1388 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1389 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1390 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1391 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001392
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001393 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001394 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1395 mem_alloc.pNext = NULL;
1396 mem_alloc.allocationSize = 0;
1397 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001398
Karl Schultz6addd812016-02-02 17:17:23 -07001399 // Introduce failure, do NOT set memProps to
1400 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001401 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001402 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001403 ASSERT_VK_SUCCESS(err);
1404
Karl Schultz6addd812016-02-02 17:17:23 -07001405 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001406
1407 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07001408 pass =
1409 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001410 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001411
1412 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001413 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001414 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001415 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001416 ASSERT_VK_SUCCESS(err);
1417
1418 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001419 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001420 ASSERT_VK_SUCCESS(err);
1421
Karl Schultz6addd812016-02-02 17:17:23 -07001422 // Introduce validation failure, try to bind a different memory object to
1423 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001424 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001425
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001426 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001427
Chia-I Wuf7458c52015-10-26 21:10:41 +08001428 vkDestroyImage(m_device->device(), image, NULL);
1429 vkFreeMemory(m_device->device(), mem1, NULL);
1430 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001431}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001432
Karl Schultz6addd812016-02-02 17:17:23 -07001433TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001434 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001435
Karl Schultz6addd812016-02-02 17:17:23 -07001436 m_errorMonitor->SetDesiredFailureMsg(
1437 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1438 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001439
1440 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001441 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1442 fenceInfo.pNext = NULL;
1443 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001444
Tony Barbour300a6082015-04-07 13:44:53 -06001445 ASSERT_NO_FATAL_FAILURE(InitState());
1446 ASSERT_NO_FATAL_FAILURE(InitViewport());
1447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1448
Tony Barbourfe3351b2015-07-28 10:17:20 -06001449 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07001450 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
1451 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001452 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001453
1454 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001455
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001456 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001457 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1458 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001459 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001460 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001461 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001462 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001463 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001464 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001465 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001466
1467 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001468 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001469
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001470 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001471}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001472// This is a positive test. We used to expect error in this case but spec now
1473// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07001474TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001475 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001476 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001477 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001478 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1479 fenceInfo.pNext = NULL;
1480
Tony Barbour0b4d9562015-04-09 10:48:04 -06001481 ASSERT_NO_FATAL_FAILURE(InitState());
1482 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08001483 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001484 VkResult result = vkResetFences(m_device->device(), 1, fences);
1485 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06001486
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001487 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06001488}
Tobin Ehlis41376e12015-07-03 08:45:14 -06001489
1490TEST_F(VkLayerTest, InvalidUsageBits)
1491{
Tony Barbourf92621a2016-05-02 14:28:12 -06001492 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001493 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06001494 "Initialize buffer with wrong usage then perform copy expecting errors "
1495 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001497 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001498
1499 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001500 VkImageObj image(m_device);
1501 // Initialize image with USAGE_INPUT_ATTACHMENT
1502 image.init(128, 128, VK_FORMAT_D32_SFLOAT_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001503 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
1504 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001505
Tony Barbourf92621a2016-05-02 14:28:12 -06001506 VkImageView dsv;
1507 VkImageViewCreateInfo dsvci = {};
1508 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1509 dsvci.image = image.handle();
1510 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1511 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1512 dsvci.subresourceRange.layerCount = 1;
1513 dsvci.subresourceRange.baseMipLevel = 0;
1514 dsvci.subresourceRange.levelCount = 1;
1515 dsvci.subresourceRange.aspectMask =
1516 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001517
Tony Barbourf92621a2016-05-02 14:28:12 -06001518 // Create a view with depth / stencil aspect for image with different usage
1519 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001521 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001522
1523 // Initialize buffer with TRANSFER_DST usage
1524 vk_testing::Buffer buffer;
1525 VkMemoryPropertyFlags reqs = 0;
1526 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1527 VkBufferImageCopy region = {};
1528 region.bufferRowLength = 128;
1529 region.bufferImageHeight = 128;
1530 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1531 region.imageSubresource.layerCount = 1;
1532 region.imageExtent.height = 16;
1533 region.imageExtent.width = 16;
1534 region.imageExtent.depth = 1;
1535
1536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1537 "Invalid usage flag for buffer ");
1538 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1539 // TRANSFER_DST
1540 BeginCommandBuffer();
1541 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
1542 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1543 1, &region);
1544 m_errorMonitor->VerifyFound();
1545
1546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1547 "Invalid usage flag for image ");
1548 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
1549 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1550 1, &region);
1551 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001552}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001553#endif // MEM_TRACKER_TESTS
1554
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001555#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001556
1557TEST_F(VkLayerTest, LeakAnObject) {
1558 VkResult err;
1559
1560 TEST_DESCRIPTION(
1561 "Create a fence and destroy its device without first destroying the fence.");
1562
1563 // Note that we have to create a new device since destroying the
1564 // framework's device causes Teardown() to fail and just calling Teardown
1565 // will destroy the errorMonitor.
1566
1567 m_errorMonitor->SetDesiredFailureMsg(
1568 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1569 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
1570
1571 ASSERT_NO_FATAL_FAILURE(InitState());
1572
1573 const std::vector<VkQueueFamilyProperties> queue_props =
1574 m_device->queue_props;
1575 std::vector<VkDeviceQueueCreateInfo> queue_info;
1576 queue_info.reserve(queue_props.size());
1577 std::vector<std::vector<float>> queue_priorities;
1578 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1579 VkDeviceQueueCreateInfo qi = {};
1580 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1581 qi.pNext = NULL;
1582 qi.queueFamilyIndex = i;
1583 qi.queueCount = queue_props[i].queueCount;
1584 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1585 qi.pQueuePriorities = queue_priorities[i].data();
1586 queue_info.push_back(qi);
1587 }
1588
1589 std::vector<const char *> device_layer_names;
1590 std::vector<const char *> device_extension_names;
1591 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
1592 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
1593 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
1594 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
1595 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
1596 device_layer_names.push_back("VK_LAYER_LUNARG_image");
1597 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
1598
1599 // The sacrificial device object
1600 VkDevice testDevice;
1601 VkDeviceCreateInfo device_create_info = {};
1602 auto features = m_device->phy().features();
1603 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1604 device_create_info.pNext = NULL;
1605 device_create_info.queueCreateInfoCount = queue_info.size();
1606 device_create_info.pQueueCreateInfos = queue_info.data();
1607 device_create_info.enabledLayerCount = device_layer_names.size();
1608 device_create_info.ppEnabledLayerNames = device_layer_names.data();
1609 device_create_info.pEnabledFeatures = &features;
1610 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1611 ASSERT_VK_SUCCESS(err);
1612
1613 VkFence fence;
1614 VkFenceCreateInfo fence_create_info = {};
1615 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1616 fence_create_info.pNext = NULL;
1617 fence_create_info.flags = 0;
1618 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
1619 ASSERT_VK_SUCCESS(err);
1620
1621 // Induce failure by not calling vkDestroyFence
1622 vkDestroyDevice(testDevice, NULL);
1623 m_errorMonitor->VerifyFound();
1624}
1625
1626TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
1627
1628 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
1629 "attempt to delete them from another.");
1630
1631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1632 "FreeCommandBuffers is attempting to free Command Buffer");
1633
1634 VkCommandPool command_pool_one;
1635 VkCommandPool command_pool_two;
1636
1637 VkCommandPoolCreateInfo pool_create_info{};
1638 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1639 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1640 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1641
1642 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1643 &command_pool_one);
1644
1645 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1646 &command_pool_two);
1647
1648 VkCommandBuffer command_buffer[9];
1649 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1650 command_buffer_allocate_info.sType =
1651 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1652 command_buffer_allocate_info.commandPool = command_pool_one;
1653 command_buffer_allocate_info.commandBufferCount = 9;
1654 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1655 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1656 command_buffer);
1657
1658 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
1659 &command_buffer[3]);
1660
1661 m_errorMonitor->VerifyFound();
1662
1663 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
1664 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
1665}
1666
1667TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
1668 VkResult err;
1669
1670 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
1671 "attempt to delete them from another.");
1672
1673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1674 "FreeDescriptorSets is attempting to free descriptorSet");
1675
1676 ASSERT_NO_FATAL_FAILURE(InitState());
1677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1678
1679 VkDescriptorPoolSize ds_type_count = {};
1680 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1681 ds_type_count.descriptorCount = 1;
1682
1683 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1684 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1685 ds_pool_ci.pNext = NULL;
1686 ds_pool_ci.flags = 0;
1687 ds_pool_ci.maxSets = 1;
1688 ds_pool_ci.poolSizeCount = 1;
1689 ds_pool_ci.pPoolSizes = &ds_type_count;
1690
1691 VkDescriptorPool ds_pool_one;
1692 err =
1693 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
1694 ASSERT_VK_SUCCESS(err);
1695
1696 // Create a second descriptor pool
1697 VkDescriptorPool ds_pool_two;
1698 err =
1699 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
1700 ASSERT_VK_SUCCESS(err);
1701
1702 VkDescriptorSetLayoutBinding dsl_binding = {};
1703 dsl_binding.binding = 0;
1704 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1705 dsl_binding.descriptorCount = 1;
1706 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1707 dsl_binding.pImmutableSamplers = NULL;
1708
1709 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1710 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1711 ds_layout_ci.pNext = NULL;
1712 ds_layout_ci.bindingCount = 1;
1713 ds_layout_ci.pBindings = &dsl_binding;
1714
1715 VkDescriptorSetLayout ds_layout;
1716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1717 &ds_layout);
1718 ASSERT_VK_SUCCESS(err);
1719
1720 VkDescriptorSet descriptorSet;
1721 VkDescriptorSetAllocateInfo alloc_info = {};
1722 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1723 alloc_info.descriptorSetCount = 1;
1724 alloc_info.descriptorPool = ds_pool_one;
1725 alloc_info.pSetLayouts = &ds_layout;
1726 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1727 &descriptorSet);
1728 ASSERT_VK_SUCCESS(err);
1729
1730 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
1731
1732 m_errorMonitor->VerifyFound();
1733
1734 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1735 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
1736 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
1737}
1738
1739TEST_F(VkLayerTest, CreateUnknownObject) {
1740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1741 "Invalid VkImage Object ");
1742
1743 TEST_DESCRIPTION(
1744 "Pass an invalid image object handle into a Vulkan API call.");
1745
1746 ASSERT_NO_FATAL_FAILURE(InitState());
1747
1748 // Pass bogus handle into GetImageMemoryRequirements
1749 VkMemoryRequirements mem_reqs;
1750 uint64_t fakeImageHandle = 0xCADECADE;
1751 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
1752
1753 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
1754
1755 m_errorMonitor->VerifyFound();
1756}
1757
Karl Schultz6addd812016-02-02 17:17:23 -07001758TEST_F(VkLayerTest, PipelineNotBound) {
1759 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001760
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001761 TEST_DESCRIPTION(
1762 "Pass in an invalid pipeline object handle into a Vulkan API call.");
1763
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07001765 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001766
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001767 ASSERT_NO_FATAL_FAILURE(InitState());
1768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001769
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001770 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001771 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1772 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001773
1774 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001775 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1776 ds_pool_ci.pNext = NULL;
1777 ds_pool_ci.maxSets = 1;
1778 ds_pool_ci.poolSizeCount = 1;
1779 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001780
1781 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07001782 err =
1783 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001784 ASSERT_VK_SUCCESS(err);
1785
1786 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001787 dsl_binding.binding = 0;
1788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1789 dsl_binding.descriptorCount = 1;
1790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1791 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001792
1793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001794 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1795 ds_layout_ci.pNext = NULL;
1796 ds_layout_ci.bindingCount = 1;
1797 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001798
1799 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001800 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1801 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001802 ASSERT_VK_SUCCESS(err);
1803
1804 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001805 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001806 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001807 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001808 alloc_info.descriptorPool = ds_pool;
1809 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001810 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1811 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001812 ASSERT_VK_SUCCESS(err);
1813
1814 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001815 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1816 pipeline_layout_ci.pNext = NULL;
1817 pipeline_layout_ci.setLayoutCount = 1;
1818 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001819
1820 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1822 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001823 ASSERT_VK_SUCCESS(err);
1824
Mark Youngad779052016-01-06 14:26:04 -07001825 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001826
1827 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07001828 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1829 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001831 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001832
Chia-I Wuf7458c52015-10-26 21:10:41 +08001833 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1834 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1835 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001836}
1837
Karl Schultz6addd812016-02-02 17:17:23 -07001838TEST_F(VkLayerTest, BindInvalidMemory) {
1839 VkResult err;
1840 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001841
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07001843 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001844
Tobin Ehlisec598302015-09-15 15:02:17 -06001845 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001846
1847 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001848 VkImage image;
1849 VkDeviceMemory mem;
1850 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06001851
Karl Schultz6addd812016-02-02 17:17:23 -07001852 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1853 const int32_t tex_width = 32;
1854 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06001855
1856 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001857 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1858 image_create_info.pNext = NULL;
1859 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1860 image_create_info.format = tex_format;
1861 image_create_info.extent.width = tex_width;
1862 image_create_info.extent.height = tex_height;
1863 image_create_info.extent.depth = 1;
1864 image_create_info.mipLevels = 1;
1865 image_create_info.arrayLayers = 1;
1866 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1867 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1868 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1869 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001870
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001871 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001872 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1873 mem_alloc.pNext = NULL;
1874 mem_alloc.allocationSize = 0;
1875 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001876
Chia-I Wuf7458c52015-10-26 21:10:41 +08001877 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001878 ASSERT_VK_SUCCESS(err);
1879
Karl Schultz6addd812016-02-02 17:17:23 -07001880 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001881
1882 mem_alloc.allocationSize = mem_reqs.size;
1883
Karl Schultz6addd812016-02-02 17:17:23 -07001884 pass =
1885 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001886 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001887
1888 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001889 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001890 ASSERT_VK_SUCCESS(err);
1891
1892 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001894
1895 // Try to bind free memory that has been freed
1896 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1897 // This may very well return an error.
1898 (void)err;
1899
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001900 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001901
Chia-I Wuf7458c52015-10-26 21:10:41 +08001902 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001903}
1904
Karl Schultz6addd812016-02-02 17:17:23 -07001905TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1906 VkResult err;
1907 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001908
Karl Schultz6addd812016-02-02 17:17:23 -07001909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1910 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001911
Tobin Ehlisec598302015-09-15 15:02:17 -06001912 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001913
Karl Schultz6addd812016-02-02 17:17:23 -07001914 // Create an image object, allocate memory, destroy the object and then try
1915 // to bind it
1916 VkImage image;
1917 VkDeviceMemory mem;
1918 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06001919
Karl Schultz6addd812016-02-02 17:17:23 -07001920 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1921 const int32_t tex_width = 32;
1922 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06001923
1924 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001925 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1926 image_create_info.pNext = NULL;
1927 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1928 image_create_info.format = tex_format;
1929 image_create_info.extent.width = tex_width;
1930 image_create_info.extent.height = tex_height;
1931 image_create_info.extent.depth = 1;
1932 image_create_info.mipLevels = 1;
1933 image_create_info.arrayLayers = 1;
1934 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1935 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1936 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1937 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001938
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001939 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001940 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1941 mem_alloc.pNext = NULL;
1942 mem_alloc.allocationSize = 0;
1943 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001944
Chia-I Wuf7458c52015-10-26 21:10:41 +08001945 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001946 ASSERT_VK_SUCCESS(err);
1947
Karl Schultz6addd812016-02-02 17:17:23 -07001948 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001949
1950 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07001951 pass =
1952 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001953 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001954
1955 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001956 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001957 ASSERT_VK_SUCCESS(err);
1958
1959 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001960 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001961 ASSERT_VK_SUCCESS(err);
1962
1963 // Now Try to bind memory to this destroyed object
1964 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1965 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07001966 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06001967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001968 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001969
Chia-I Wuf7458c52015-10-26 21:10:41 +08001970 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001971}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001972
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001973#endif // OBJ_TRACKER_TESTS
1974
Tobin Ehlis0788f522015-05-26 16:11:58 -06001975#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06001976
1977// This is a positive test. No errors should be generated.
1978TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
1979
1980 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1981 "submitted on separate queues followed by a QueueWaitIdle.");
1982
Dustin Graves48458142016-04-29 16:11:55 -06001983 if ((m_device->queue_props.empty()) ||
1984 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06001985 return;
1986
Mark Lobodzinskic808d442016-04-14 10:57:23 -06001987 m_errorMonitor->ExpectSuccess();
1988
1989 VkSemaphore semaphore;
1990 VkSemaphoreCreateInfo semaphore_create_info{};
1991 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1992 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1993 &semaphore);
1994
1995 VkCommandPool command_pool;
1996 VkCommandPoolCreateInfo pool_create_info{};
1997 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1998 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1999 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2000 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2001 &command_pool);
2002
2003 VkCommandBuffer command_buffer[2];
2004 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2005 command_buffer_allocate_info.sType =
2006 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2007 command_buffer_allocate_info.commandPool = command_pool;
2008 command_buffer_allocate_info.commandBufferCount = 2;
2009 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2010 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2011 command_buffer);
2012
2013 VkQueue queue = VK_NULL_HANDLE;
2014 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2015 1, &queue);
2016
2017 {
2018 VkCommandBufferBeginInfo begin_info{};
2019 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2020 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2021
2022 vkCmdPipelineBarrier(command_buffer[0],
2023 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2024 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2025 0, nullptr, 0, nullptr);
2026
2027 VkViewport viewport{};
2028 viewport.maxDepth = 1.0f;
2029 viewport.minDepth = 0.0f;
2030 viewport.width = 512;
2031 viewport.height = 512;
2032 viewport.x = 0;
2033 viewport.y = 0;
2034 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2035 vkEndCommandBuffer(command_buffer[0]);
2036 }
2037 {
2038 VkCommandBufferBeginInfo begin_info{};
2039 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2040 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2041
2042 VkViewport viewport{};
2043 viewport.maxDepth = 1.0f;
2044 viewport.minDepth = 0.0f;
2045 viewport.width = 512;
2046 viewport.height = 512;
2047 viewport.x = 0;
2048 viewport.y = 0;
2049 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2050 vkEndCommandBuffer(command_buffer[1]);
2051 }
2052 {
2053 VkSubmitInfo submit_info{};
2054 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2055 submit_info.commandBufferCount = 1;
2056 submit_info.pCommandBuffers = &command_buffer[0];
2057 submit_info.signalSemaphoreCount = 1;
2058 submit_info.pSignalSemaphores = &semaphore;
2059 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2060 }
2061 {
2062 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2063 VkSubmitInfo submit_info{};
2064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2065 submit_info.commandBufferCount = 1;
2066 submit_info.pCommandBuffers = &command_buffer[1];
2067 submit_info.waitSemaphoreCount = 1;
2068 submit_info.pWaitSemaphores = &semaphore;
2069 submit_info.pWaitDstStageMask = flags;
2070 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2071 }
2072
2073 vkQueueWaitIdle(m_device->m_queue);
2074
2075 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2076 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2077 &command_buffer[0]);
2078 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2079
2080 m_errorMonitor->VerifyNotFound();
2081}
2082
2083// This is a positive test. No errors should be generated.
2084TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
2085
2086 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2087 "submitted on separate queues, the second having a fence"
2088 "followed by a QueueWaitIdle.");
2089
Dustin Graves48458142016-04-29 16:11:55 -06002090 if ((m_device->queue_props.empty()) ||
2091 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002092 return;
2093
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002094 m_errorMonitor->ExpectSuccess();
2095
2096 VkFence fence;
2097 VkFenceCreateInfo fence_create_info{};
2098 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2099 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2100
2101 VkSemaphore semaphore;
2102 VkSemaphoreCreateInfo semaphore_create_info{};
2103 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2104 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2105 &semaphore);
2106
2107 VkCommandPool command_pool;
2108 VkCommandPoolCreateInfo pool_create_info{};
2109 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2110 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2111 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2112 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2113 &command_pool);
2114
2115 VkCommandBuffer command_buffer[2];
2116 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2117 command_buffer_allocate_info.sType =
2118 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2119 command_buffer_allocate_info.commandPool = command_pool;
2120 command_buffer_allocate_info.commandBufferCount = 2;
2121 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2122 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2123 command_buffer);
2124
2125 VkQueue queue = VK_NULL_HANDLE;
2126 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2127 1, &queue);
2128
2129 {
2130 VkCommandBufferBeginInfo begin_info{};
2131 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2132 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2133
2134 vkCmdPipelineBarrier(command_buffer[0],
2135 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2136 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2137 0, nullptr, 0, nullptr);
2138
2139 VkViewport viewport{};
2140 viewport.maxDepth = 1.0f;
2141 viewport.minDepth = 0.0f;
2142 viewport.width = 512;
2143 viewport.height = 512;
2144 viewport.x = 0;
2145 viewport.y = 0;
2146 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2147 vkEndCommandBuffer(command_buffer[0]);
2148 }
2149 {
2150 VkCommandBufferBeginInfo begin_info{};
2151 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2152 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2153
2154 VkViewport viewport{};
2155 viewport.maxDepth = 1.0f;
2156 viewport.minDepth = 0.0f;
2157 viewport.width = 512;
2158 viewport.height = 512;
2159 viewport.x = 0;
2160 viewport.y = 0;
2161 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2162 vkEndCommandBuffer(command_buffer[1]);
2163 }
2164 {
2165 VkSubmitInfo submit_info{};
2166 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2167 submit_info.commandBufferCount = 1;
2168 submit_info.pCommandBuffers = &command_buffer[0];
2169 submit_info.signalSemaphoreCount = 1;
2170 submit_info.pSignalSemaphores = &semaphore;
2171 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2172 }
2173 {
2174 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2175 VkSubmitInfo submit_info{};
2176 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2177 submit_info.commandBufferCount = 1;
2178 submit_info.pCommandBuffers = &command_buffer[1];
2179 submit_info.waitSemaphoreCount = 1;
2180 submit_info.pWaitSemaphores = &semaphore;
2181 submit_info.pWaitDstStageMask = flags;
2182 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2183 }
2184
2185 vkQueueWaitIdle(m_device->m_queue);
2186
2187 vkDestroyFence(m_device->device(), fence, nullptr);
2188 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2189 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2190 &command_buffer[0]);
2191 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2192
2193 m_errorMonitor->VerifyNotFound();
2194}
2195
2196// This is a positive test. No errors should be generated.
2197TEST_F(VkLayerTest,
2198 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
2199
2200 TEST_DESCRIPTION(
2201 "Two command buffers, each in a separate QueueSubmit call "
2202 "submitted on separate queues, the second having a fence"
2203 "followed by two consecutive WaitForFences calls on the same fence.");
2204
Dustin Graves48458142016-04-29 16:11:55 -06002205 if ((m_device->queue_props.empty()) ||
2206 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002207 return;
2208
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002209 m_errorMonitor->ExpectSuccess();
2210
2211 VkFence fence;
2212 VkFenceCreateInfo fence_create_info{};
2213 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2214 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2215
2216 VkSemaphore semaphore;
2217 VkSemaphoreCreateInfo semaphore_create_info{};
2218 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2219 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2220 &semaphore);
2221
2222 VkCommandPool command_pool;
2223 VkCommandPoolCreateInfo pool_create_info{};
2224 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2225 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2226 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2227 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2228 &command_pool);
2229
2230 VkCommandBuffer command_buffer[2];
2231 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2232 command_buffer_allocate_info.sType =
2233 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2234 command_buffer_allocate_info.commandPool = command_pool;
2235 command_buffer_allocate_info.commandBufferCount = 2;
2236 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2237 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2238 command_buffer);
2239
2240 VkQueue queue = VK_NULL_HANDLE;
2241 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2242 1, &queue);
2243
2244 {
2245 VkCommandBufferBeginInfo begin_info{};
2246 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2247 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2248
2249 vkCmdPipelineBarrier(command_buffer[0],
2250 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2251 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2252 0, nullptr, 0, nullptr);
2253
2254 VkViewport viewport{};
2255 viewport.maxDepth = 1.0f;
2256 viewport.minDepth = 0.0f;
2257 viewport.width = 512;
2258 viewport.height = 512;
2259 viewport.x = 0;
2260 viewport.y = 0;
2261 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2262 vkEndCommandBuffer(command_buffer[0]);
2263 }
2264 {
2265 VkCommandBufferBeginInfo begin_info{};
2266 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2267 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2268
2269 VkViewport viewport{};
2270 viewport.maxDepth = 1.0f;
2271 viewport.minDepth = 0.0f;
2272 viewport.width = 512;
2273 viewport.height = 512;
2274 viewport.x = 0;
2275 viewport.y = 0;
2276 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2277 vkEndCommandBuffer(command_buffer[1]);
2278 }
2279 {
2280 VkSubmitInfo submit_info{};
2281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2282 submit_info.commandBufferCount = 1;
2283 submit_info.pCommandBuffers = &command_buffer[0];
2284 submit_info.signalSemaphoreCount = 1;
2285 submit_info.pSignalSemaphores = &semaphore;
2286 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2287 }
2288 {
2289 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2290 VkSubmitInfo submit_info{};
2291 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2292 submit_info.commandBufferCount = 1;
2293 submit_info.pCommandBuffers = &command_buffer[1];
2294 submit_info.waitSemaphoreCount = 1;
2295 submit_info.pWaitSemaphores = &semaphore;
2296 submit_info.pWaitDstStageMask = flags;
2297 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2298 }
2299
2300 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2301 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2302
2303 vkDestroyFence(m_device->device(), fence, nullptr);
2304 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2305 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2306 &command_buffer[0]);
2307 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2308
2309 m_errorMonitor->VerifyNotFound();
2310}
2311
2312// This is a positive test. No errors should be generated.
2313TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
2314
2315 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2316 "submitted on separate queues, the second having a fence, "
2317 "followed by a WaitForFences call.");
2318
Dustin Graves48458142016-04-29 16:11:55 -06002319 if ((m_device->queue_props.empty()) ||
2320 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002321 return;
2322
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002323 m_errorMonitor->ExpectSuccess();
2324
2325 VkFence fence;
2326 VkFenceCreateInfo fence_create_info{};
2327 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2328 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2329
2330 VkSemaphore semaphore;
2331 VkSemaphoreCreateInfo semaphore_create_info{};
2332 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2333 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2334 &semaphore);
2335
2336 VkCommandPool command_pool;
2337 VkCommandPoolCreateInfo pool_create_info{};
2338 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2339 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2340 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2341 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2342 &command_pool);
2343
2344 VkCommandBuffer command_buffer[2];
2345 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2346 command_buffer_allocate_info.sType =
2347 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2348 command_buffer_allocate_info.commandPool = command_pool;
2349 command_buffer_allocate_info.commandBufferCount = 2;
2350 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2351 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2352 command_buffer);
2353
2354 VkQueue queue = VK_NULL_HANDLE;
2355 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2356 1, &queue);
2357
2358
2359 {
2360 VkCommandBufferBeginInfo begin_info{};
2361 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2362 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2363
2364 vkCmdPipelineBarrier(command_buffer[0],
2365 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2366 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2367 0, nullptr, 0, nullptr);
2368
2369 VkViewport viewport{};
2370 viewport.maxDepth = 1.0f;
2371 viewport.minDepth = 0.0f;
2372 viewport.width = 512;
2373 viewport.height = 512;
2374 viewport.x = 0;
2375 viewport.y = 0;
2376 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2377 vkEndCommandBuffer(command_buffer[0]);
2378 }
2379 {
2380 VkCommandBufferBeginInfo begin_info{};
2381 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2382 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2383
2384 VkViewport viewport{};
2385 viewport.maxDepth = 1.0f;
2386 viewport.minDepth = 0.0f;
2387 viewport.width = 512;
2388 viewport.height = 512;
2389 viewport.x = 0;
2390 viewport.y = 0;
2391 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2392 vkEndCommandBuffer(command_buffer[1]);
2393 }
2394 {
2395 VkSubmitInfo submit_info{};
2396 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2397 submit_info.commandBufferCount = 1;
2398 submit_info.pCommandBuffers = &command_buffer[0];
2399 submit_info.signalSemaphoreCount = 1;
2400 submit_info.pSignalSemaphores = &semaphore;
2401 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2402 }
2403 {
2404 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2405 VkSubmitInfo submit_info{};
2406 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2407 submit_info.commandBufferCount = 1;
2408 submit_info.pCommandBuffers = &command_buffer[1];
2409 submit_info.waitSemaphoreCount = 1;
2410 submit_info.pWaitSemaphores = &semaphore;
2411 submit_info.pWaitDstStageMask = flags;
2412 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2413 }
2414
2415 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2416
2417 vkDestroyFence(m_device->device(), fence, nullptr);
2418 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2419 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2420 &command_buffer[0]);
2421 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2422
2423 m_errorMonitor->VerifyNotFound();
2424}
2425
2426// This is a positive test. No errors should be generated.
2427TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
2428
2429 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2430 "on the same queue, sharing a signal/wait semaphore, the "
2431 "second having a fence, "
2432 "followed by a WaitForFences call.");
2433
2434 m_errorMonitor->ExpectSuccess();
2435
2436 VkFence fence;
2437 VkFenceCreateInfo fence_create_info{};
2438 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2439 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2440
2441 VkSemaphore semaphore;
2442 VkSemaphoreCreateInfo semaphore_create_info{};
2443 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2444 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2445 &semaphore);
2446
2447 VkCommandPool command_pool;
2448 VkCommandPoolCreateInfo pool_create_info{};
2449 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2450 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2451 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2452 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2453 &command_pool);
2454
2455 VkCommandBuffer command_buffer[2];
2456 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2457 command_buffer_allocate_info.sType =
2458 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2459 command_buffer_allocate_info.commandPool = command_pool;
2460 command_buffer_allocate_info.commandBufferCount = 2;
2461 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2462 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2463 command_buffer);
2464
2465 {
2466 VkCommandBufferBeginInfo begin_info{};
2467 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2468 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2469
2470 vkCmdPipelineBarrier(command_buffer[0],
2471 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2472 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2473 0, nullptr, 0, nullptr);
2474
2475 VkViewport viewport{};
2476 viewport.maxDepth = 1.0f;
2477 viewport.minDepth = 0.0f;
2478 viewport.width = 512;
2479 viewport.height = 512;
2480 viewport.x = 0;
2481 viewport.y = 0;
2482 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2483 vkEndCommandBuffer(command_buffer[0]);
2484 }
2485 {
2486 VkCommandBufferBeginInfo begin_info{};
2487 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2488 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2489
2490 VkViewport viewport{};
2491 viewport.maxDepth = 1.0f;
2492 viewport.minDepth = 0.0f;
2493 viewport.width = 512;
2494 viewport.height = 512;
2495 viewport.x = 0;
2496 viewport.y = 0;
2497 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2498 vkEndCommandBuffer(command_buffer[1]);
2499 }
2500 {
2501 VkSubmitInfo submit_info{};
2502 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2503 submit_info.commandBufferCount = 1;
2504 submit_info.pCommandBuffers = &command_buffer[0];
2505 submit_info.signalSemaphoreCount = 1;
2506 submit_info.pSignalSemaphores = &semaphore;
2507 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2508 }
2509 {
2510 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2511 VkSubmitInfo submit_info{};
2512 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2513 submit_info.commandBufferCount = 1;
2514 submit_info.pCommandBuffers = &command_buffer[1];
2515 submit_info.waitSemaphoreCount = 1;
2516 submit_info.pWaitSemaphores = &semaphore;
2517 submit_info.pWaitDstStageMask = flags;
2518 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2519 }
2520
2521 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2522
2523 vkDestroyFence(m_device->device(), fence, nullptr);
2524 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2525 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2526 &command_buffer[0]);
2527 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2528
2529 m_errorMonitor->VerifyNotFound();
2530}
2531
2532// This is a positive test. No errors should be generated.
2533TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
2534
2535 TEST_DESCRIPTION(
2536 "Two command buffers, each in a separate QueueSubmit call "
2537 "on the same queue, no fences, followed by a third QueueSubmit with NO "
2538 "SubmitInfos but with a fence, followed by a WaitForFences call.");
2539
2540 m_errorMonitor->ExpectSuccess();
2541
2542 VkFence fence;
2543 VkFenceCreateInfo fence_create_info{};
2544 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2545 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2546
2547 VkCommandPool command_pool;
2548 VkCommandPoolCreateInfo pool_create_info{};
2549 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2550 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2551 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2552 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2553 &command_pool);
2554
2555 VkCommandBuffer command_buffer[2];
2556 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2557 command_buffer_allocate_info.sType =
2558 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2559 command_buffer_allocate_info.commandPool = command_pool;
2560 command_buffer_allocate_info.commandBufferCount = 2;
2561 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2562 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2563 command_buffer);
2564
2565 {
2566 VkCommandBufferBeginInfo begin_info{};
2567 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2568 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2569
2570 vkCmdPipelineBarrier(command_buffer[0],
2571 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2572 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2573 0, nullptr, 0, nullptr);
2574
2575 VkViewport viewport{};
2576 viewport.maxDepth = 1.0f;
2577 viewport.minDepth = 0.0f;
2578 viewport.width = 512;
2579 viewport.height = 512;
2580 viewport.x = 0;
2581 viewport.y = 0;
2582 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2583 vkEndCommandBuffer(command_buffer[0]);
2584 }
2585 {
2586 VkCommandBufferBeginInfo begin_info{};
2587 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2588 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2589
2590 VkViewport viewport{};
2591 viewport.maxDepth = 1.0f;
2592 viewport.minDepth = 0.0f;
2593 viewport.width = 512;
2594 viewport.height = 512;
2595 viewport.x = 0;
2596 viewport.y = 0;
2597 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2598 vkEndCommandBuffer(command_buffer[1]);
2599 }
2600 {
2601 VkSubmitInfo submit_info{};
2602 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2603 submit_info.commandBufferCount = 1;
2604 submit_info.pCommandBuffers = &command_buffer[0];
2605 submit_info.signalSemaphoreCount = 0;
2606 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
2607 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2608 }
2609 {
2610 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2611 VkSubmitInfo submit_info{};
2612 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2613 submit_info.commandBufferCount = 1;
2614 submit_info.pCommandBuffers = &command_buffer[1];
2615 submit_info.waitSemaphoreCount = 0;
2616 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
2617 submit_info.pWaitDstStageMask = flags;
2618 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2619 }
2620
2621 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
2622
2623 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2624
2625 vkDestroyFence(m_device->device(), fence, nullptr);
2626 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2627 &command_buffer[0]);
2628 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2629
2630 m_errorMonitor->VerifyNotFound();
2631}
2632
2633// This is a positive test. No errors should be generated.
2634TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
2635
2636 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2637 "on the same queue, the second having a fence, followed "
2638 "by a WaitForFences call.");
2639
2640 m_errorMonitor->ExpectSuccess();
2641
2642 VkFence fence;
2643 VkFenceCreateInfo fence_create_info{};
2644 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2645 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2646
2647 VkCommandPool command_pool;
2648 VkCommandPoolCreateInfo pool_create_info{};
2649 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2650 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2651 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2652 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2653 &command_pool);
2654
2655 VkCommandBuffer command_buffer[2];
2656 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2657 command_buffer_allocate_info.sType =
2658 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2659 command_buffer_allocate_info.commandPool = command_pool;
2660 command_buffer_allocate_info.commandBufferCount = 2;
2661 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2662 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2663 command_buffer);
2664
2665 {
2666 VkCommandBufferBeginInfo begin_info{};
2667 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2668 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2669
2670 vkCmdPipelineBarrier(command_buffer[0],
2671 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2672 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2673 0, nullptr, 0, nullptr);
2674
2675 VkViewport viewport{};
2676 viewport.maxDepth = 1.0f;
2677 viewport.minDepth = 0.0f;
2678 viewport.width = 512;
2679 viewport.height = 512;
2680 viewport.x = 0;
2681 viewport.y = 0;
2682 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2683 vkEndCommandBuffer(command_buffer[0]);
2684 }
2685 {
2686 VkCommandBufferBeginInfo begin_info{};
2687 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2688 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2689
2690 VkViewport viewport{};
2691 viewport.maxDepth = 1.0f;
2692 viewport.minDepth = 0.0f;
2693 viewport.width = 512;
2694 viewport.height = 512;
2695 viewport.x = 0;
2696 viewport.y = 0;
2697 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2698 vkEndCommandBuffer(command_buffer[1]);
2699 }
2700 {
2701 VkSubmitInfo submit_info{};
2702 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2703 submit_info.commandBufferCount = 1;
2704 submit_info.pCommandBuffers = &command_buffer[0];
2705 submit_info.signalSemaphoreCount = 0;
2706 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
2707 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2708 }
2709 {
2710 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2711 VkSubmitInfo submit_info{};
2712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2713 submit_info.commandBufferCount = 1;
2714 submit_info.pCommandBuffers = &command_buffer[1];
2715 submit_info.waitSemaphoreCount = 0;
2716 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
2717 submit_info.pWaitDstStageMask = flags;
2718 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2719 }
2720
2721 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2722
2723 vkDestroyFence(m_device->device(), fence, nullptr);
2724 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2725 &command_buffer[0]);
2726 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2727
2728 m_errorMonitor->VerifyNotFound();
2729}
2730
2731// This is a positive test. No errors should be generated.
2732TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
2733
2734 TEST_DESCRIPTION(
2735 "Two command buffers each in a separate SubmitInfo sent in a single "
2736 "QueueSubmit call followed by a WaitForFences call.");
2737
2738 m_errorMonitor->ExpectSuccess();
2739
2740 VkFence fence;
2741 VkFenceCreateInfo fence_create_info{};
2742 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2743 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2744
2745 VkSemaphore semaphore;
2746 VkSemaphoreCreateInfo semaphore_create_info{};
2747 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2748 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2749 &semaphore);
2750
2751 VkCommandPool command_pool;
2752 VkCommandPoolCreateInfo pool_create_info{};
2753 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2754 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2755 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2756 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2757 &command_pool);
2758
2759 VkCommandBuffer command_buffer[2];
2760 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2761 command_buffer_allocate_info.sType =
2762 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2763 command_buffer_allocate_info.commandPool = command_pool;
2764 command_buffer_allocate_info.commandBufferCount = 2;
2765 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2766 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2767 command_buffer);
2768
2769 {
2770 VkCommandBufferBeginInfo begin_info{};
2771 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2772 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2773
2774 vkCmdPipelineBarrier(command_buffer[0],
2775 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2776 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2777 0, nullptr, 0, nullptr);
2778
2779 VkViewport viewport{};
2780 viewport.maxDepth = 1.0f;
2781 viewport.minDepth = 0.0f;
2782 viewport.width = 512;
2783 viewport.height = 512;
2784 viewport.x = 0;
2785 viewport.y = 0;
2786 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2787 vkEndCommandBuffer(command_buffer[0]);
2788 }
2789 {
2790 VkCommandBufferBeginInfo begin_info{};
2791 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2792 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2793
2794 VkViewport viewport{};
2795 viewport.maxDepth = 1.0f;
2796 viewport.minDepth = 0.0f;
2797 viewport.width = 512;
2798 viewport.height = 512;
2799 viewport.x = 0;
2800 viewport.y = 0;
2801 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2802 vkEndCommandBuffer(command_buffer[1]);
2803 }
2804 {
2805 VkSubmitInfo submit_info[2];
2806 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2807
2808 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2809 submit_info[0].pNext = NULL;
2810 submit_info[0].commandBufferCount = 1;
2811 submit_info[0].pCommandBuffers = &command_buffer[0];
2812 submit_info[0].signalSemaphoreCount = 1;
2813 submit_info[0].pSignalSemaphores = &semaphore;
2814 submit_info[0].waitSemaphoreCount = 0;
2815 submit_info[0].pWaitSemaphores = NULL;
2816 submit_info[0].pWaitDstStageMask = 0;
2817
2818 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2819 submit_info[1].pNext = NULL;
2820 submit_info[1].commandBufferCount = 1;
2821 submit_info[1].pCommandBuffers = &command_buffer[1];
2822 submit_info[1].waitSemaphoreCount = 1;
2823 submit_info[1].pWaitSemaphores = &semaphore;
2824 submit_info[1].pWaitDstStageMask = flags;
2825 submit_info[1].signalSemaphoreCount = 0;
2826 submit_info[1].pSignalSemaphores = NULL;
2827 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
2828 }
2829
2830 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2831
2832 vkDestroyFence(m_device->device(), fence, nullptr);
2833 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2834 &command_buffer[0]);
2835 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2836
2837 m_errorMonitor->VerifyNotFound();
2838}
2839
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002840TEST_F(VkLayerTest, DynamicStatesNotBound) {
2841 TEST_DESCRIPTION(
2842 "Run a series of simple draw calls to validate all the different "
2843 "failure cases that can occur when dynamic state is required but not "
2844 "correctly bound."
2845 "Here are the different dynamic state cases verified by this test:\n"
2846 "-Line Width\n-Depth Bias\n-Viewport State\n-Scissor State\n-Blend "
2847 "State\n-Depth Bounds\n-Stencil Read Mask\n-Stencil Write "
2848 "Mask\n-Stencil Reference");
2849
2850 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07002851 m_errorMonitor->SetDesiredFailureMsg(
2852 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002853 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002854 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2855 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002856 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002857 // Dynamic depth bias
Karl Schultz6addd812016-02-02 17:17:23 -07002858 m_errorMonitor->SetDesiredFailureMsg(
2859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002860 "Dynamic depth bias state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002861 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2862 BsoFailDepthBias);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002863 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002864 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07002865 m_errorMonitor->SetDesiredFailureMsg(
2866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002867 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002868 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2869 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002870 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002871 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07002872 m_errorMonitor->SetDesiredFailureMsg(
2873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002874 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002875 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2876 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002877 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002878 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07002879 m_errorMonitor->SetDesiredFailureMsg(
2880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002881 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002882 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2883 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002884 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002885 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07002886 m_errorMonitor->SetDesiredFailureMsg(
2887 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002888 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002889 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2890 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002891 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002892 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07002893 m_errorMonitor->SetDesiredFailureMsg(
2894 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002895 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002896 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2897 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002898 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002899 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07002900 m_errorMonitor->SetDesiredFailureMsg(
2901 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002902 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002903 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2904 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002905 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002906}
2907
Karl Schultz6addd812016-02-02 17:17:23 -07002908TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002909 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002910
Karl Schultz6addd812016-02-02 17:17:23 -07002911 m_errorMonitor->SetDesiredFailureMsg(
2912 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2913 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
2914 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002915
2916 VkFenceCreateInfo fenceInfo = {};
2917 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2918 fenceInfo.pNext = NULL;
2919 fenceInfo.flags = 0;
2920
2921 ASSERT_NO_FATAL_FAILURE(InitState());
2922 ASSERT_NO_FATAL_FAILURE(InitViewport());
2923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2924
Karl Schultz6addd812016-02-02 17:17:23 -07002925 // We luck out b/c by default the framework creates CB w/ the
2926 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002927 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002928 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2929 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002930 EndCommandBuffer();
2931
2932 testFence.init(*m_device, fenceInfo);
2933
2934 // Bypass framework since it does the waits automatically
2935 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002936 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002937 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2938 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002939 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002940 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002941 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002942 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002943 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002944 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002945 submit_info.pSignalSemaphores = NULL;
2946
Karl Schultz6addd812016-02-02 17:17:23 -07002947 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
2948 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002949
Karl Schultz6addd812016-02-02 17:17:23 -07002950 // Cause validation error by re-submitting cmd buffer that should only be
2951 // submitted once
2952 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002953
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002954 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002955}
2956
Karl Schultz6addd812016-02-02 17:17:23 -07002957TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002958 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07002959 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002960
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002962 "Unable to allocate 1 descriptors of "
2963 "type "
2964 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002965
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002966 ASSERT_NO_FATAL_FAILURE(InitState());
2967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002968
Karl Schultz6addd812016-02-02 17:17:23 -07002969 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
2970 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002971 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002972 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2973 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002974
2975 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002976 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2977 ds_pool_ci.pNext = NULL;
2978 ds_pool_ci.flags = 0;
2979 ds_pool_ci.maxSets = 1;
2980 ds_pool_ci.poolSizeCount = 1;
2981 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002982
2983 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002984 err =
2985 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002986 ASSERT_VK_SUCCESS(err);
2987
2988 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002989 dsl_binding.binding = 0;
2990 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2991 dsl_binding.descriptorCount = 1;
2992 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2993 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002994
2995 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002996 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2997 ds_layout_ci.pNext = NULL;
2998 ds_layout_ci.bindingCount = 1;
2999 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003000
3001 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3003 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003004 ASSERT_VK_SUCCESS(err);
3005
3006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003010 alloc_info.descriptorPool = ds_pool;
3011 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3013 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003015 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003016
Chia-I Wuf7458c52015-10-26 21:10:41 +08003017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003019}
3020
Karl Schultz6addd812016-02-02 17:17:23 -07003021TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3022 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003023
Karl Schultz6addd812016-02-02 17:17:23 -07003024 m_errorMonitor->SetDesiredFailureMsg(
3025 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3026 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3027 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003028
Tobin Ehlise735c692015-10-08 13:13:50 -06003029 ASSERT_NO_FATAL_FAILURE(InitState());
3030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003031
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003032 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003033 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3034 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003035
3036 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003037 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3038 ds_pool_ci.pNext = NULL;
3039 ds_pool_ci.maxSets = 1;
3040 ds_pool_ci.poolSizeCount = 1;
3041 ds_pool_ci.flags = 0;
3042 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3043 // app can only call vkResetDescriptorPool on this pool.;
3044 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003045
3046 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003047 err =
3048 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003049 ASSERT_VK_SUCCESS(err);
3050
3051 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003052 dsl_binding.binding = 0;
3053 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3054 dsl_binding.descriptorCount = 1;
3055 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3056 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003057
3058 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003059 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3060 ds_layout_ci.pNext = NULL;
3061 ds_layout_ci.bindingCount = 1;
3062 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003063
3064 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003065 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3066 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003067 ASSERT_VK_SUCCESS(err);
3068
3069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003073 alloc_info.descriptorPool = ds_pool;
3074 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3076 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003077 ASSERT_VK_SUCCESS(err);
3078
3079 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003080 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003081
Chia-I Wuf7458c52015-10-26 21:10:41 +08003082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003084}
3085
Karl Schultz6addd812016-02-02 17:17:23 -07003086TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003087 // Attempt to clear Descriptor Pool with bad object.
3088 // ObjectTracker should catch this.
3089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3090 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003091 uint64_t fake_pool_handle = 0xbaad6001;
3092 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3093 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003094 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003095}
3096
Karl Schultz6addd812016-02-02 17:17:23 -07003097TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003098 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3099 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003100 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003101 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003102
3103 uint64_t fake_set_handle = 0xbaad6001;
3104 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003105 VkResult err;
3106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "Invalid VkDescriptorSet Object 0xbaad6001");
3108
3109 ASSERT_NO_FATAL_FAILURE(InitState());
3110
3111 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3112 layout_bindings[0].binding = 0;
3113 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3114 layout_bindings[0].descriptorCount = 1;
3115 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3116 layout_bindings[0].pImmutableSamplers = NULL;
3117
3118 VkDescriptorSetLayout descriptor_set_layout;
3119 VkDescriptorSetLayoutCreateInfo dslci = {};
3120 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3121 dslci.pNext = NULL;
3122 dslci.bindingCount = 1;
3123 dslci.pBindings = layout_bindings;
3124 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003125 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003126
3127 VkPipelineLayout pipeline_layout;
3128 VkPipelineLayoutCreateInfo plci = {};
3129 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3130 plci.pNext = NULL;
3131 plci.setLayoutCount = 1;
3132 plci.pSetLayouts = &descriptor_set_layout;
3133 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003134 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003135
3136 BeginCommandBuffer();
3137 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003138 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003139 m_errorMonitor->VerifyFound();
3140 EndCommandBuffer();
3141 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3142 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003143}
3144
Karl Schultz6addd812016-02-02 17:17:23 -07003145TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003146 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3147 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003148 uint64_t fake_layout_handle = 0xbaad6001;
3149 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3151 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
3152
3153 VkPipelineLayout pipeline_layout;
3154 VkPipelineLayoutCreateInfo plci = {};
3155 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3156 plci.pNext = NULL;
3157 plci.setLayoutCount = 1;
3158 plci.pSetLayouts = &bad_layout;
3159 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3160
3161 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003162}
3163
Karl Schultz6addd812016-02-02 17:17:23 -07003164TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003165 // Attempt to bind an invalid Pipeline to a valid Command Buffer
3166 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003167 // Create a valid cmd buffer
3168 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003169 uint64_t fake_pipeline_handle = 0xbaad6001;
3170 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3172 "Invalid VkPipeline Object 0xbaad6001");
3173 ASSERT_NO_FATAL_FAILURE(InitState());
3174 BeginCommandBuffer();
3175 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3176 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
3177 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06003178
3179 // Now issue a draw call with no pipeline bound
3180 m_errorMonitor->SetDesiredFailureMsg(
3181 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3182 "At Draw/Dispatch time no valid VkPipeline is bound!");
3183 ASSERT_NO_FATAL_FAILURE(InitState());
3184 BeginCommandBuffer();
3185 Draw(1, 0, 0, 0);
3186 m_errorMonitor->VerifyFound();
3187 // Finally same check once more but with Dispatch/Compute
3188 m_errorMonitor->SetDesiredFailureMsg(
3189 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3190 "At Draw/Dispatch time no valid VkPipeline is bound!");
3191 ASSERT_NO_FATAL_FAILURE(InitState());
3192 BeginCommandBuffer();
3193 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
3194 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003195}
3196
Karl Schultz6addd812016-02-02 17:17:23 -07003197TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
3198 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
3199 // CommandBuffer
3200 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003201
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003203 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003204
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003205 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06003206 ASSERT_NO_FATAL_FAILURE(InitViewport());
3207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003208 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003209 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3210 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003211
3212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3214 ds_pool_ci.pNext = NULL;
3215 ds_pool_ci.maxSets = 1;
3216 ds_pool_ci.poolSizeCount = 1;
3217 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06003218
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003219 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003220 err =
3221 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003222 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003223
Tony Barboureb254902015-07-15 12:50:33 -06003224 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003225 dsl_binding.binding = 0;
3226 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3227 dsl_binding.descriptorCount = 1;
3228 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3229 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003230
Tony Barboureb254902015-07-15 12:50:33 -06003231 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003232 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3233 ds_layout_ci.pNext = NULL;
3234 ds_layout_ci.bindingCount = 1;
3235 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003236 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003237 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3238 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003239 ASSERT_VK_SUCCESS(err);
3240
3241 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003242 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003243 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003244 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003245 alloc_info.descriptorPool = ds_pool;
3246 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003247 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3248 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003249 ASSERT_VK_SUCCESS(err);
3250
Tony Barboureb254902015-07-15 12:50:33 -06003251 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003252 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3253 pipeline_layout_ci.pNext = NULL;
3254 pipeline_layout_ci.setLayoutCount = 1;
3255 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003256
3257 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003258 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3259 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003260 ASSERT_VK_SUCCESS(err);
3261
Karl Schultz6addd812016-02-02 17:17:23 -07003262 VkShaderObj vs(m_device, bindStateVertShaderText,
3263 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06003264 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07003265 // on more devices
3266 VkShaderObj fs(m_device, bindStateFragShaderText,
3267 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003268
Tony Barbourc95e4ac2015-08-04 17:05:26 -06003269 VkPipelineObj pipe(m_device);
3270 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003271 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06003272 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06003273 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003274
3275 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003276 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3277 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3278 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3279 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3280 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003282 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003283
Chia-I Wuf7458c52015-10-26 21:10:41 +08003284 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3285 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3286 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003287}
3288
Karl Schultz6addd812016-02-02 17:17:23 -07003289TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003290 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07003291 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003292
Karl Schultz6addd812016-02-02 17:17:23 -07003293 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003294 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
3295 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003296
3297 ASSERT_NO_FATAL_FAILURE(InitState());
3298 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003299 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3300 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003301
3302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3304 ds_pool_ci.pNext = NULL;
3305 ds_pool_ci.maxSets = 1;
3306 ds_pool_ci.poolSizeCount = 1;
3307 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003308
3309 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003310 err =
3311 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003312 ASSERT_VK_SUCCESS(err);
3313
3314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003315 dsl_binding.binding = 0;
3316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3317 dsl_binding.descriptorCount = 1;
3318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003320
3321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3323 ds_layout_ci.pNext = NULL;
3324 ds_layout_ci.bindingCount = 1;
3325 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003326 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3328 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003329 ASSERT_VK_SUCCESS(err);
3330
3331 VkDescriptorSet descriptorSet;
3332 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003334 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003335 alloc_info.descriptorPool = ds_pool;
3336 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3338 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003339 ASSERT_VK_SUCCESS(err);
3340
Karl Schultz6addd812016-02-02 17:17:23 -07003341 VkBufferView view =
3342 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003343 VkWriteDescriptorSet descriptor_write;
3344 memset(&descriptor_write, 0, sizeof(descriptor_write));
3345 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3346 descriptor_write.dstSet = descriptorSet;
3347 descriptor_write.dstBinding = 0;
3348 descriptor_write.descriptorCount = 1;
3349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3350 descriptor_write.pTexelBufferView = &view;
3351
3352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003354 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003355
3356 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3357 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3358}
3359
Karl Schultz6addd812016-02-02 17:17:23 -07003360TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
3361 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
3362 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07003363 // 1. No dynamicOffset supplied
3364 // 2. Too many dynamicOffsets supplied
3365 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07003366 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003368 " requires 1 dynamicOffsets, but only "
3369 "0 dynamicOffsets are left in "
3370 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003371
3372 ASSERT_NO_FATAL_FAILURE(InitState());
3373 ASSERT_NO_FATAL_FAILURE(InitViewport());
3374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3375
3376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3378 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003379
3380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3382 ds_pool_ci.pNext = NULL;
3383 ds_pool_ci.maxSets = 1;
3384 ds_pool_ci.poolSizeCount = 1;
3385 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003386
3387 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003388 err =
3389 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003390 ASSERT_VK_SUCCESS(err);
3391
3392 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003393 dsl_binding.binding = 0;
3394 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3395 dsl_binding.descriptorCount = 1;
3396 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3397 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003398
3399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3401 ds_layout_ci.pNext = NULL;
3402 ds_layout_ci.bindingCount = 1;
3403 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003404 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3406 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003407 ASSERT_VK_SUCCESS(err);
3408
3409 VkDescriptorSet descriptorSet;
3410 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003411 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003412 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003413 alloc_info.descriptorPool = ds_pool;
3414 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003415 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3416 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003417 ASSERT_VK_SUCCESS(err);
3418
3419 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003420 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3421 pipeline_layout_ci.pNext = NULL;
3422 pipeline_layout_ci.setLayoutCount = 1;
3423 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003424
3425 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003426 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3427 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003428 ASSERT_VK_SUCCESS(err);
3429
3430 // Create a buffer to update the descriptor with
3431 uint32_t qfi = 0;
3432 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003433 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3434 buffCI.size = 1024;
3435 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3436 buffCI.queueFamilyIndexCount = 1;
3437 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003438
3439 VkBuffer dyub;
3440 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3441 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003442 // Allocate memory and bind to buffer so we can make it to the appropriate
3443 // error
3444 VkMemoryAllocateInfo mem_alloc = {};
3445 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3446 mem_alloc.pNext = NULL;
3447 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12003448 mem_alloc.memoryTypeIndex = 0;
3449
3450 VkMemoryRequirements memReqs;
3451 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
3452 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
3453 0);
3454 if (!pass) {
3455 vkDestroyBuffer(m_device->device(), dyub, NULL);
3456 return;
3457 }
3458
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003459 VkDeviceMemory mem;
3460 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3461 ASSERT_VK_SUCCESS(err);
3462 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
3463 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003464 // Correctly update descriptor to avoid "NOT_UPDATED" error
3465 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003466 buffInfo.buffer = dyub;
3467 buffInfo.offset = 0;
3468 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003469
3470 VkWriteDescriptorSet descriptor_write;
3471 memset(&descriptor_write, 0, sizeof(descriptor_write));
3472 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3473 descriptor_write.dstSet = descriptorSet;
3474 descriptor_write.dstBinding = 0;
3475 descriptor_write.descriptorCount = 1;
3476 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3477 descriptor_write.pBufferInfo = &buffInfo;
3478
3479 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3480
3481 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003482 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3483 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3484 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003485 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07003486 uint32_t pDynOff[2] = {512, 756};
3487 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07003488 m_errorMonitor->SetDesiredFailureMsg(
3489 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07003490 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07003491 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3492 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3493 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12003494 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07003495 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3497 " dynamic offset 512 combined with "
3498 "offset 0 and range 1024 that "
3499 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07003500 // Create PSO to be used for draw-time errors below
3501 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003502 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003503 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07003504 "out gl_PerVertex { \n"
3505 " vec4 gl_Position;\n"
3506 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003507 "void main(){\n"
3508 " gl_Position = vec4(1);\n"
3509 "}\n";
3510 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003511 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003512 "\n"
3513 "layout(location=0) out vec4 x;\n"
3514 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3515 "void main(){\n"
3516 " x = vec4(bar.y);\n"
3517 "}\n";
3518 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3519 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3520 VkPipelineObj pipe(m_device);
3521 pipe.AddShader(&vs);
3522 pipe.AddShader(&fs);
3523 pipe.AddColorAttachment();
3524 pipe.CreateVKPipeline(pipeline_layout, renderPass());
3525
Karl Schultz6addd812016-02-02 17:17:23 -07003526 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3527 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3528 // This update should succeed, but offset size of 512 will overstep buffer
3529 // /w range 1024 & size 1024
3530 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3531 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3532 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07003533 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003534 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003535
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003536 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06003537 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003538
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003539 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3541}
3542
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003543TEST_F(VkLayerTest, InvalidPushConstants) {
3544 // Hit push constant error cases:
3545 // 1. Create PipelineLayout where push constant overstep maxPushConstantSize
3546 // 2. Incorrectly set push constant size to 0
3547 // 3. Incorrectly set push constant size to non-multiple of 4
3548 // 4. Attempt push constant update that exceeds maxPushConstantSize
3549 VkResult err;
3550 m_errorMonitor->SetDesiredFailureMsg(
3551 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3552 "vkCreatePipelineLayout() call has push constants with offset ");
3553
3554 ASSERT_NO_FATAL_FAILURE(InitState());
3555 ASSERT_NO_FATAL_FAILURE(InitViewport());
3556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3557
3558 VkPushConstantRange pc_range = {};
3559 pc_range.size = 0xFFFFFFFFu;
3560 pc_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3561 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3562 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3563 pipeline_layout_ci.pushConstantRangeCount = 1;
3564 pipeline_layout_ci.pPushConstantRanges = &pc_range;
3565
3566 VkPipelineLayout pipeline_layout;
3567 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3568 &pipeline_layout);
3569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003570 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003571 // Now cause errors due to size 0 and non-4 byte aligned size
3572 pc_range.size = 0;
3573 m_errorMonitor->SetDesiredFailureMsg(
3574 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3575 "vkCreatePipelineLayout() call has push constant index 0 with size 0");
3576 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3577 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003578 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003579 pc_range.size = 1;
3580 m_errorMonitor->SetDesiredFailureMsg(
3581 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3582 "vkCreatePipelineLayout() call has push constant index 0 with size 1");
3583 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3584 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003585 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003586 // Cause error due to bad size in vkCmdPushConstants() call
3587 m_errorMonitor->SetDesiredFailureMsg(
3588 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3589 "vkCmdPushConstants() call has push constants with offset ");
3590 pipeline_layout_ci.pushConstantRangeCount = 0;
3591 pipeline_layout_ci.pPushConstantRanges = NULL;
3592 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3593 &pipeline_layout);
3594 ASSERT_VK_SUCCESS(err);
3595 BeginCommandBuffer();
3596 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
3597 VK_SHADER_STAGE_VERTEX_BIT, 0, 0xFFFFFFFFu, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003598 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003599 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3600}
3601
Karl Schultz6addd812016-02-02 17:17:23 -07003602TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07003603 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07003604 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003605
3606 ASSERT_NO_FATAL_FAILURE(InitState());
3607 ASSERT_NO_FATAL_FAILURE(InitViewport());
3608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3609
3610 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
3611 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003612 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3613 ds_type_count[0].descriptorCount = 10;
3614 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
3615 ds_type_count[1].descriptorCount = 2;
3616 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
3617 ds_type_count[2].descriptorCount = 2;
3618 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
3619 ds_type_count[3].descriptorCount = 5;
3620 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
3621 // type
3622 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3623 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3624 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003625
3626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3628 ds_pool_ci.pNext = NULL;
3629 ds_pool_ci.maxSets = 5;
3630 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
3631 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003632
3633 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003634 err =
3635 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003636 ASSERT_VK_SUCCESS(err);
3637
3638 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
3639 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003640 dsl_binding[0].binding = 0;
3641 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3642 dsl_binding[0].descriptorCount = 5;
3643 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3644 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003645
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003646 // Create layout identical to set0 layout but w/ different stageFlags
3647 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003648 dsl_fs_stage_only.binding = 0;
3649 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3650 dsl_fs_stage_only.descriptorCount = 5;
3651 dsl_fs_stage_only.stageFlags =
3652 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
3653 // bind time
3654 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003655 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003656 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3657 ds_layout_ci.pNext = NULL;
3658 ds_layout_ci.bindingCount = 1;
3659 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003660 static const uint32_t NUM_LAYOUTS = 4;
3661 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003662 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003663 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
3664 // layout for error case
3665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3666 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003667 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003668 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003669 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3670 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003671 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003672 dsl_binding[0].binding = 0;
3673 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003674 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003675 dsl_binding[1].binding = 1;
3676 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
3677 dsl_binding[1].descriptorCount = 2;
3678 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3679 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003680 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003681 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07003682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3683 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003684 ASSERT_VK_SUCCESS(err);
3685 dsl_binding[0].binding = 0;
3686 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003687 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003688 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07003689 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3690 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003691 ASSERT_VK_SUCCESS(err);
3692 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003693 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07003694 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3695 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003696 ASSERT_VK_SUCCESS(err);
3697
3698 static const uint32_t NUM_SETS = 4;
3699 VkDescriptorSet descriptorSet[NUM_SETS] = {};
3700 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003702 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003703 alloc_info.descriptorPool = ds_pool;
3704 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3706 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003707 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003708 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07003709 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003710 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003711 err =
3712 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003713 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003714
3715 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003716 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3717 pipeline_layout_ci.pNext = NULL;
3718 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
3719 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003720
3721 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003722 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3723 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003724 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003725 // Create pipelineLayout with only one setLayout
3726 pipeline_layout_ci.setLayoutCount = 1;
3727 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003728 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3729 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003730 ASSERT_VK_SUCCESS(err);
3731 // Create pipelineLayout with 2 descriptor setLayout at index 0
3732 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
3733 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07003734 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3735 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003736 ASSERT_VK_SUCCESS(err);
3737 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
3738 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
3739 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07003740 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3741 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003742 ASSERT_VK_SUCCESS(err);
3743 // Create pipelineLayout with UB type, but stageFlags for FS only
3744 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
3745 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003746 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3747 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003748 ASSERT_VK_SUCCESS(err);
3749 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
3750 VkDescriptorSetLayout pl_bad_s0[2] = {};
3751 pl_bad_s0[0] = ds_layout_fs_only;
3752 pl_bad_s0[1] = ds_layout[1];
3753 pipeline_layout_ci.setLayoutCount = 2;
3754 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
3755 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07003756 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3757 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003758 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003759
3760 // Create a buffer to update the descriptor with
3761 uint32_t qfi = 0;
3762 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003763 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3764 buffCI.size = 1024;
3765 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3766 buffCI.queueFamilyIndexCount = 1;
3767 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003768
3769 VkBuffer dyub;
3770 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3771 ASSERT_VK_SUCCESS(err);
3772 // Correctly update descriptor to avoid "NOT_UPDATED" error
3773 static const uint32_t NUM_BUFFS = 5;
3774 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003775 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07003776 buffInfo[i].buffer = dyub;
3777 buffInfo[i].offset = 0;
3778 buffInfo[i].range = 1024;
3779 }
Karl Schultz6addd812016-02-02 17:17:23 -07003780 VkImage image;
3781 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3782 const int32_t tex_width = 32;
3783 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003784 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003785 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3786 image_create_info.pNext = NULL;
3787 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3788 image_create_info.format = tex_format;
3789 image_create_info.extent.width = tex_width;
3790 image_create_info.extent.height = tex_height;
3791 image_create_info.extent.depth = 1;
3792 image_create_info.mipLevels = 1;
3793 image_create_info.arrayLayers = 1;
3794 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3795 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3796 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3797 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003798 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3799 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003800
Karl Schultz6addd812016-02-02 17:17:23 -07003801 VkMemoryRequirements memReqs;
3802 VkDeviceMemory imageMem;
3803 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003804 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003805 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3806 memAlloc.pNext = NULL;
3807 memAlloc.allocationSize = 0;
3808 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003809 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
3810 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07003811 pass =
3812 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003813 ASSERT_TRUE(pass);
3814 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
3815 ASSERT_VK_SUCCESS(err);
3816 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
3817 ASSERT_VK_SUCCESS(err);
3818
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003819 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003820 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3821 image_view_create_info.image = image;
3822 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
3823 image_view_create_info.format = tex_format;
3824 image_view_create_info.subresourceRange.layerCount = 1;
3825 image_view_create_info.subresourceRange.baseMipLevel = 0;
3826 image_view_create_info.subresourceRange.levelCount = 1;
3827 image_view_create_info.subresourceRange.aspectMask =
3828 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003829
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003830 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07003831 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
3832 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003833 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003834 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003835 imageInfo[0].imageView = view;
3836 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3837 imageInfo[1].imageView = view;
3838 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003839 imageInfo[2].imageView = view;
3840 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3841 imageInfo[3].imageView = view;
3842 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003843
3844 static const uint32_t NUM_SET_UPDATES = 3;
3845 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
3846 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3847 descriptor_write[0].dstSet = descriptorSet[0];
3848 descriptor_write[0].dstBinding = 0;
3849 descriptor_write[0].descriptorCount = 5;
3850 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3851 descriptor_write[0].pBufferInfo = buffInfo;
3852 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3853 descriptor_write[1].dstSet = descriptorSet[1];
3854 descriptor_write[1].dstBinding = 0;
3855 descriptor_write[1].descriptorCount = 2;
3856 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
3857 descriptor_write[1].pImageInfo = imageInfo;
3858 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3859 descriptor_write[2].dstSet = descriptorSet[1];
3860 descriptor_write[2].dstBinding = 1;
3861 descriptor_write[2].descriptorCount = 2;
3862 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003863 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003864
3865 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003866
Tobin Ehlis88452832015-12-03 09:40:56 -07003867 // Create PSO to be used for draw-time errors below
3868 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003869 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003870 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07003871 "out gl_PerVertex {\n"
3872 " vec4 gl_Position;\n"
3873 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003874 "void main(){\n"
3875 " gl_Position = vec4(1);\n"
3876 "}\n";
3877 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003878 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003879 "\n"
3880 "layout(location=0) out vec4 x;\n"
3881 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3882 "void main(){\n"
3883 " x = vec4(bar.y);\n"
3884 "}\n";
3885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003887 VkPipelineObj pipe(m_device);
3888 pipe.AddShader(&vs);
3889 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07003890 pipe.AddColorAttachment();
3891 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07003892
3893 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07003894
Karl Schultz6addd812016-02-02 17:17:23 -07003895 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3896 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3897 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
3898 // of PSO
3899 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
3900 // cmd_pipeline.c
3901 // due to the fact that cmd_alloc_dset_data() has not been called in
3902 // cmd_bind_graphics_pipeline()
3903 // TODO : Want to cause various binding incompatibility issues here to test
3904 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07003905 // First cause various verify_layout_compatibility() fails
3906 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003907 // verify_set_layout_compatibility fail cases:
3908 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07003909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3910 " due to: invalid VkPipelineLayout ");
3911 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3912 VK_PIPELINE_BIND_POINT_GRAPHICS,
3913 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
3914 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003915 m_errorMonitor->VerifyFound();
3916
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003917 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07003918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3919 " attempting to bind set to index 1");
3920 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3921 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
3922 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003923 m_errorMonitor->VerifyFound();
3924
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003925 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003926 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
3927 // descriptors
3928 m_errorMonitor->SetDesiredFailureMsg(
3929 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003930 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07003931 vkCmdBindDescriptorSets(
3932 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3933 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003934 m_errorMonitor->VerifyFound();
3935
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003936 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
3937 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07003938 m_errorMonitor->SetDesiredFailureMsg(
3939 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003940 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07003941 vkCmdBindDescriptorSets(
3942 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3943 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003944 m_errorMonitor->VerifyFound();
3945
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003946 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
3947 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07003948 m_errorMonitor->SetDesiredFailureMsg(
3949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003950 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07003951 vkCmdBindDescriptorSets(
3952 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3953 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003954 m_errorMonitor->VerifyFound();
3955
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003956 // Cause INFO messages due to disturbing previously bound Sets
3957 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07003958 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3959 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3960 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003961 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07003962 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003963 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003964 " previously bound as set #0 was disturbed ");
3965 vkCmdBindDescriptorSets(
3966 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3967 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003968 m_errorMonitor->VerifyFound();
3969
Karl Schultz6addd812016-02-02 17:17:23 -07003970 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3971 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3972 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003973 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003975 " newly bound as set #0 so set #1 and "
3976 "any subsequent sets were disturbed ");
3977 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3978 VK_PIPELINE_BIND_POINT_GRAPHICS,
3979 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003980 m_errorMonitor->VerifyFound();
3981
Tobin Ehlis88452832015-12-03 09:40:56 -07003982 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07003983 // 1. Error due to not binding required set (we actually use same code as
3984 // above to disturb set0)
3985 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3986 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3987 2, &descriptorSet[0], 0, NULL);
3988 vkCmdBindDescriptorSets(
3989 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3990 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
3991 m_errorMonitor->SetDesiredFailureMsg(
3992 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3993 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07003994 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003995 m_errorMonitor->VerifyFound();
3996
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003997 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003998 // 2. Error due to bound set not being compatible with PSO's
3999 // VkPipelineLayout (diff stageFlags in this case)
4000 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
4001 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
4002 2, &descriptorSet[0], 0, NULL);
4003 m_errorMonitor->SetDesiredFailureMsg(
4004 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4005 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07004006 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004007 m_errorMonitor->VerifyFound();
4008
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004009 // Remaining clean-up
4010 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07004011 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
4013 }
4014 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06004015 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
4016 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004017 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07004018 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4020}
Tobin Ehlis559c6382015-11-05 09:52:49 -07004021
Karl Schultz6addd812016-02-02 17:17:23 -07004022TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004023
Karl Schultz6addd812016-02-02 17:17:23 -07004024 m_errorMonitor->SetDesiredFailureMsg(
4025 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004026 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004027
4028 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004029 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004030 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004031 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004032
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004033 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004034}
4035
Karl Schultz6addd812016-02-02 17:17:23 -07004036TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
4037 VkResult err;
4038 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004039
Karl Schultz6addd812016-02-02 17:17:23 -07004040 m_errorMonitor->SetDesiredFailureMsg(
4041 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004042 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004043
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004044 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004045
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004046 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004047 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06004048 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004049 cmd.commandPool = m_commandPool;
4050 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004051 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06004052
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004053 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06004054 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004055
4056 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004057 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07004058 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004059 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06004060 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07004061 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
4062 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004063 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004064
4065 // The error should be caught by validation of the BeginCommandBuffer call
4066 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
4067
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004068 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004069 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004070}
4071
Karl Schultz6addd812016-02-02 17:17:23 -07004072TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004073 // Cause error due to Begin while recording CB
4074 // Then cause 2 errors for attempting to reset CB w/o having
4075 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
4076 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004078 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004079
4080 ASSERT_NO_FATAL_FAILURE(InitState());
4081
4082 // Calls AllocateCommandBuffers
4083 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
4084
Karl Schultz6addd812016-02-02 17:17:23 -07004085 // Force the failure by setting the Renderpass and Framebuffer fields with
4086 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004087 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07004088 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004089 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4090 cmd_buf_info.pNext = NULL;
4091 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004092 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004093
4094 // Begin CB to transition to recording state
4095 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
4096 // Can't re-begin. This should trigger error
4097 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004098 m_errorMonitor->VerifyFound();
4099
Karl Schultz6addd812016-02-02 17:17:23 -07004100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4101 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004102 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
4103 // Reset attempt will trigger error due to incorrect CommandPool state
4104 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004105 m_errorMonitor->VerifyFound();
4106
Karl Schultz6addd812016-02-02 17:17:23 -07004107 m_errorMonitor->SetDesiredFailureMsg(
4108 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4109 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004110 // Transition CB to RECORDED state
4111 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
4112 // Now attempting to Begin will implicitly reset, which triggers error
4113 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004114 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004115}
4116
Karl Schultz6addd812016-02-02 17:17:23 -07004117TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004118 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07004119 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004120
Karl Schultz6addd812016-02-02 17:17:23 -07004121 m_errorMonitor->SetDesiredFailureMsg(
4122 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004123 "Invalid Pipeline CreateInfo State: Vtx Shader required");
4124
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004125 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004127
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4130 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004131
4132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4134 ds_pool_ci.pNext = NULL;
4135 ds_pool_ci.maxSets = 1;
4136 ds_pool_ci.poolSizeCount = 1;
4137 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004138
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004139 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004140 err =
4141 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004142 ASSERT_VK_SUCCESS(err);
4143
Tony Barboureb254902015-07-15 12:50:33 -06004144 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004145 dsl_binding.binding = 0;
4146 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4147 dsl_binding.descriptorCount = 1;
4148 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4149 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004150
Tony Barboureb254902015-07-15 12:50:33 -06004151 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004152 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4153 ds_layout_ci.pNext = NULL;
4154 ds_layout_ci.bindingCount = 1;
4155 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004156
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004157 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4159 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004160 ASSERT_VK_SUCCESS(err);
4161
4162 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004163 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004164 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004165 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004166 alloc_info.descriptorPool = ds_pool;
4167 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004168 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4169 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004170 ASSERT_VK_SUCCESS(err);
4171
Tony Barboureb254902015-07-15 12:50:33 -06004172 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004173 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4174 pipeline_layout_ci.setLayoutCount = 1;
4175 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004176
4177 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004178 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4179 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004180 ASSERT_VK_SUCCESS(err);
4181
Tobin Ehlise68360f2015-10-01 11:15:13 -06004182 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07004183 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06004184
4185 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004186 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4187 vp_state_ci.scissorCount = 1;
4188 vp_state_ci.pScissors = &sc;
4189 vp_state_ci.viewportCount = 1;
4190 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004191
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004192 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4193 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4194 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4195 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4196 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4197 rs_state_ci.depthClampEnable = VK_FALSE;
4198 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4199 rs_state_ci.depthBiasEnable = VK_FALSE;
4200
Tony Barboureb254902015-07-15 12:50:33 -06004201 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004202 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4203 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004204 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004205 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4206 gp_ci.layout = pipeline_layout;
4207 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06004208
4209 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004210 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4211 pc_ci.initialDataSize = 0;
4212 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004213
4214 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06004215 VkPipelineCache pipelineCache;
4216
Karl Schultz6addd812016-02-02 17:17:23 -07004217 err =
4218 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004219 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004220 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4221 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004222
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004223 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004224
Chia-I Wuf7458c52015-10-26 21:10:41 +08004225 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4226 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4227 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4228 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004229}
Tobin Ehlis912df022015-09-17 08:46:18 -06004230/*// TODO : This test should be good, but needs Tess support in compiler to run
4231TEST_F(VkLayerTest, InvalidPatchControlPoints)
4232{
4233 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06004234 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004235
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004237 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
4238primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004239
Tobin Ehlis912df022015-09-17 08:46:18 -06004240 ASSERT_NO_FATAL_FAILURE(InitState());
4241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06004242
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004243 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06004244 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004245 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004246
4247 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4248 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4249 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004250 ds_pool_ci.poolSizeCount = 1;
4251 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06004252
4253 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004254 err = vkCreateDescriptorPool(m_device->device(),
4255VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06004256 ASSERT_VK_SUCCESS(err);
4257
4258 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004259 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06004260 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004261 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004262 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4263 dsl_binding.pImmutableSamplers = NULL;
4264
4265 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004266 ds_layout_ci.sType =
4267VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06004268 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004269 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004270 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06004271
4272 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4274&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06004275 ASSERT_VK_SUCCESS(err);
4276
4277 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07004278 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
4279VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06004280 ASSERT_VK_SUCCESS(err);
4281
4282 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004283 pipeline_layout_ci.sType =
4284VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06004285 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004286 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004287 pipeline_layout_ci.pSetLayouts = &ds_layout;
4288
4289 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004290 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4291&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06004292 ASSERT_VK_SUCCESS(err);
4293
4294 VkPipelineShaderStageCreateInfo shaderStages[3];
4295 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
4296
Karl Schultz6addd812016-02-02 17:17:23 -07004297 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
4298this);
Tobin Ehlis912df022015-09-17 08:46:18 -06004299 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07004300 VkShaderObj
4301tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4302this);
4303 VkShaderObj
4304te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
4305this);
Tobin Ehlis912df022015-09-17 08:46:18 -06004306
Karl Schultz6addd812016-02-02 17:17:23 -07004307 shaderStages[0].sType =
4308VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004309 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004310 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07004311 shaderStages[1].sType =
4312VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004313 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004314 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07004315 shaderStages[2].sType =
4316VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004317 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004318 shaderStages[2].shader = te.handle();
4319
4320 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004321 iaCI.sType =
4322VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08004323 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06004324
4325 VkPipelineTessellationStateCreateInfo tsCI = {};
4326 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
4327 tsCI.patchControlPoints = 0; // This will cause an error
4328
4329 VkGraphicsPipelineCreateInfo gp_ci = {};
4330 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4331 gp_ci.pNext = NULL;
4332 gp_ci.stageCount = 3;
4333 gp_ci.pStages = shaderStages;
4334 gp_ci.pVertexInputState = NULL;
4335 gp_ci.pInputAssemblyState = &iaCI;
4336 gp_ci.pTessellationState = &tsCI;
4337 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004338 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06004339 gp_ci.pMultisampleState = NULL;
4340 gp_ci.pDepthStencilState = NULL;
4341 gp_ci.pColorBlendState = NULL;
4342 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4343 gp_ci.layout = pipeline_layout;
4344 gp_ci.renderPass = renderPass();
4345
4346 VkPipelineCacheCreateInfo pc_ci = {};
4347 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4348 pc_ci.pNext = NULL;
4349 pc_ci.initialSize = 0;
4350 pc_ci.initialData = 0;
4351 pc_ci.maxSize = 0;
4352
4353 VkPipeline pipeline;
4354 VkPipelineCache pipelineCache;
4355
Karl Schultz6addd812016-02-02 17:17:23 -07004356 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
4357&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06004358 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004359 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4360&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06004361
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004362 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004363
Chia-I Wuf7458c52015-10-26 21:10:41 +08004364 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4365 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06004368}
4369*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06004370// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07004371TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07004372 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004373
Karl Schultz6addd812016-02-02 17:17:23 -07004374 m_errorMonitor->SetDesiredFailureMsg(
4375 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004376 "Gfx Pipeline viewport count (1) must match scissor count (0).");
4377
Tobin Ehlise68360f2015-10-01 11:15:13 -06004378 ASSERT_NO_FATAL_FAILURE(InitState());
4379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004380
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004381 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4383 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004384
4385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4387 ds_pool_ci.maxSets = 1;
4388 ds_pool_ci.poolSizeCount = 1;
4389 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004390
4391 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004392 err =
4393 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004394 ASSERT_VK_SUCCESS(err);
4395
4396 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004397 dsl_binding.binding = 0;
4398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4399 dsl_binding.descriptorCount = 1;
4400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004401
4402 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004403 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4404 ds_layout_ci.bindingCount = 1;
4405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004406
4407 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4409 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004410 ASSERT_VK_SUCCESS(err);
4411
4412 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004413 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004415 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004416 alloc_info.descriptorPool = ds_pool;
4417 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4419 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004420 ASSERT_VK_SUCCESS(err);
4421
4422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4424 pipeline_layout_ci.setLayoutCount = 1;
4425 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004426
4427 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004428 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4429 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004430 ASSERT_VK_SUCCESS(err);
4431
4432 VkViewport vp = {}; // Just need dummy vp to point to
4433
4434 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004435 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4436 vp_state_ci.scissorCount = 0;
4437 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
4438 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004439
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004440 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4441 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4442 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4443 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4444 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4445 rs_state_ci.depthClampEnable = VK_FALSE;
4446 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4447 rs_state_ci.depthBiasEnable = VK_FALSE;
4448
Cody Northropeb3a6c12015-10-05 14:44:45 -06004449 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004450 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004451
Karl Schultz6addd812016-02-02 17:17:23 -07004452 VkShaderObj vs(m_device, bindStateVertShaderText,
4453 VK_SHADER_STAGE_VERTEX_BIT, this);
4454 VkShaderObj fs(m_device, bindStateFragShaderText,
4455 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004456 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004457 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004458 shaderStages[0] = vs.GetStageCreateInfo();
4459 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004460
4461 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004462 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4463 gp_ci.stageCount = 2;
4464 gp_ci.pStages = shaderStages;
4465 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004466 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004467 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4468 gp_ci.layout = pipeline_layout;
4469 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004470
4471 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004472 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004473
4474 VkPipeline pipeline;
4475 VkPipelineCache pipelineCache;
4476
Karl Schultz6addd812016-02-02 17:17:23 -07004477 err =
4478 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004479 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004480 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4481 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004482
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004483 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004484
Chia-I Wuf7458c52015-10-26 21:10:41 +08004485 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4486 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4487 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4488 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004489}
Karl Schultz6addd812016-02-02 17:17:23 -07004490// Don't set viewport state in PSO. This is an error b/c we always need this
4491// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06004492// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07004493TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06004494 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07004495 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004496
Karl Schultz6addd812016-02-02 17:17:23 -07004497 m_errorMonitor->SetDesiredFailureMsg(
4498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004499 "Gfx Pipeline pViewportState is null. Even if ");
4500
Tobin Ehlise68360f2015-10-01 11:15:13 -06004501 ASSERT_NO_FATAL_FAILURE(InitState());
4502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004503
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004504 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004505 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4506 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004507
4508 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004509 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4510 ds_pool_ci.maxSets = 1;
4511 ds_pool_ci.poolSizeCount = 1;
4512 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004513
4514 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004515 err =
4516 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004517 ASSERT_VK_SUCCESS(err);
4518
4519 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004520 dsl_binding.binding = 0;
4521 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4522 dsl_binding.descriptorCount = 1;
4523 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004524
4525 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004526 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4527 ds_layout_ci.bindingCount = 1;
4528 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004529
4530 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004531 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4532 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004533 ASSERT_VK_SUCCESS(err);
4534
4535 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004536 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004537 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004538 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004539 alloc_info.descriptorPool = ds_pool;
4540 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004541 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4542 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004543 ASSERT_VK_SUCCESS(err);
4544
4545 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004546 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4547 pipeline_layout_ci.setLayoutCount = 1;
4548 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004549
4550 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004551 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4552 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004553 ASSERT_VK_SUCCESS(err);
4554
4555 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
4556 // Set scissor as dynamic to avoid second error
4557 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004558 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4559 dyn_state_ci.dynamicStateCount = 1;
4560 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004561
Cody Northropeb3a6c12015-10-05 14:44:45 -06004562 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004563 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004564
Karl Schultz6addd812016-02-02 17:17:23 -07004565 VkShaderObj vs(m_device, bindStateVertShaderText,
4566 VK_SHADER_STAGE_VERTEX_BIT, this);
4567 VkShaderObj fs(m_device, bindStateFragShaderText,
4568 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004569 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004570 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004571 shaderStages[0] = vs.GetStageCreateInfo();
4572 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004573
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004574
4575 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4576 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4577 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4578 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4579 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4580 rs_state_ci.depthClampEnable = VK_FALSE;
4581 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4582 rs_state_ci.depthBiasEnable = VK_FALSE;
4583
Tobin Ehlise68360f2015-10-01 11:15:13 -06004584 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004585 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4586 gp_ci.stageCount = 2;
4587 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004588 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004589 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
4590 // should cause validation error
4591 gp_ci.pDynamicState = &dyn_state_ci;
4592 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4593 gp_ci.layout = pipeline_layout;
4594 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004595
4596 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004597 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004598
4599 VkPipeline pipeline;
4600 VkPipelineCache pipelineCache;
4601
Karl Schultz6addd812016-02-02 17:17:23 -07004602 err =
4603 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004604 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004605 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4606 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004607
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004608 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004609
Chia-I Wuf7458c52015-10-26 21:10:41 +08004610 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4611 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4613 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004614}
4615// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07004616// Then run second test where dynamic scissor count doesn't match PSO scissor
4617// count
4618TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
4619 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004620
Karl Schultz6addd812016-02-02 17:17:23 -07004621 m_errorMonitor->SetDesiredFailureMsg(
4622 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004623 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
4624
Tobin Ehlise68360f2015-10-01 11:15:13 -06004625 ASSERT_NO_FATAL_FAILURE(InitState());
4626 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004627
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004628 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004629 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4630 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004631
4632 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004633 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4634 ds_pool_ci.maxSets = 1;
4635 ds_pool_ci.poolSizeCount = 1;
4636 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004637
4638 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004639 err =
4640 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004641 ASSERT_VK_SUCCESS(err);
4642
4643 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004644 dsl_binding.binding = 0;
4645 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4646 dsl_binding.descriptorCount = 1;
4647 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004648
4649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4651 ds_layout_ci.bindingCount = 1;
4652 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004653
4654 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004655 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4656 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004657 ASSERT_VK_SUCCESS(err);
4658
4659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004662 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004663 alloc_info.descriptorPool = ds_pool;
4664 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4666 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004667 ASSERT_VK_SUCCESS(err);
4668
4669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4671 pipeline_layout_ci.setLayoutCount = 1;
4672 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004673
4674 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004675 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4676 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004677 ASSERT_VK_SUCCESS(err);
4678
4679 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004680 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4681 vp_state_ci.viewportCount = 1;
4682 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
4683 vp_state_ci.scissorCount = 1;
4684 vp_state_ci.pScissors =
4685 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06004686
4687 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
4688 // Set scissor as dynamic to avoid that error
4689 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004690 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4691 dyn_state_ci.dynamicStateCount = 1;
4692 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004693
Cody Northropeb3a6c12015-10-05 14:44:45 -06004694 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004695 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004696
Karl Schultz6addd812016-02-02 17:17:23 -07004697 VkShaderObj vs(m_device, bindStateVertShaderText,
4698 VK_SHADER_STAGE_VERTEX_BIT, this);
4699 VkShaderObj fs(m_device, bindStateFragShaderText,
4700 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004701 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004702 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004703 shaderStages[0] = vs.GetStageCreateInfo();
4704 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004705
Cody Northropf6622dc2015-10-06 10:33:21 -06004706 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4707 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4708 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004709 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06004710 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004711 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06004712 vi_ci.pVertexAttributeDescriptions = nullptr;
4713
4714 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4715 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4716 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4717
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004718 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004719 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06004720 rs_ci.pNext = nullptr;
4721
Mark Youngc89c6312016-03-31 16:03:20 -06004722 VkPipelineColorBlendAttachmentState att = {};
4723 att.blendEnable = VK_FALSE;
4724 att.colorWriteMask = 0xf;
4725
Cody Northropf6622dc2015-10-06 10:33:21 -06004726 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4727 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4728 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06004729 cb_ci.attachmentCount = 1;
4730 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06004731
Tobin Ehlise68360f2015-10-01 11:15:13 -06004732 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004733 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4734 gp_ci.stageCount = 2;
4735 gp_ci.pStages = shaderStages;
4736 gp_ci.pVertexInputState = &vi_ci;
4737 gp_ci.pInputAssemblyState = &ia_ci;
4738 gp_ci.pViewportState = &vp_state_ci;
4739 gp_ci.pRasterizationState = &rs_ci;
4740 gp_ci.pColorBlendState = &cb_ci;
4741 gp_ci.pDynamicState = &dyn_state_ci;
4742 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4743 gp_ci.layout = pipeline_layout;
4744 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004745
4746 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004747 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004748
4749 VkPipeline pipeline;
4750 VkPipelineCache pipelineCache;
4751
Karl Schultz6addd812016-02-02 17:17:23 -07004752 err =
4753 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004754 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004755 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4756 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004757
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004758 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004759
Tobin Ehlisd332f282015-10-02 11:00:56 -06004760 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07004761 // First need to successfully create the PSO from above by setting
4762 // pViewports
4763 m_errorMonitor->SetDesiredFailureMsg(
4764 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4765 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
4766 "scissorCount is 1. These counts must match.");
4767
4768 VkViewport vp = {}; // Just need dummy vp to point to
4769 vp_state_ci.pViewports = &vp;
4770 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4771 &gp_ci, NULL, &pipeline);
4772 ASSERT_VK_SUCCESS(err);
4773 BeginCommandBuffer();
4774 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4775 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4776 VkRect2D scissors[2] = {}; // don't care about data
4777 // Count of 2 doesn't match PSO count of 1
4778 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
4779 Draw(1, 0, 0, 0);
4780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004781 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07004782
4783 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4787}
4788// Create PSO w/o non-zero scissorCount but no scissor data
4789// Then run second test where dynamic viewportCount doesn't match PSO
4790// viewportCount
4791TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
4792 VkResult err;
4793
4794 m_errorMonitor->SetDesiredFailureMsg(
4795 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4796 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
4797
4798 ASSERT_NO_FATAL_FAILURE(InitState());
4799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4800
4801 VkDescriptorPoolSize ds_type_count = {};
4802 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4803 ds_type_count.descriptorCount = 1;
4804
4805 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4806 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4807 ds_pool_ci.maxSets = 1;
4808 ds_pool_ci.poolSizeCount = 1;
4809 ds_pool_ci.pPoolSizes = &ds_type_count;
4810
4811 VkDescriptorPool ds_pool;
4812 err =
4813 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkDescriptorSetLayoutBinding dsl_binding = {};
4817 dsl_binding.binding = 0;
4818 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4819 dsl_binding.descriptorCount = 1;
4820 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4821
4822 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4823 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4824 ds_layout_ci.bindingCount = 1;
4825 ds_layout_ci.pBindings = &dsl_binding;
4826
4827 VkDescriptorSetLayout ds_layout;
4828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4829 &ds_layout);
4830 ASSERT_VK_SUCCESS(err);
4831
4832 VkDescriptorSet descriptorSet;
4833 VkDescriptorSetAllocateInfo alloc_info = {};
4834 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4835 alloc_info.descriptorSetCount = 1;
4836 alloc_info.descriptorPool = ds_pool;
4837 alloc_info.pSetLayouts = &ds_layout;
4838 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4839 &descriptorSet);
4840 ASSERT_VK_SUCCESS(err);
4841
4842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4844 pipeline_layout_ci.setLayoutCount = 1;
4845 pipeline_layout_ci.pSetLayouts = &ds_layout;
4846
4847 VkPipelineLayout pipeline_layout;
4848 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4849 &pipeline_layout);
4850 ASSERT_VK_SUCCESS(err);
4851
4852 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4853 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4854 vp_state_ci.scissorCount = 1;
4855 vp_state_ci.pScissors =
4856 NULL; // Null scissor w/ count of 1 should cause error
4857 vp_state_ci.viewportCount = 1;
4858 vp_state_ci.pViewports =
4859 NULL; // vp is dynamic (below) so this won't cause error
4860
4861 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
4862 // Set scissor as dynamic to avoid that error
4863 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
4864 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4865 dyn_state_ci.dynamicStateCount = 1;
4866 dyn_state_ci.pDynamicStates = &vp_state;
4867
4868 VkPipelineShaderStageCreateInfo shaderStages[2];
4869 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4870
4871 VkShaderObj vs(m_device, bindStateVertShaderText,
4872 VK_SHADER_STAGE_VERTEX_BIT, this);
4873 VkShaderObj fs(m_device, bindStateFragShaderText,
4874 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004875 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004876 // but add it to be able to run on more devices
4877 shaderStages[0] = vs.GetStageCreateInfo();
4878 shaderStages[1] = fs.GetStageCreateInfo();
4879
4880 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4881 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4882 vi_ci.pNext = nullptr;
4883 vi_ci.vertexBindingDescriptionCount = 0;
4884 vi_ci.pVertexBindingDescriptions = nullptr;
4885 vi_ci.vertexAttributeDescriptionCount = 0;
4886 vi_ci.pVertexAttributeDescriptions = nullptr;
4887
4888 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4889 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4890 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4891
4892 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4893 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4894 rs_ci.pNext = nullptr;
4895
Mark Youngc89c6312016-03-31 16:03:20 -06004896 VkPipelineColorBlendAttachmentState att = {};
4897 att.blendEnable = VK_FALSE;
4898 att.colorWriteMask = 0xf;
4899
Karl Schultz6addd812016-02-02 17:17:23 -07004900 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4901 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4902 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06004903 cb_ci.attachmentCount = 1;
4904 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07004905
4906 VkGraphicsPipelineCreateInfo gp_ci = {};
4907 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4908 gp_ci.stageCount = 2;
4909 gp_ci.pStages = shaderStages;
4910 gp_ci.pVertexInputState = &vi_ci;
4911 gp_ci.pInputAssemblyState = &ia_ci;
4912 gp_ci.pViewportState = &vp_state_ci;
4913 gp_ci.pRasterizationState = &rs_ci;
4914 gp_ci.pColorBlendState = &cb_ci;
4915 gp_ci.pDynamicState = &dyn_state_ci;
4916 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4917 gp_ci.layout = pipeline_layout;
4918 gp_ci.renderPass = renderPass();
4919
4920 VkPipelineCacheCreateInfo pc_ci = {};
4921 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4922
4923 VkPipeline pipeline;
4924 VkPipelineCache pipelineCache;
4925
4926 err =
4927 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4928 ASSERT_VK_SUCCESS(err);
4929 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4930 &gp_ci, NULL, &pipeline);
4931
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004932 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07004933
4934 // Now hit second fail case where we set scissor w/ different count than PSO
4935 // First need to successfully create the PSO from above by setting
4936 // pViewports
4937 m_errorMonitor->SetDesiredFailureMsg(
4938 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4939 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
4940 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004941
Tobin Ehlisd332f282015-10-02 11:00:56 -06004942 VkRect2D sc = {}; // Just need dummy vp to point to
4943 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07004944 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4945 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004946 ASSERT_VK_SUCCESS(err);
4947 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004948 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4949 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004950 VkViewport viewports[2] = {}; // don't care about data
4951 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004952 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004953 Draw(1, 0, 0, 0);
4954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004955 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004956
Chia-I Wuf7458c52015-10-26 21:10:41 +08004957 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4958 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004961}
4962
Mark Young7394fdd2016-03-31 14:56:43 -06004963TEST_F(VkLayerTest, PSOLineWidthInvalid) {
4964 VkResult err;
4965
4966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06004967 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06004968
4969 ASSERT_NO_FATAL_FAILURE(InitState());
4970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4971
4972 VkDescriptorPoolSize ds_type_count = {};
4973 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4974 ds_type_count.descriptorCount = 1;
4975
4976 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4977 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4978 ds_pool_ci.maxSets = 1;
4979 ds_pool_ci.poolSizeCount = 1;
4980 ds_pool_ci.pPoolSizes = &ds_type_count;
4981
4982 VkDescriptorPool ds_pool;
4983 err =
4984 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4985 ASSERT_VK_SUCCESS(err);
4986
4987 VkDescriptorSetLayoutBinding dsl_binding = {};
4988 dsl_binding.binding = 0;
4989 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4990 dsl_binding.descriptorCount = 1;
4991 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4992
4993 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4994 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4995 ds_layout_ci.bindingCount = 1;
4996 ds_layout_ci.pBindings = &dsl_binding;
4997
4998 VkDescriptorSetLayout ds_layout;
4999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5000 &ds_layout);
5001 ASSERT_VK_SUCCESS(err);
5002
5003 VkDescriptorSet descriptorSet;
5004 VkDescriptorSetAllocateInfo alloc_info = {};
5005 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5006 alloc_info.descriptorSetCount = 1;
5007 alloc_info.descriptorPool = ds_pool;
5008 alloc_info.pSetLayouts = &ds_layout;
5009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5010 &descriptorSet);
5011 ASSERT_VK_SUCCESS(err);
5012
5013 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5014 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5015 pipeline_layout_ci.setLayoutCount = 1;
5016 pipeline_layout_ci.pSetLayouts = &ds_layout;
5017
5018 VkPipelineLayout pipeline_layout;
5019 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
5020 &pipeline_layout);
5021 ASSERT_VK_SUCCESS(err);
5022
5023 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5024 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5025 vp_state_ci.scissorCount = 1;
5026 vp_state_ci.pScissors = NULL;
5027 vp_state_ci.viewportCount = 1;
5028 vp_state_ci.pViewports = NULL;
5029
5030 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
5031 VK_DYNAMIC_STATE_SCISSOR,
5032 VK_DYNAMIC_STATE_LINE_WIDTH};
5033 // Set scissor as dynamic to avoid that error
5034 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
5035 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
5036 dyn_state_ci.dynamicStateCount = 2;
5037 dyn_state_ci.pDynamicStates = dynamic_states;
5038
5039 VkPipelineShaderStageCreateInfo shaderStages[2];
5040 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5041
5042 VkShaderObj vs(m_device, bindStateVertShaderText,
5043 VK_SHADER_STAGE_VERTEX_BIT, this);
5044 VkShaderObj fs(m_device, bindStateFragShaderText,
5045 VK_SHADER_STAGE_FRAGMENT_BIT,
5046 this); // TODO - We shouldn't need a fragment shader
5047 // but add it to be able to run on more devices
5048 shaderStages[0] = vs.GetStageCreateInfo();
5049 shaderStages[1] = fs.GetStageCreateInfo();
5050
5051 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5052 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5053 vi_ci.pNext = nullptr;
5054 vi_ci.vertexBindingDescriptionCount = 0;
5055 vi_ci.pVertexBindingDescriptions = nullptr;
5056 vi_ci.vertexAttributeDescriptionCount = 0;
5057 vi_ci.pVertexAttributeDescriptions = nullptr;
5058
5059 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5060 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5061 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5062
5063 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5064 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5065 rs_ci.pNext = nullptr;
5066
Mark Young47107952016-05-02 15:59:55 -06005067 // Check too low (line width of -1.0f).
5068 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06005069
5070 VkPipelineColorBlendAttachmentState att = {};
5071 att.blendEnable = VK_FALSE;
5072 att.colorWriteMask = 0xf;
5073
5074 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5075 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5076 cb_ci.pNext = nullptr;
5077 cb_ci.attachmentCount = 1;
5078 cb_ci.pAttachments = &att;
5079
5080 VkGraphicsPipelineCreateInfo gp_ci = {};
5081 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5082 gp_ci.stageCount = 2;
5083 gp_ci.pStages = shaderStages;
5084 gp_ci.pVertexInputState = &vi_ci;
5085 gp_ci.pInputAssemblyState = &ia_ci;
5086 gp_ci.pViewportState = &vp_state_ci;
5087 gp_ci.pRasterizationState = &rs_ci;
5088 gp_ci.pColorBlendState = &cb_ci;
5089 gp_ci.pDynamicState = &dyn_state_ci;
5090 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5091 gp_ci.layout = pipeline_layout;
5092 gp_ci.renderPass = renderPass();
5093
5094 VkPipelineCacheCreateInfo pc_ci = {};
5095 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5096
5097 VkPipeline pipeline;
5098 VkPipelineCache pipelineCache;
5099
5100 err =
5101 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5102 ASSERT_VK_SUCCESS(err);
5103 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5104 &gp_ci, NULL, &pipeline);
5105
5106 m_errorMonitor->VerifyFound();
5107
5108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5109 "Attempt to set lineWidth to 65536");
5110
5111 // Check too high (line width of 65536.0f).
5112 rs_ci.lineWidth = 65536.0f;
5113
5114 err =
5115 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5116 ASSERT_VK_SUCCESS(err);
5117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5118 &gp_ci, NULL, &pipeline);
5119
5120 m_errorMonitor->VerifyFound();
5121
5122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06005123 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06005124
5125 dyn_state_ci.dynamicStateCount = 3;
5126
5127 rs_ci.lineWidth = 1.0f;
5128
5129 err =
5130 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5131 ASSERT_VK_SUCCESS(err);
5132 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5133 &gp_ci, NULL, &pipeline);
5134 BeginCommandBuffer();
5135 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5136 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5137
5138 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06005139 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06005140 m_errorMonitor->VerifyFound();
5141
5142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5143 "Attempt to set lineWidth to 65536");
5144
5145 // Check too high with dynamic setting.
5146 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
5147 m_errorMonitor->VerifyFound();
5148 EndCommandBuffer();
5149
5150 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5154}
5155
Karl Schultz6addd812016-02-02 17:17:23 -07005156TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005157 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005158 m_errorMonitor->SetDesiredFailureMsg(
5159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005160 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005161
5162 ASSERT_NO_FATAL_FAILURE(InitState());
5163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005164
Tony Barbourfe3351b2015-07-28 10:17:20 -06005165 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005166 // Don't care about RenderPass handle b/c error should be flagged before
5167 // that
5168 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
5169 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005170
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005171 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005172}
5173
Karl Schultz6addd812016-02-02 17:17:23 -07005174TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005175 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005176 m_errorMonitor->SetDesiredFailureMsg(
5177 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005178 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005179
5180 ASSERT_NO_FATAL_FAILURE(InitState());
5181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005182
Tony Barbourfe3351b2015-07-28 10:17:20 -06005183 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005184 // Just create a dummy Renderpass that's non-NULL so we can get to the
5185 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06005186 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005187 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
5188 rp_begin.pNext = NULL;
5189 rp_begin.renderPass = renderPass();
5190 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005191
Karl Schultz6addd812016-02-02 17:17:23 -07005192 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
5193 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005194
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005195 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005196}
5197
Karl Schultz6addd812016-02-02 17:17:23 -07005198TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005199 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07005200 m_errorMonitor->SetDesiredFailureMsg(
5201 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005202 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005203
5204 ASSERT_NO_FATAL_FAILURE(InitState());
5205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005206
5207 // Renderpass is started here
5208 BeginCommandBuffer();
5209
5210 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005211 vk_testing::Buffer dstBuffer;
5212 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005213
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005214 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005215
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005216 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005217}
5218
Karl Schultz6addd812016-02-02 17:17:23 -07005219TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005220 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07005221 m_errorMonitor->SetDesiredFailureMsg(
5222 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005223 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005224
5225 ASSERT_NO_FATAL_FAILURE(InitState());
5226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005227
5228 // Renderpass is started here
5229 BeginCommandBuffer();
5230
5231 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005232 vk_testing::Buffer dstBuffer;
5233 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005234
Karl Schultz6addd812016-02-02 17:17:23 -07005235 VkDeviceSize dstOffset = 0;
5236 VkDeviceSize dataSize = 1024;
5237 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005238
Karl Schultz6addd812016-02-02 17:17:23 -07005239 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
5240 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005241
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005242 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005243}
5244
Karl Schultz6addd812016-02-02 17:17:23 -07005245TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005246 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005247 m_errorMonitor->SetDesiredFailureMsg(
5248 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005249 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005250
5251 ASSERT_NO_FATAL_FAILURE(InitState());
5252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005253
5254 // Renderpass is started here
5255 BeginCommandBuffer();
5256
Michael Lentine0a369f62016-02-03 16:51:46 -06005257 VkClearColorValue clear_color;
5258 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07005259 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5260 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5261 const int32_t tex_width = 32;
5262 const int32_t tex_height = 32;
5263 VkImageCreateInfo image_create_info = {};
5264 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5265 image_create_info.pNext = NULL;
5266 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5267 image_create_info.format = tex_format;
5268 image_create_info.extent.width = tex_width;
5269 image_create_info.extent.height = tex_height;
5270 image_create_info.extent.depth = 1;
5271 image_create_info.mipLevels = 1;
5272 image_create_info.arrayLayers = 1;
5273 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5274 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5275 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005276
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005277 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07005278 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
5279 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005280
Karl Schultz6addd812016-02-02 17:17:23 -07005281 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
5282 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005283
Karl Schultz6addd812016-02-02 17:17:23 -07005284 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
5285 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005286
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005287 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005288}
5289
Karl Schultz6addd812016-02-02 17:17:23 -07005290TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005291 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005292 m_errorMonitor->SetDesiredFailureMsg(
5293 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005294 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005295
5296 ASSERT_NO_FATAL_FAILURE(InitState());
5297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005298
5299 // Renderpass is started here
5300 BeginCommandBuffer();
5301
5302 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07005303 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005304 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
5305 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5306 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
5307 image_create_info.extent.width = 64;
5308 image_create_info.extent.height = 64;
5309 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5310 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005311
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005312 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07005313 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
5314 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005315
Karl Schultz6addd812016-02-02 17:17:23 -07005316 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
5317 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005318
Karl Schultz6addd812016-02-02 17:17:23 -07005319 vkCmdClearDepthStencilImage(
5320 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
5321 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
5322 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005324 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005325}
5326
Karl Schultz6addd812016-02-02 17:17:23 -07005327TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005328 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005329 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005330
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005332 "vkCmdClearAttachments: This call "
5333 "must be issued inside an active "
5334 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005335
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005336 ASSERT_NO_FATAL_FAILURE(InitState());
5337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005338
5339 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005340 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005341 ASSERT_VK_SUCCESS(err);
5342
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005343 VkClearAttachment color_attachment;
5344 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5345 color_attachment.clearValue.color.float32[0] = 0;
5346 color_attachment.clearValue.color.float32[1] = 0;
5347 color_attachment.clearValue.color.float32[2] = 0;
5348 color_attachment.clearValue.color.float32[3] = 0;
5349 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005350 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
5351 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
5352 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005353
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005354 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005355}
5356
Karl Schultz9e66a292016-04-21 15:57:51 -06005357TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
5358 // Try to add a buffer memory barrier with no buffer.
5359 m_errorMonitor->SetDesiredFailureMsg(
5360 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5361 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
5362
5363 ASSERT_NO_FATAL_FAILURE(InitState());
5364 BeginCommandBuffer();
5365
5366 VkBufferMemoryBarrier buf_barrier = {};
5367 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
5368 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5369 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5370 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5371 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5372 buf_barrier.buffer = VK_NULL_HANDLE;
5373 buf_barrier.offset = 0;
5374 buf_barrier.size = VK_WHOLE_SIZE;
5375 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5376 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
5377 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
5378
5379 m_errorMonitor->VerifyFound();
5380}
5381
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06005382TEST_F(VkLayerTest, InvalidBarriers) {
5383 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
5384
5385 m_errorMonitor->SetDesiredFailureMsg(
5386 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
5387
5388 ASSERT_NO_FATAL_FAILURE(InitState());
5389 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5390
5391 VkMemoryBarrier mem_barrier = {};
5392 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
5393 mem_barrier.pNext = NULL;
5394 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5395 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5396 BeginCommandBuffer();
5397 // BeginCommandBuffer() starts a render pass
5398 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5399 VK_PIPELINE_STAGE_HOST_BIT,
5400 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
5401 &mem_barrier, 0, nullptr, 0, nullptr);
5402 m_errorMonitor->VerifyFound();
5403
5404 m_errorMonitor->SetDesiredFailureMsg(
5405 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5406 "Image Layout cannot be transitioned to UNDEFINED");
5407 VkImageObj image(m_device);
5408 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
5409 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5410 ASSERT_TRUE(image.initialized());
5411 VkImageMemoryBarrier img_barrier = {};
5412 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
5413 img_barrier.pNext = NULL;
5414 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5415 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5416 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5417 // New layout can't be UNDEFINED
5418 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5419 img_barrier.image = image.handle();
5420 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5421 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5422 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5423 img_barrier.subresourceRange.baseArrayLayer = 0;
5424 img_barrier.subresourceRange.baseMipLevel = 0;
5425 img_barrier.subresourceRange.layerCount = 1;
5426 img_barrier.subresourceRange.levelCount = 1;
5427 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5428 VK_PIPELINE_STAGE_HOST_BIT,
5429 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5430 nullptr, 1, &img_barrier);
5431 m_errorMonitor->VerifyFound();
5432 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5433
5434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5435 "Subresource must have the sum of the "
5436 "baseArrayLayer");
5437 // baseArrayLayer + layerCount must be <= image's arrayLayers
5438 img_barrier.subresourceRange.baseArrayLayer = 1;
5439 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5440 VK_PIPELINE_STAGE_HOST_BIT,
5441 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5442 nullptr, 1, &img_barrier);
5443 m_errorMonitor->VerifyFound();
5444 img_barrier.subresourceRange.baseArrayLayer = 0;
5445
5446 m_errorMonitor->SetDesiredFailureMsg(
5447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5448 "Subresource must have the sum of the baseMipLevel");
5449 // baseMipLevel + levelCount must be <= image's mipLevels
5450 img_barrier.subresourceRange.baseMipLevel = 1;
5451 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5452 VK_PIPELINE_STAGE_HOST_BIT,
5453 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5454 nullptr, 1, &img_barrier);
5455 m_errorMonitor->VerifyFound();
5456 img_barrier.subresourceRange.baseMipLevel = 0;
5457
5458 m_errorMonitor->SetDesiredFailureMsg(
5459 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5460 "Buffer Barriers cannot be used during a render pass");
5461 vk_testing::Buffer buffer;
5462 buffer.init(*m_device, 256);
5463 VkBufferMemoryBarrier buf_barrier = {};
5464 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
5465 buf_barrier.pNext = NULL;
5466 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5467 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5468 buf_barrier.buffer = buffer.handle();
5469 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5470 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5471 buf_barrier.offset = 0;
5472 buf_barrier.size = VK_WHOLE_SIZE;
5473 // Can't send buffer barrier during a render pass
5474 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5475 VK_PIPELINE_STAGE_HOST_BIT,
5476 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5477 &buf_barrier, 0, nullptr);
5478 m_errorMonitor->VerifyFound();
5479 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
5480
5481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5482 "which is not less than total size");
5483 buf_barrier.offset = 257;
5484 // Offset greater than total size
5485 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5486 VK_PIPELINE_STAGE_HOST_BIT,
5487 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5488 &buf_barrier, 0, nullptr);
5489 m_errorMonitor->VerifyFound();
5490 buf_barrier.offset = 0;
5491
5492 m_errorMonitor->SetDesiredFailureMsg(
5493 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
5494 buf_barrier.size = 257;
5495 // Size greater than total size
5496 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5497 VK_PIPELINE_STAGE_HOST_BIT,
5498 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5499 &buf_barrier, 0, nullptr);
5500 m_errorMonitor->VerifyFound();
5501 buf_barrier.size = VK_WHOLE_SIZE;
5502
5503 m_errorMonitor->SetDesiredFailureMsg(
5504 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5505 "Image is a depth and stencil format and thus must "
5506 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
5507 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
5508 VkDepthStencilObj ds_image(m_device);
5509 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
5510 ASSERT_TRUE(ds_image.initialized());
5511 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5512 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
5513 img_barrier.image = ds_image.handle();
5514 // Leave aspectMask at COLOR on purpose
5515 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5516 VK_PIPELINE_STAGE_HOST_BIT,
5517 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5518 nullptr, 1, &img_barrier);
5519 m_errorMonitor->VerifyFound();
5520}
5521
Karl Schultz6addd812016-02-02 17:17:23 -07005522TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005523 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005524 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005525
Karl Schultz6addd812016-02-02 17:17:23 -07005526 m_errorMonitor->SetDesiredFailureMsg(
5527 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005528 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
5529
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005530 ASSERT_NO_FATAL_FAILURE(InitState());
5531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005532 uint32_t qfi = 0;
5533 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005534 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5535 buffCI.size = 1024;
5536 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
5537 buffCI.queueFamilyIndexCount = 1;
5538 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005539
5540 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005541 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005542 ASSERT_VK_SUCCESS(err);
5543
5544 BeginCommandBuffer();
5545 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005546 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5547 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005548 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07005549 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
5550 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005551
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005552 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005553
Chia-I Wuf7458c52015-10-26 21:10:41 +08005554 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005555}
5556
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005557TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
5558 // Create an out-of-range queueFamilyIndex
5559 m_errorMonitor->SetDesiredFailureMsg(
5560 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis24aab042016-03-24 10:54:18 -06005561 "queueFamilyIndex 777, must have been given when the device was created.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005562
5563 ASSERT_NO_FATAL_FAILURE(InitState());
5564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5565 VkBufferCreateInfo buffCI = {};
5566 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5567 buffCI.size = 1024;
5568 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
5569 buffCI.queueFamilyIndexCount = 1;
5570 // Introduce failure by specifying invalid queue_family_index
5571 uint32_t qfi = 777;
5572 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06005573 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005574
5575 VkBuffer ib;
5576 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
5577
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005578 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005579}
5580
Karl Schultz6addd812016-02-02 17:17:23 -07005581TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
5582 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
5583 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005584
Karl Schultz6addd812016-02-02 17:17:23 -07005585 m_errorMonitor->SetDesiredFailureMsg(
5586 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005587 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005588
5589 ASSERT_NO_FATAL_FAILURE(InitState());
5590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005591
5592 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005593 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005594 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
5595 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005596
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005597 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005598}
5599
Karl Schultz6addd812016-02-02 17:17:23 -07005600TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005601 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07005602 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005603
Karl Schultz6addd812016-02-02 17:17:23 -07005604 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005605 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5606 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
5607 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005608
Tobin Ehlis3b780662015-05-28 12:11:26 -06005609 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005610 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005611 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005612 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5613 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005614
5615 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005616 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5617 ds_pool_ci.pNext = NULL;
5618 ds_pool_ci.maxSets = 1;
5619 ds_pool_ci.poolSizeCount = 1;
5620 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005621
Tobin Ehlis3b780662015-05-28 12:11:26 -06005622 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005623 err =
5624 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005625 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06005626 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005627 dsl_binding.binding = 0;
5628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5629 dsl_binding.descriptorCount = 1;
5630 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5631 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005632
Tony Barboureb254902015-07-15 12:50:33 -06005633 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005634 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5635 ds_layout_ci.pNext = NULL;
5636 ds_layout_ci.bindingCount = 1;
5637 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005638
Tobin Ehlis3b780662015-05-28 12:11:26 -06005639 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5641 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005642 ASSERT_VK_SUCCESS(err);
5643
5644 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005645 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005647 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005648 alloc_info.descriptorPool = ds_pool;
5649 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005650 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5651 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005652 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005653
Tobin Ehlis30db8f82016-05-05 08:19:48 -06005654 VkSamplerCreateInfo sampler_ci = {};
5655 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5656 sampler_ci.pNext = NULL;
5657 sampler_ci.magFilter = VK_FILTER_NEAREST;
5658 sampler_ci.minFilter = VK_FILTER_NEAREST;
5659 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5660 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5661 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5662 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5663 sampler_ci.mipLodBias = 1.0;
5664 sampler_ci.anisotropyEnable = VK_FALSE;
5665 sampler_ci.maxAnisotropy = 1;
5666 sampler_ci.compareEnable = VK_FALSE;
5667 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5668 sampler_ci.minLod = 1.0;
5669 sampler_ci.maxLod = 1.0;
5670 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5671 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5672 VkSampler sampler;
5673 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5674 ASSERT_VK_SUCCESS(err);
5675
5676 VkDescriptorImageInfo info = {};
5677 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005678
5679 VkWriteDescriptorSet descriptor_write;
5680 memset(&descriptor_write, 0, sizeof(descriptor_write));
5681 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005682 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005683 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005684 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005685 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005686 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005687
5688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005690 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005691
Chia-I Wuf7458c52015-10-26 21:10:41 +08005692 vkDestroySampler(m_device->device(), sampler, NULL);
5693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005695}
5696
Karl Schultz6addd812016-02-02 17:17:23 -07005697TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005698 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07005699 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005700
Karl Schultz6addd812016-02-02 17:17:23 -07005701 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005702 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5703 " binding #0 with 1 total descriptors but update of 1 descriptors "
5704 "starting at binding offset of 0 combined with update array element "
5705 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005706
Tobin Ehlis3b780662015-05-28 12:11:26 -06005707 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005708 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5711 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005712
5713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5715 ds_pool_ci.pNext = NULL;
5716 ds_pool_ci.maxSets = 1;
5717 ds_pool_ci.poolSizeCount = 1;
5718 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005719
Tobin Ehlis3b780662015-05-28 12:11:26 -06005720 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005721 err =
5722 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005723 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005724
Tony Barboureb254902015-07-15 12:50:33 -06005725 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005726 dsl_binding.binding = 0;
5727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5728 dsl_binding.descriptorCount = 1;
5729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5730 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06005731
5732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5734 ds_layout_ci.pNext = NULL;
5735 ds_layout_ci.bindingCount = 1;
5736 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005737
Tobin Ehlis3b780662015-05-28 12:11:26 -06005738 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5740 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005741 ASSERT_VK_SUCCESS(err);
5742
5743 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005744 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005745 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005746 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005747 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 Ehlis3b780662015-05-28 12:11:26 -06005751 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005752
Tobin Ehlis30db8f82016-05-05 08:19:48 -06005753 // Correctly update descriptor to avoid "NOT_UPDATED" error
5754 VkDescriptorBufferInfo buff_info = {};
5755 buff_info.buffer =
5756 VkBuffer(0); // Don't care about buffer handle for this test
5757 buff_info.offset = 0;
5758 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005759
5760 VkWriteDescriptorSet descriptor_write;
5761 memset(&descriptor_write, 0, sizeof(descriptor_write));
5762 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005763 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005764 descriptor_write.dstArrayElement =
5765 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08005766 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005767 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5768 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005769
5770 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5771
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005772 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005773
Chia-I Wuf7458c52015-10-26 21:10:41 +08005774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005776}
5777
Karl Schultz6addd812016-02-02 17:17:23 -07005778TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
5779 // Create layout w/ count of 1 and attempt update to that layout w/ binding
5780 // index 2
5781 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005782
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5784 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005785
Tobin Ehlis3b780662015-05-28 12:11:26 -06005786 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005787 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005788 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5790 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005791
5792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5794 ds_pool_ci.pNext = NULL;
5795 ds_pool_ci.maxSets = 1;
5796 ds_pool_ci.poolSizeCount = 1;
5797 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005798
Tobin Ehlis3b780662015-05-28 12:11:26 -06005799 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005800 err =
5801 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005802 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005803
Tony Barboureb254902015-07-15 12:50:33 -06005804 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005805 dsl_binding.binding = 0;
5806 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5807 dsl_binding.descriptorCount = 1;
5808 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5809 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06005810
5811 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005812 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5813 ds_layout_ci.pNext = NULL;
5814 ds_layout_ci.bindingCount = 1;
5815 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005816 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005817 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5818 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005819 ASSERT_VK_SUCCESS(err);
5820
5821 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005822 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005823 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005824 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005825 alloc_info.descriptorPool = ds_pool;
5826 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005827 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5828 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005829 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005830
Tony Barboureb254902015-07-15 12:50:33 -06005831 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005832 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5833 sampler_ci.pNext = NULL;
5834 sampler_ci.magFilter = VK_FILTER_NEAREST;
5835 sampler_ci.minFilter = VK_FILTER_NEAREST;
5836 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5837 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5838 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5839 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5840 sampler_ci.mipLodBias = 1.0;
5841 sampler_ci.anisotropyEnable = VK_FALSE;
5842 sampler_ci.maxAnisotropy = 1;
5843 sampler_ci.compareEnable = VK_FALSE;
5844 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5845 sampler_ci.minLod = 1.0;
5846 sampler_ci.maxLod = 1.0;
5847 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5848 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06005849
Tobin Ehlis3b780662015-05-28 12:11:26 -06005850 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005851 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005852 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005853
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005854 VkDescriptorImageInfo info = {};
5855 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005856
5857 VkWriteDescriptorSet descriptor_write;
5858 memset(&descriptor_write, 0, sizeof(descriptor_write));
5859 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005860 descriptor_write.dstSet = descriptorSet;
5861 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005862 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005863 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005864 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005865 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005866
5867 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5868
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005869 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005870
Chia-I Wuf7458c52015-10-26 21:10:41 +08005871 vkDestroySampler(m_device->device(), sampler, NULL);
5872 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5873 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005874}
5875
Karl Schultz6addd812016-02-02 17:17:23 -07005876TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
5877 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
5878 // types
5879 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005880
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005882 "Unexpected UPDATE struct of type ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005883
Tobin Ehlis3b780662015-05-28 12:11:26 -06005884 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005885
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005886 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005887 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5888 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005889
5890 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005891 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5892 ds_pool_ci.pNext = NULL;
5893 ds_pool_ci.maxSets = 1;
5894 ds_pool_ci.poolSizeCount = 1;
5895 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005896
Tobin Ehlis3b780662015-05-28 12:11:26 -06005897 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005898 err =
5899 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005900 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06005901 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005902 dsl_binding.binding = 0;
5903 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5904 dsl_binding.descriptorCount = 1;
5905 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5906 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005907
Tony Barboureb254902015-07-15 12:50:33 -06005908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5910 ds_layout_ci.pNext = NULL;
5911 ds_layout_ci.bindingCount = 1;
5912 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005913
Tobin Ehlis3b780662015-05-28 12:11:26 -06005914 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5916 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005917 ASSERT_VK_SUCCESS(err);
5918
5919 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005920 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005921 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005922 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005923 alloc_info.descriptorPool = ds_pool;
5924 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005925 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5926 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005927 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005928
Tony Barboureb254902015-07-15 12:50:33 -06005929 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005930 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5931 sampler_ci.pNext = NULL;
5932 sampler_ci.magFilter = VK_FILTER_NEAREST;
5933 sampler_ci.minFilter = VK_FILTER_NEAREST;
5934 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5935 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5936 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5937 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5938 sampler_ci.mipLodBias = 1.0;
5939 sampler_ci.anisotropyEnable = VK_FALSE;
5940 sampler_ci.maxAnisotropy = 1;
5941 sampler_ci.compareEnable = VK_FALSE;
5942 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5943 sampler_ci.minLod = 1.0;
5944 sampler_ci.maxLod = 1.0;
5945 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5946 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005947 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005948 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005949 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005950
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005951 VkDescriptorImageInfo info = {};
5952 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005953
5954 VkWriteDescriptorSet descriptor_write;
5955 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07005956 descriptor_write.sType =
5957 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005958 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005959 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005960 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005961 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005962 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005963
5964 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5965
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005966 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005967
Chia-I Wuf7458c52015-10-26 21:10:41 +08005968 vkDestroySampler(m_device->device(), sampler, NULL);
5969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5970 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005971}
5972
Karl Schultz6addd812016-02-02 17:17:23 -07005973TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005974 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07005975 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005976
Karl Schultz6addd812016-02-02 17:17:23 -07005977 m_errorMonitor->SetDesiredFailureMsg(
5978 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005980
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005981 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005982 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
5983 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005984 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005985 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
5986 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005987
5988 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005989 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5990 ds_pool_ci.pNext = NULL;
5991 ds_pool_ci.maxSets = 1;
5992 ds_pool_ci.poolSizeCount = 1;
5993 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005994
5995 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005996 err =
5997 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005998 ASSERT_VK_SUCCESS(err);
5999
6000 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006001 dsl_binding.binding = 0;
6002 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6003 dsl_binding.descriptorCount = 1;
6004 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6005 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006006
6007 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006008 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6009 ds_layout_ci.pNext = NULL;
6010 ds_layout_ci.bindingCount = 1;
6011 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006012 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006013 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6014 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006015 ASSERT_VK_SUCCESS(err);
6016
6017 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006018 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006019 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006020 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006021 alloc_info.descriptorPool = ds_pool;
6022 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006023 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6024 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006025 ASSERT_VK_SUCCESS(err);
6026
Karl Schultz6addd812016-02-02 17:17:23 -07006027 VkSampler sampler =
6028 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006029
6030 VkDescriptorImageInfo descriptor_info;
6031 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
6032 descriptor_info.sampler = sampler;
6033
6034 VkWriteDescriptorSet descriptor_write;
6035 memset(&descriptor_write, 0, sizeof(descriptor_write));
6036 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006037 descriptor_write.dstSet = descriptorSet;
6038 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006039 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006040 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6041 descriptor_write.pImageInfo = &descriptor_info;
6042
6043 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6044
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006045 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006046
Chia-I Wuf7458c52015-10-26 21:10:41 +08006047 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006049}
6050
Karl Schultz6addd812016-02-02 17:17:23 -07006051TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
6052 // Create a single combined Image/Sampler descriptor and send it an invalid
6053 // imageView
6054 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006055
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6057 "Attempted write update to combined "
6058 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06006059 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006060
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006061 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006062 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006063 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6064 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006065
6066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6068 ds_pool_ci.pNext = NULL;
6069 ds_pool_ci.maxSets = 1;
6070 ds_pool_ci.poolSizeCount = 1;
6071 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006072
6073 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006074 err =
6075 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006076 ASSERT_VK_SUCCESS(err);
6077
6078 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006079 dsl_binding.binding = 0;
6080 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6081 dsl_binding.descriptorCount = 1;
6082 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6083 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006084
6085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6087 ds_layout_ci.pNext = NULL;
6088 ds_layout_ci.bindingCount = 1;
6089 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006090 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6092 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006093 ASSERT_VK_SUCCESS(err);
6094
6095 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006096 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006097 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006098 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006099 alloc_info.descriptorPool = ds_pool;
6100 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006101 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6102 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006103 ASSERT_VK_SUCCESS(err);
6104
6105 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006106 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6107 sampler_ci.pNext = NULL;
6108 sampler_ci.magFilter = VK_FILTER_NEAREST;
6109 sampler_ci.minFilter = VK_FILTER_NEAREST;
6110 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6111 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6112 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6113 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6114 sampler_ci.mipLodBias = 1.0;
6115 sampler_ci.anisotropyEnable = VK_FALSE;
6116 sampler_ci.maxAnisotropy = 1;
6117 sampler_ci.compareEnable = VK_FALSE;
6118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6119 sampler_ci.minLod = 1.0;
6120 sampler_ci.maxLod = 1.0;
6121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6122 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006123
6124 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006125 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006126 ASSERT_VK_SUCCESS(err);
6127
Karl Schultz6addd812016-02-02 17:17:23 -07006128 VkImageView view =
6129 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006130
6131 VkDescriptorImageInfo descriptor_info;
6132 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
6133 descriptor_info.sampler = sampler;
6134 descriptor_info.imageView = view;
6135
6136 VkWriteDescriptorSet descriptor_write;
6137 memset(&descriptor_write, 0, sizeof(descriptor_write));
6138 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006139 descriptor_write.dstSet = descriptorSet;
6140 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006141 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006142 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6143 descriptor_write.pImageInfo = &descriptor_info;
6144
6145 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006147 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006148
Chia-I Wuf7458c52015-10-26 21:10:41 +08006149 vkDestroySampler(m_device->device(), sampler, NULL);
6150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6151 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006152}
6153
Karl Schultz6addd812016-02-02 17:17:23 -07006154TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
6155 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
6156 // into the other
6157 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006158
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6160 " binding #1 with type "
6161 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
6162 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006163
Tobin Ehlis04356f92015-10-27 16:35:27 -06006164 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07006165 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006166 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006167 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6168 ds_type_count[0].descriptorCount = 1;
6169 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6170 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006171
6172 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006173 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6174 ds_pool_ci.pNext = NULL;
6175 ds_pool_ci.maxSets = 1;
6176 ds_pool_ci.poolSizeCount = 2;
6177 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006178
6179 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006180 err =
6181 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006182 ASSERT_VK_SUCCESS(err);
6183 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006184 dsl_binding[0].binding = 0;
6185 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6186 dsl_binding[0].descriptorCount = 1;
6187 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6188 dsl_binding[0].pImmutableSamplers = NULL;
6189 dsl_binding[1].binding = 1;
6190 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6191 dsl_binding[1].descriptorCount = 1;
6192 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6193 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006194
6195 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006196 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6197 ds_layout_ci.pNext = NULL;
6198 ds_layout_ci.bindingCount = 2;
6199 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006200
6201 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6203 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006204 ASSERT_VK_SUCCESS(err);
6205
6206 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006207 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006209 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006210 alloc_info.descriptorPool = ds_pool;
6211 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6213 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006214 ASSERT_VK_SUCCESS(err);
6215
6216 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006217 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6218 sampler_ci.pNext = NULL;
6219 sampler_ci.magFilter = VK_FILTER_NEAREST;
6220 sampler_ci.minFilter = VK_FILTER_NEAREST;
6221 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6222 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6223 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6224 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6225 sampler_ci.mipLodBias = 1.0;
6226 sampler_ci.anisotropyEnable = VK_FALSE;
6227 sampler_ci.maxAnisotropy = 1;
6228 sampler_ci.compareEnable = VK_FALSE;
6229 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6230 sampler_ci.minLod = 1.0;
6231 sampler_ci.maxLod = 1.0;
6232 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6233 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006234
6235 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006236 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006237 ASSERT_VK_SUCCESS(err);
6238
6239 VkDescriptorImageInfo info = {};
6240 info.sampler = sampler;
6241
6242 VkWriteDescriptorSet descriptor_write;
6243 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
6244 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006245 descriptor_write.dstSet = descriptorSet;
6246 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08006247 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006248 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6249 descriptor_write.pImageInfo = &info;
6250 // This write update should succeed
6251 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6252 // Now perform a copy update that fails due to type mismatch
6253 VkCopyDescriptorSet copy_ds_update;
6254 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6255 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6256 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06006257 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006258 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006259 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08006260 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06006261 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6262
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006263 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06006264 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07006265 m_errorMonitor->SetDesiredFailureMsg(
6266 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006267 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06006268 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6269 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6270 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006271 copy_ds_update.srcBinding =
6272 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006273 copy_ds_update.dstSet = descriptorSet;
6274 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06006275 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06006276 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006278 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006279
Tobin Ehlis04356f92015-10-27 16:35:27 -06006280 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07006281 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006282 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
6283 "update array offset of 0 and update of "
6284 "5 descriptors oversteps total number "
6285 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006286
Tobin Ehlis04356f92015-10-27 16:35:27 -06006287 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6288 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6289 copy_ds_update.srcSet = descriptorSet;
6290 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006291 copy_ds_update.dstSet = descriptorSet;
6292 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006293 copy_ds_update.descriptorCount =
6294 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06006295 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006297 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06006298
Chia-I Wuf7458c52015-10-26 21:10:41 +08006299 vkDestroySampler(m_device->device(), sampler, NULL);
6300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006302}
6303
Karl Schultz6addd812016-02-02 17:17:23 -07006304TEST_F(VkLayerTest, NumSamplesMismatch) {
6305 // Create CommandBuffer where MSAA samples doesn't match RenderPass
6306 // sampleCount
6307 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006308
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006310 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006311
Tobin Ehlis3b780662015-05-28 12:11:26 -06006312 ASSERT_NO_FATAL_FAILURE(InitState());
6313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006314 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06006315 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006316 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006317
6318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6320 ds_pool_ci.pNext = NULL;
6321 ds_pool_ci.maxSets = 1;
6322 ds_pool_ci.poolSizeCount = 1;
6323 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06006324
Tobin Ehlis3b780662015-05-28 12:11:26 -06006325 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006326 err =
6327 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006328 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006329
Tony Barboureb254902015-07-15 12:50:33 -06006330 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006331 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06006332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006333 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6335 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006336
Tony Barboureb254902015-07-15 12:50:33 -06006337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6339 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006340 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006341 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006342
Tobin Ehlis3b780662015-05-28 12:11:26 -06006343 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6345 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006346 ASSERT_VK_SUCCESS(err);
6347
6348 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006349 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006351 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006352 alloc_info.descriptorPool = ds_pool;
6353 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6355 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006356 ASSERT_VK_SUCCESS(err);
6357
Tony Barboureb254902015-07-15 12:50:33 -06006358 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 pipe_ms_state_ci.sType =
6360 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6361 pipe_ms_state_ci.pNext = NULL;
6362 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
6363 pipe_ms_state_ci.sampleShadingEnable = 0;
6364 pipe_ms_state_ci.minSampleShading = 1.0;
6365 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006366
Tony Barboureb254902015-07-15 12:50:33 -06006367 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006368 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6369 pipeline_layout_ci.pNext = NULL;
6370 pipeline_layout_ci.setLayoutCount = 1;
6371 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006372
6373 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006374 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6375 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006376 ASSERT_VK_SUCCESS(err);
6377
Karl Schultz6addd812016-02-02 17:17:23 -07006378 VkShaderObj vs(m_device, bindStateVertShaderText,
6379 VK_SHADER_STAGE_VERTEX_BIT, this);
6380 VkShaderObj fs(m_device, bindStateFragShaderText,
6381 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006382 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006383 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006384 VkPipelineObj pipe(m_device);
6385 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006386 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006387 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006388 pipe.SetMSAA(&pipe_ms_state_ci);
6389 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06006390
Tony Barbourfe3351b2015-07-28 10:17:20 -06006391 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006392 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6393 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06006394
Mark Young29927482016-05-04 14:38:51 -06006395 // Render triangle (the error should trigger on the attempt to draw).
6396 Draw(3, 1, 0, 0);
6397
6398 // Finalize recording of the command buffer
6399 EndCommandBuffer();
6400
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006401 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006402
Chia-I Wuf7458c52015-10-26 21:10:41 +08006403 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6405 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006406}
Mark Young29927482016-05-04 14:38:51 -06006407
Mark Youngc89c6312016-03-31 16:03:20 -06006408TEST_F(VkLayerTest, NumBlendAttachMismatch) {
6409 // Create Pipeline where the number of blend attachments doesn't match the
6410 // number of color attachments. In this case, we don't add any color
6411 // blend attachments even though we have a color attachment.
6412 VkResult err;
6413
6414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06006415 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06006416
6417 ASSERT_NO_FATAL_FAILURE(InitState());
6418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6419 VkDescriptorPoolSize ds_type_count = {};
6420 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6421 ds_type_count.descriptorCount = 1;
6422
6423 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6424 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6425 ds_pool_ci.pNext = NULL;
6426 ds_pool_ci.maxSets = 1;
6427 ds_pool_ci.poolSizeCount = 1;
6428 ds_pool_ci.pPoolSizes = &ds_type_count;
6429
6430 VkDescriptorPool ds_pool;
6431 err =
6432 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6433 ASSERT_VK_SUCCESS(err);
6434
6435 VkDescriptorSetLayoutBinding dsl_binding = {};
6436 dsl_binding.binding = 0;
6437 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6438 dsl_binding.descriptorCount = 1;
6439 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6440 dsl_binding.pImmutableSamplers = NULL;
6441
6442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6444 ds_layout_ci.pNext = NULL;
6445 ds_layout_ci.bindingCount = 1;
6446 ds_layout_ci.pBindings = &dsl_binding;
6447
6448 VkDescriptorSetLayout ds_layout;
6449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6450 &ds_layout);
6451 ASSERT_VK_SUCCESS(err);
6452
6453 VkDescriptorSet descriptorSet;
6454 VkDescriptorSetAllocateInfo alloc_info = {};
6455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6456 alloc_info.descriptorSetCount = 1;
6457 alloc_info.descriptorPool = ds_pool;
6458 alloc_info.pSetLayouts = &ds_layout;
6459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6460 &descriptorSet);
6461 ASSERT_VK_SUCCESS(err);
6462
6463 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
6464 pipe_ms_state_ci.sType =
6465 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6466 pipe_ms_state_ci.pNext = NULL;
6467 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
6468 pipe_ms_state_ci.sampleShadingEnable = 0;
6469 pipe_ms_state_ci.minSampleShading = 1.0;
6470 pipe_ms_state_ci.pSampleMask = NULL;
6471
6472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6474 pipeline_layout_ci.pNext = NULL;
6475 pipeline_layout_ci.setLayoutCount = 1;
6476 pipeline_layout_ci.pSetLayouts = &ds_layout;
6477
6478 VkPipelineLayout pipeline_layout;
6479 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6480 &pipeline_layout);
6481 ASSERT_VK_SUCCESS(err);
6482
6483 VkShaderObj vs(m_device, bindStateVertShaderText,
6484 VK_SHADER_STAGE_VERTEX_BIT, this);
6485 VkShaderObj fs(m_device, bindStateFragShaderText,
6486 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006487 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06006488 // but add it to be able to run on more devices
6489 VkPipelineObj pipe(m_device);
6490 pipe.AddShader(&vs);
6491 pipe.AddShader(&fs);
6492 pipe.SetMSAA(&pipe_ms_state_ci);
6493 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6494
6495 BeginCommandBuffer();
6496 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6497 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6498
Mark Young29927482016-05-04 14:38:51 -06006499 // Render triangle (the error should trigger on the attempt to draw).
6500 Draw(3, 1, 0, 0);
6501
6502 // Finalize recording of the command buffer
6503 EndCommandBuffer();
6504
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006505 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06006506
6507 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6508 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6509 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6510}
Mark Young29927482016-05-04 14:38:51 -06006511
Karl Schultz6addd812016-02-02 17:17:23 -07006512TEST_F(VkLayerTest, ClearCmdNoDraw) {
6513 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
6514 // to issuing a Draw
6515 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006516
Karl Schultz6addd812016-02-02 17:17:23 -07006517 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07006518 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006519 "vkCmdClearAttachments() issued on CB object ");
6520
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006521 ASSERT_NO_FATAL_FAILURE(InitState());
6522 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06006523
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006524 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006525 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6526 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006527
6528 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006529 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6530 ds_pool_ci.pNext = NULL;
6531 ds_pool_ci.maxSets = 1;
6532 ds_pool_ci.poolSizeCount = 1;
6533 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006534
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006535 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006536 err =
6537 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006538 ASSERT_VK_SUCCESS(err);
6539
Tony Barboureb254902015-07-15 12:50:33 -06006540 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006541 dsl_binding.binding = 0;
6542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6543 dsl_binding.descriptorCount = 1;
6544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6545 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006546
Tony Barboureb254902015-07-15 12:50:33 -06006547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6549 ds_layout_ci.pNext = NULL;
6550 ds_layout_ci.bindingCount = 1;
6551 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006552
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006553 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6555 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006556 ASSERT_VK_SUCCESS(err);
6557
6558 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006559 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006561 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006562 alloc_info.descriptorPool = ds_pool;
6563 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6565 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006566 ASSERT_VK_SUCCESS(err);
6567
Tony Barboureb254902015-07-15 12:50:33 -06006568 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006569 pipe_ms_state_ci.sType =
6570 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6571 pipe_ms_state_ci.pNext = NULL;
6572 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
6573 pipe_ms_state_ci.sampleShadingEnable = 0;
6574 pipe_ms_state_ci.minSampleShading = 1.0;
6575 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006576
Tony Barboureb254902015-07-15 12:50:33 -06006577 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006578 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6579 pipeline_layout_ci.pNext = NULL;
6580 pipeline_layout_ci.setLayoutCount = 1;
6581 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006582
6583 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6585 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006586 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006587
Karl Schultz6addd812016-02-02 17:17:23 -07006588 VkShaderObj vs(m_device, bindStateVertShaderText,
6589 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006590 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006591 // on more devices
6592 VkShaderObj fs(m_device, bindStateFragShaderText,
6593 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006594
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006595 VkPipelineObj pipe(m_device);
6596 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006597 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006598 pipe.SetMSAA(&pipe_ms_state_ci);
6599 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006600
6601 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006602
Karl Schultz6addd812016-02-02 17:17:23 -07006603 // Main thing we care about for this test is that the VkImage obj we're
6604 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006605 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006606 VkClearAttachment color_attachment;
6607 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6608 color_attachment.clearValue.color.float32[0] = 1.0;
6609 color_attachment.clearValue.color.float32[1] = 1.0;
6610 color_attachment.clearValue.color.float32[2] = 1.0;
6611 color_attachment.clearValue.color.float32[3] = 1.0;
6612 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006613 VkClearRect clear_rect = {
6614 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006615
Karl Schultz6addd812016-02-02 17:17:23 -07006616 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6617 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006618
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006619 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006620
Chia-I Wuf7458c52015-10-26 21:10:41 +08006621 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6622 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6623 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006624}
6625
Karl Schultz6addd812016-02-02 17:17:23 -07006626TEST_F(VkLayerTest, VtxBufferBadIndex) {
6627 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006628
Karl Schultz6addd812016-02-02 17:17:23 -07006629 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006630 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07006631 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006632
Tobin Ehlis502480b2015-06-24 15:53:07 -06006633 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06006634 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06006635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06006636
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006637 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006638 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6639 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006640
6641 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006642 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6643 ds_pool_ci.pNext = NULL;
6644 ds_pool_ci.maxSets = 1;
6645 ds_pool_ci.poolSizeCount = 1;
6646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006647
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06006648 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006649 err =
6650 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006651 ASSERT_VK_SUCCESS(err);
6652
Tony Barboureb254902015-07-15 12:50:33 -06006653 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006654 dsl_binding.binding = 0;
6655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6656 dsl_binding.descriptorCount = 1;
6657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006659
Tony Barboureb254902015-07-15 12:50:33 -06006660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6662 ds_layout_ci.pNext = NULL;
6663 ds_layout_ci.bindingCount = 1;
6664 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006665
Tobin Ehlis502480b2015-06-24 15:53:07 -06006666 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6668 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006669 ASSERT_VK_SUCCESS(err);
6670
6671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006675 alloc_info.descriptorPool = ds_pool;
6676 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6678 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006679 ASSERT_VK_SUCCESS(err);
6680
Tony Barboureb254902015-07-15 12:50:33 -06006681 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006682 pipe_ms_state_ci.sType =
6683 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6684 pipe_ms_state_ci.pNext = NULL;
6685 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
6686 pipe_ms_state_ci.sampleShadingEnable = 0;
6687 pipe_ms_state_ci.minSampleShading = 1.0;
6688 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006689
Tony Barboureb254902015-07-15 12:50:33 -06006690 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006691 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6692 pipeline_layout_ci.pNext = NULL;
6693 pipeline_layout_ci.setLayoutCount = 1;
6694 pipeline_layout_ci.pSetLayouts = &ds_layout;
6695 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006696
Karl Schultz6addd812016-02-02 17:17:23 -07006697 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6698 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006699 ASSERT_VK_SUCCESS(err);
6700
Karl Schultz6addd812016-02-02 17:17:23 -07006701 VkShaderObj vs(m_device, bindStateVertShaderText,
6702 VK_SHADER_STAGE_VERTEX_BIT, this);
6703 VkShaderObj fs(m_device, bindStateFragShaderText,
6704 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006705 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006706 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006707 VkPipelineObj pipe(m_device);
6708 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006709 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006710 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006711 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006712 pipe.SetViewport(m_viewports);
6713 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006714 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006715
6716 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006717 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6718 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06006719 // Don't care about actual data, just need to get to draw to flag error
6720 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07006721 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
6722 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06006723 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06006724 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006725
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006726 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006727
Chia-I Wuf7458c52015-10-26 21:10:41 +08006728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6729 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6730 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006731}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006732// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
6733TEST_F(VkLayerTest, InvalidImageLayout) {
6734 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
6735 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
6736 "images in the wrong layout when they're copied or transitioned.");
6737 // 3 in ValidateCmdBufImageLayouts
6738 // * -1 Attempt to submit cmd buf w/ deleted image
6739 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
6740 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
6741 m_errorMonitor->SetDesiredFailureMsg(
6742 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6743 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
6744
6745 ASSERT_NO_FATAL_FAILURE(InitState());
6746 // Create src & dst images to use for copy operations
6747 VkImage src_image;
6748 VkImage dst_image;
6749
6750 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6751 const int32_t tex_width = 32;
6752 const int32_t tex_height = 32;
6753
6754 VkImageCreateInfo image_create_info = {};
6755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6756 image_create_info.pNext = NULL;
6757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6758 image_create_info.format = tex_format;
6759 image_create_info.extent.width = tex_width;
6760 image_create_info.extent.height = tex_height;
6761 image_create_info.extent.depth = 1;
6762 image_create_info.mipLevels = 1;
6763 image_create_info.arrayLayers = 4;
6764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6765 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6766 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6767 image_create_info.flags = 0;
6768
6769 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
6770 ASSERT_VK_SUCCESS(err);
6771 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
6772 ASSERT_VK_SUCCESS(err);
6773
6774 BeginCommandBuffer();
6775 VkImageCopy copyRegion;
6776 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6777 copyRegion.srcSubresource.mipLevel = 0;
6778 copyRegion.srcSubresource.baseArrayLayer = 0;
6779 copyRegion.srcSubresource.layerCount = 1;
6780 copyRegion.srcOffset.x = 0;
6781 copyRegion.srcOffset.y = 0;
6782 copyRegion.srcOffset.z = 0;
6783 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6784 copyRegion.dstSubresource.mipLevel = 0;
6785 copyRegion.dstSubresource.baseArrayLayer = 0;
6786 copyRegion.dstSubresource.layerCount = 1;
6787 copyRegion.dstOffset.x = 0;
6788 copyRegion.dstOffset.y = 0;
6789 copyRegion.dstOffset.z = 0;
6790 copyRegion.extent.width = 1;
6791 copyRegion.extent.height = 1;
6792 copyRegion.extent.depth = 1;
6793 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6794 m_errorMonitor->VerifyFound();
6795 // Now cause error due to src image layout changing
6796 m_errorMonitor->SetDesiredFailureMsg(
6797 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6798 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
6799 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6800 m_errorMonitor->VerifyFound();
6801 // Final src error is due to bad layout type
6802 m_errorMonitor->SetDesiredFailureMsg(
6803 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6804 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
6805 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6806 m_errorMonitor->VerifyFound();
6807 // Now verify same checks for dst
6808 m_errorMonitor->SetDesiredFailureMsg(
6809 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6810 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
6811 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6812 m_errorMonitor->VerifyFound();
6813 // Now cause error due to src image layout changing
6814 m_errorMonitor->SetDesiredFailureMsg(
6815 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6816 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
6817 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
6818 m_errorMonitor->VerifyFound();
6819 m_errorMonitor->SetDesiredFailureMsg(
6820 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6821 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
6822 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
6823 m_errorMonitor->VerifyFound();
6824 // Now cause error due to bad image layout transition in PipelineBarrier
6825 VkImageMemoryBarrier image_barrier[1] = {};
6826 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6827 image_barrier[0].image = src_image;
6828 image_barrier[0].subresourceRange.layerCount = 2;
6829 image_barrier[0].subresourceRange.levelCount = 2;
6830 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6831 m_errorMonitor->SetDesiredFailureMsg(
6832 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6833 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
6834 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
6835 m_errorMonitor->VerifyFound();
6836
6837 // Finally some layout errors at RenderPass create time
6838 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
6839 VkAttachmentReference attach = {};
6840 // perf warning for GENERAL layout w/ non-DS input attachment
6841 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6842 VkSubpassDescription subpass = {};
6843 subpass.inputAttachmentCount = 1;
6844 subpass.pInputAttachments = &attach;
6845 VkRenderPassCreateInfo rpci = {};
6846 rpci.subpassCount = 1;
6847 rpci.pSubpasses = &subpass;
6848 rpci.attachmentCount = 1;
6849 VkAttachmentDescription attach_desc = {};
6850 attach_desc.format = VK_FORMAT_UNDEFINED;
6851 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06006852 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006853 VkRenderPass rp;
6854 m_errorMonitor->SetDesiredFailureMsg(
6855 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6856 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
6857 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6858 m_errorMonitor->VerifyFound();
6859 // error w/ non-general layout
6860 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6861
6862 m_errorMonitor->SetDesiredFailureMsg(
6863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6864 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
6865 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6866 m_errorMonitor->VerifyFound();
6867 subpass.inputAttachmentCount = 0;
6868 subpass.colorAttachmentCount = 1;
6869 subpass.pColorAttachments = &attach;
6870 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6871 // perf warning for GENERAL layout on color attachment
6872 m_errorMonitor->SetDesiredFailureMsg(
6873 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6874 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
6875 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6876 m_errorMonitor->VerifyFound();
6877 // error w/ non-color opt or GENERAL layout for color attachment
6878 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6879 m_errorMonitor->SetDesiredFailureMsg(
6880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6881 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
6882 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6883 m_errorMonitor->VerifyFound();
6884 subpass.colorAttachmentCount = 0;
6885 subpass.pDepthStencilAttachment = &attach;
6886 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6887 // perf warning for GENERAL layout on DS attachment
6888 m_errorMonitor->SetDesiredFailureMsg(
6889 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6890 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
6891 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6892 m_errorMonitor->VerifyFound();
6893 // error w/ non-ds opt or GENERAL layout for color attachment
6894 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6895 m_errorMonitor->SetDesiredFailureMsg(
6896 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6897 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
6898 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6899 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06006900 // For this error we need a valid renderpass so create default one
6901 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6902 attach.attachment = 0;
6903 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
6904 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
6905 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
6906 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
6907 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
6908 // Can't do a CLEAR load on READ_ONLY initialLayout
6909 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
6910 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6911 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6913 " with invalid first layout "
6914 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
6915 "ONLY_OPTIMAL");
6916 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6917 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006918
6919 vkDestroyImage(m_device->device(), src_image, NULL);
6920 vkDestroyImage(m_device->device(), dst_image, NULL);
6921}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006922#endif // DRAW_STATE_TESTS
6923
Tobin Ehlis0788f522015-05-26 16:11:58 -06006924#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06006925#if GTEST_IS_THREADSAFE
6926struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006927 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006928 VkEvent event;
6929 bool bailout;
6930};
6931
Karl Schultz6addd812016-02-02 17:17:23 -07006932extern "C" void *AddToCommandBuffer(void *arg) {
6933 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006934
Karl Schultz6addd812016-02-02 17:17:23 -07006935 for (int i = 0; i < 10000; i++) {
6936 vkCmdSetEvent(data->commandBuffer, data->event,
6937 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006938 if (data->bailout) {
6939 break;
6940 }
6941 }
6942 return NULL;
6943}
6944
Karl Schultz6addd812016-02-02 17:17:23 -07006945TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006946 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006947
Karl Schultz6addd812016-02-02 17:17:23 -07006948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6949 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006950
Mike Stroyanaccf7692015-05-12 16:00:45 -06006951 ASSERT_NO_FATAL_FAILURE(InitState());
6952 ASSERT_NO_FATAL_FAILURE(InitViewport());
6953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6954
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006955 // Calls AllocateCommandBuffers
6956 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006957
6958 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006959 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006960
6961 VkEventCreateInfo event_info;
6962 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006963 VkResult err;
6964
6965 memset(&event_info, 0, sizeof(event_info));
6966 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
6967
Chia-I Wuf7458c52015-10-26 21:10:41 +08006968 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006969 ASSERT_VK_SUCCESS(err);
6970
Mike Stroyanaccf7692015-05-12 16:00:45 -06006971 err = vkResetEvent(device(), event);
6972 ASSERT_VK_SUCCESS(err);
6973
6974 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006975 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006976 data.event = event;
6977 data.bailout = false;
6978 m_errorMonitor->SetBailout(&data.bailout);
6979 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006980 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006981 // Add many entries to command buffer from this thread at the same time.
6982 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006983
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006984 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006985 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006986
Mike Stroyan10b8cb72016-01-22 15:22:03 -07006987 m_errorMonitor->SetBailout(NULL);
6988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006989 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006990
Chia-I Wuf7458c52015-10-26 21:10:41 +08006991 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006992}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006993#endif // GTEST_IS_THREADSAFE
6994#endif // THREADING_TESTS
6995
Chris Forbes9f7ff632015-05-25 11:13:08 +12006996#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07006997TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006999 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007000
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007001 ASSERT_NO_FATAL_FAILURE(InitState());
7002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7003
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007004 VkShaderModule module;
7005 VkShaderModuleCreateInfo moduleCreateInfo;
7006 struct icd_spv_header spv;
7007
7008 spv.magic = ICD_SPV_MAGIC;
7009 spv.version = ICD_SPV_VERSION;
7010 spv.gen_magic = 0;
7011
7012 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
7013 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007014 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007015 moduleCreateInfo.codeSize = 4;
7016 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007017 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007018
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007019 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007020}
7021
Karl Schultz6addd812016-02-02 17:17:23 -07007022TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12007024 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007025
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007026 ASSERT_NO_FATAL_FAILURE(InitState());
7027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7028
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007029 VkShaderModule module;
7030 VkShaderModuleCreateInfo moduleCreateInfo;
7031 struct icd_spv_header spv;
7032
7033 spv.magic = ~ICD_SPV_MAGIC;
7034 spv.version = ICD_SPV_VERSION;
7035 spv.gen_magic = 0;
7036
7037 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
7038 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007039 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007040 moduleCreateInfo.codeSize = sizeof(spv) + 10;
7041 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007042 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007043
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007044 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007045}
7046
Chris Forbesb4afd0f2016-04-04 10:48:35 +12007047#if 0
7048// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07007049TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12007051 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007052
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007053 ASSERT_NO_FATAL_FAILURE(InitState());
7054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7055
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007056 VkShaderModule module;
7057 VkShaderModuleCreateInfo moduleCreateInfo;
7058 struct icd_spv_header spv;
7059
7060 spv.magic = ICD_SPV_MAGIC;
7061 spv.version = ~ICD_SPV_VERSION;
7062 spv.gen_magic = 0;
7063
7064 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
7065 moduleCreateInfo.pNext = NULL;
7066
Karl Schultz6addd812016-02-02 17:17:23 -07007067 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007068 moduleCreateInfo.codeSize = sizeof(spv) + 10;
7069 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08007070 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007071
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007072 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007073}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12007074#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06007075
Karl Schultz6addd812016-02-02 17:17:23 -07007076TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007078 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007079
Chris Forbes9f7ff632015-05-25 11:13:08 +12007080 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12007082
7083 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007084 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007085 "\n"
7086 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007087 "out gl_PerVertex {\n"
7088 " vec4 gl_Position;\n"
7089 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007090 "void main(){\n"
7091 " gl_Position = vec4(1);\n"
7092 " x = 0;\n"
7093 "}\n";
7094 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007095 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007096 "\n"
7097 "layout(location=0) out vec4 color;\n"
7098 "void main(){\n"
7099 " color = vec4(1);\n"
7100 "}\n";
7101
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12007104
7105 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007106 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12007107 pipe.AddShader(&vs);
7108 pipe.AddShader(&fs);
7109
Chris Forbes9f7ff632015-05-25 11:13:08 +12007110 VkDescriptorSetObj descriptorSet(m_device);
7111 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007112 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12007113
Tony Barbour5781e8f2015-08-04 16:23:11 -06007114 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12007115
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007116 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12007117}
Chris Forbes9f7ff632015-05-25 11:13:08 +12007118
Karl Schultz6addd812016-02-02 17:17:23 -07007119TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007121 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007122
Chris Forbes59cb88d2015-05-25 11:13:13 +12007123 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12007125
7126 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007127 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007128 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007129 "out gl_PerVertex {\n"
7130 " vec4 gl_Position;\n"
7131 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007132 "void main(){\n"
7133 " gl_Position = vec4(1);\n"
7134 "}\n";
7135 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007136 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007137 "\n"
7138 "layout(location=0) in float x;\n"
7139 "layout(location=0) out vec4 color;\n"
7140 "void main(){\n"
7141 " color = vec4(x);\n"
7142 "}\n";
7143
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12007146
7147 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007148 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12007149 pipe.AddShader(&vs);
7150 pipe.AddShader(&fs);
7151
Chris Forbes59cb88d2015-05-25 11:13:13 +12007152 VkDescriptorSetObj descriptorSet(m_device);
7153 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12007155
Tony Barbour5781e8f2015-08-04 16:23:11 -06007156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12007157
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007158 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12007159}
7160
Karl Schultz6addd812016-02-02 17:17:23 -07007161TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13007162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007163 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13007164
7165 ASSERT_NO_FATAL_FAILURE(InitState());
7166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7167
7168 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007169 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007170 "\n"
7171 "out gl_PerVertex {\n"
7172 " vec4 gl_Position;\n"
7173 "};\n"
7174 "void main(){\n"
7175 " gl_Position = vec4(1);\n"
7176 "}\n";
7177 char const *fsSource =
7178 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007179 "\n"
7180 "in block { layout(location=0) float x; } ins;\n"
7181 "layout(location=0) out vec4 color;\n"
7182 "void main(){\n"
7183 " color = vec4(ins.x);\n"
7184 "}\n";
7185
7186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7188
7189 VkPipelineObj pipe(m_device);
7190 pipe.AddColorAttachment();
7191 pipe.AddShader(&vs);
7192 pipe.AddShader(&fs);
7193
7194 VkDescriptorSetObj descriptorSet(m_device);
7195 descriptorSet.AppendDummy();
7196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7197
7198 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7199
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007200 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13007201}
7202
Karl Schultz6addd812016-02-02 17:17:23 -07007203TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13007204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13007205 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07007206 "output arr[2] of float32' vs 'ptr to "
7207 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13007208
7209 ASSERT_NO_FATAL_FAILURE(InitState());
7210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7211
7212 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007213 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13007214 "\n"
7215 "layout(location=0) out float x[2];\n"
7216 "out gl_PerVertex {\n"
7217 " vec4 gl_Position;\n"
7218 "};\n"
7219 "void main(){\n"
7220 " x[0] = 0; x[1] = 0;\n"
7221 " gl_Position = vec4(1);\n"
7222 "}\n";
7223 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007224 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13007225 "\n"
7226 "layout(location=0) in float x[3];\n"
7227 "layout(location=0) out vec4 color;\n"
7228 "void main(){\n"
7229 " color = vec4(x[0] + x[1] + x[2]);\n"
7230 "}\n";
7231
7232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7234
7235 VkPipelineObj pipe(m_device);
7236 pipe.AddColorAttachment();
7237 pipe.AddShader(&vs);
7238 pipe.AddShader(&fs);
7239
7240 VkDescriptorSetObj descriptorSet(m_device);
7241 descriptorSet.AppendDummy();
7242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7243
7244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13007247}
7248
Karl Schultz6addd812016-02-02 17:17:23 -07007249TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007251 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007252
Chris Forbesb56af562015-05-25 11:13:17 +12007253 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12007255
7256 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007257 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007258 "\n"
7259 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007260 "out gl_PerVertex {\n"
7261 " vec4 gl_Position;\n"
7262 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007263 "void main(){\n"
7264 " x = 0;\n"
7265 " gl_Position = vec4(1);\n"
7266 "}\n";
7267 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007268 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007269 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007270 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12007271 "layout(location=0) out vec4 color;\n"
7272 "void main(){\n"
7273 " color = vec4(x);\n"
7274 "}\n";
7275
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12007278
7279 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007280 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12007281 pipe.AddShader(&vs);
7282 pipe.AddShader(&fs);
7283
Chris Forbesb56af562015-05-25 11:13:17 +12007284 VkDescriptorSetObj descriptorSet(m_device);
7285 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12007287
Tony Barbour5781e8f2015-08-04 16:23:11 -06007288 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12007289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007290 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12007291}
7292
Karl Schultz6addd812016-02-02 17:17:23 -07007293TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13007294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007295 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13007296
7297 ASSERT_NO_FATAL_FAILURE(InitState());
7298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7299
7300 char const *vsSource =
7301 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007302 "\n"
7303 "out block { layout(location=0) int x; } outs;\n"
7304 "out gl_PerVertex {\n"
7305 " vec4 gl_Position;\n"
7306 "};\n"
7307 "void main(){\n"
7308 " outs.x = 0;\n"
7309 " gl_Position = vec4(1);\n"
7310 "}\n";
7311 char const *fsSource =
7312 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007313 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007314 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13007315 "layout(location=0) out vec4 color;\n"
7316 "void main(){\n"
7317 " color = vec4(ins.x);\n"
7318 "}\n";
7319
7320 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7321 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7322
7323 VkPipelineObj pipe(m_device);
7324 pipe.AddColorAttachment();
7325 pipe.AddShader(&vs);
7326 pipe.AddShader(&fs);
7327
7328 VkDescriptorSetObj descriptorSet(m_device);
7329 descriptorSet.AppendDummy();
7330 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7331
7332 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007334 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13007335}
7336
7337TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
7338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7339 "location 0.0 which is not written by vertex shader");
7340
7341 ASSERT_NO_FATAL_FAILURE(InitState());
7342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7343
7344 char const *vsSource =
7345 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007346 "\n"
7347 "out block { layout(location=1) float x; } outs;\n"
7348 "out gl_PerVertex {\n"
7349 " vec4 gl_Position;\n"
7350 "};\n"
7351 "void main(){\n"
7352 " outs.x = 0;\n"
7353 " gl_Position = vec4(1);\n"
7354 "}\n";
7355 char const *fsSource =
7356 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007357 "\n"
7358 "in block { layout(location=0) float x; } ins;\n"
7359 "layout(location=0) out vec4 color;\n"
7360 "void main(){\n"
7361 " color = vec4(ins.x);\n"
7362 "}\n";
7363
7364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7366
7367 VkPipelineObj pipe(m_device);
7368 pipe.AddColorAttachment();
7369 pipe.AddShader(&vs);
7370 pipe.AddShader(&fs);
7371
7372 VkDescriptorSetObj descriptorSet(m_device);
7373 descriptorSet.AppendDummy();
7374 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7375
7376 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7377
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007378 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13007379}
7380
7381TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
7382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7383 "location 0.1 which is not written by vertex shader");
7384
7385 ASSERT_NO_FATAL_FAILURE(InitState());
7386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7387
7388 char const *vsSource =
7389 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007390 "\n"
7391 "out block { layout(location=0, component=0) float x; } outs;\n"
7392 "out gl_PerVertex {\n"
7393 " vec4 gl_Position;\n"
7394 "};\n"
7395 "void main(){\n"
7396 " outs.x = 0;\n"
7397 " gl_Position = vec4(1);\n"
7398 "}\n";
7399 char const *fsSource =
7400 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007401 "\n"
7402 "in block { layout(location=0, component=1) float x; } ins;\n"
7403 "layout(location=0) out vec4 color;\n"
7404 "void main(){\n"
7405 " color = vec4(ins.x);\n"
7406 "}\n";
7407
7408 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7409 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7410
7411 VkPipelineObj pipe(m_device);
7412 pipe.AddColorAttachment();
7413 pipe.AddShader(&vs);
7414 pipe.AddShader(&fs);
7415
7416 VkDescriptorSetObj descriptorSet(m_device);
7417 descriptorSet.AppendDummy();
7418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7419
7420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007422 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13007423}
7424
Karl Schultz6addd812016-02-02 17:17:23 -07007425TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007427 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007428
Chris Forbesde136e02015-05-25 11:13:28 +12007429 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12007431
7432 VkVertexInputBindingDescription input_binding;
7433 memset(&input_binding, 0, sizeof(input_binding));
7434
7435 VkVertexInputAttributeDescription input_attrib;
7436 memset(&input_attrib, 0, sizeof(input_attrib));
7437 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7438
7439 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007440 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007441 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007442 "out gl_PerVertex {\n"
7443 " vec4 gl_Position;\n"
7444 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007445 "void main(){\n"
7446 " gl_Position = vec4(1);\n"
7447 "}\n";
7448 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007449 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007450 "\n"
7451 "layout(location=0) out vec4 color;\n"
7452 "void main(){\n"
7453 " color = vec4(1);\n"
7454 "}\n";
7455
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007456 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7457 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12007458
7459 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007460 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12007461 pipe.AddShader(&vs);
7462 pipe.AddShader(&fs);
7463
7464 pipe.AddVertexInputBindings(&input_binding, 1);
7465 pipe.AddVertexInputAttribs(&input_attrib, 1);
7466
Chris Forbesde136e02015-05-25 11:13:28 +12007467 VkDescriptorSetObj descriptorSet(m_device);
7468 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12007470
Tony Barbour5781e8f2015-08-04 16:23:11 -06007471 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12007472
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007473 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12007474}
7475
Karl Schultz6addd812016-02-02 17:17:23 -07007476TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007478 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13007479
7480 ASSERT_NO_FATAL_FAILURE(InitState());
7481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7482
7483 VkVertexInputBindingDescription input_binding;
7484 memset(&input_binding, 0, sizeof(input_binding));
7485
7486 VkVertexInputAttributeDescription input_attrib;
7487 memset(&input_attrib, 0, sizeof(input_attrib));
7488 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7489
7490 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007491 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13007492 "\n"
7493 "layout(location=1) in float x;\n"
7494 "out gl_PerVertex {\n"
7495 " vec4 gl_Position;\n"
7496 "};\n"
7497 "void main(){\n"
7498 " gl_Position = vec4(x);\n"
7499 "}\n";
7500 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007501 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13007502 "\n"
7503 "layout(location=0) out vec4 color;\n"
7504 "void main(){\n"
7505 " color = vec4(1);\n"
7506 "}\n";
7507
7508 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7509 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7510
7511 VkPipelineObj pipe(m_device);
7512 pipe.AddColorAttachment();
7513 pipe.AddShader(&vs);
7514 pipe.AddShader(&fs);
7515
7516 pipe.AddVertexInputBindings(&input_binding, 1);
7517 pipe.AddVertexInputAttribs(&input_attrib, 1);
7518
7519 VkDescriptorSetObj descriptorSet(m_device);
7520 descriptorSet.AppendDummy();
7521 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7522
7523 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7524
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007525 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13007526}
7527
Karl Schultz6addd812016-02-02 17:17:23 -07007528TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
7529 m_errorMonitor->SetDesiredFailureMsg(
7530 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007531 "VS consumes input at location 0 but not provided");
7532
Chris Forbes62e8e502015-05-25 11:13:29 +12007533 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007534 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12007535
7536 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007537 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007538 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007539 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07007540 "out gl_PerVertex {\n"
7541 " vec4 gl_Position;\n"
7542 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007543 "void main(){\n"
7544 " gl_Position = x;\n"
7545 "}\n";
7546 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007547 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007548 "\n"
7549 "layout(location=0) out vec4 color;\n"
7550 "void main(){\n"
7551 " color = vec4(1);\n"
7552 "}\n";
7553
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12007556
7557 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007558 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12007559 pipe.AddShader(&vs);
7560 pipe.AddShader(&fs);
7561
Chris Forbes62e8e502015-05-25 11:13:29 +12007562 VkDescriptorSetObj descriptorSet(m_device);
7563 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12007565
Tony Barbour5781e8f2015-08-04 16:23:11 -06007566 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12007567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007568 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12007569}
7570
Karl Schultz6addd812016-02-02 17:17:23 -07007571TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
7572 m_errorMonitor->SetDesiredFailureMsg(
7573 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007574 "location 0 does not match VS input type");
7575
Chris Forbesc97d98e2015-05-25 11:13:31 +12007576 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12007578
7579 VkVertexInputBindingDescription input_binding;
7580 memset(&input_binding, 0, sizeof(input_binding));
7581
7582 VkVertexInputAttributeDescription input_attrib;
7583 memset(&input_attrib, 0, sizeof(input_attrib));
7584 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7585
7586 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007587 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007588 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007589 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07007590 "out gl_PerVertex {\n"
7591 " vec4 gl_Position;\n"
7592 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007593 "void main(){\n"
7594 " gl_Position = vec4(x);\n"
7595 "}\n";
7596 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007597 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007598 "\n"
7599 "layout(location=0) out vec4 color;\n"
7600 "void main(){\n"
7601 " color = vec4(1);\n"
7602 "}\n";
7603
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007604 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7605 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12007606
7607 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007608 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12007609 pipe.AddShader(&vs);
7610 pipe.AddShader(&fs);
7611
7612 pipe.AddVertexInputBindings(&input_binding, 1);
7613 pipe.AddVertexInputAttribs(&input_attrib, 1);
7614
Chris Forbesc97d98e2015-05-25 11:13:31 +12007615 VkDescriptorSetObj descriptorSet(m_device);
7616 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12007618
Tony Barbour5781e8f2015-08-04 16:23:11 -06007619 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12007620
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007621 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12007622}
7623
Chris Forbesc68b43c2016-04-06 11:18:47 +12007624TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
7625 m_errorMonitor->SetDesiredFailureMsg(
7626 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7627 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
7628
7629 ASSERT_NO_FATAL_FAILURE(InitState());
7630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7631
7632 char const *vsSource =
7633 "#version 450\n"
7634 "\n"
7635 "out gl_PerVertex {\n"
7636 " vec4 gl_Position;\n"
7637 "};\n"
7638 "void main(){\n"
7639 " gl_Position = vec4(1);\n"
7640 "}\n";
7641 char const *fsSource =
7642 "#version 450\n"
7643 "\n"
7644 "layout(location=0) out vec4 color;\n"
7645 "void main(){\n"
7646 " color = vec4(1);\n"
7647 "}\n";
7648
7649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7651
7652 VkPipelineObj pipe(m_device);
7653 pipe.AddColorAttachment();
7654 pipe.AddShader(&vs);
7655 pipe.AddShader(&vs);
7656 pipe.AddShader(&fs);
7657
7658 VkDescriptorSetObj descriptorSet(m_device);
7659 descriptorSet.AppendDummy();
7660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7661
7662 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7663
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007664 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12007665}
7666
Karl Schultz6addd812016-02-02 17:17:23 -07007667TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007668 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13007669
7670 ASSERT_NO_FATAL_FAILURE(InitState());
7671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7672
7673 VkVertexInputBindingDescription input_binding;
7674 memset(&input_binding, 0, sizeof(input_binding));
7675
7676 VkVertexInputAttributeDescription input_attribs[2];
7677 memset(input_attribs, 0, sizeof(input_attribs));
7678
7679 for (int i = 0; i < 2; i++) {
7680 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
7681 input_attribs[i].location = i;
7682 }
7683
7684 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007685 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007686 "\n"
7687 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007688 "out gl_PerVertex {\n"
7689 " vec4 gl_Position;\n"
7690 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007691 "void main(){\n"
7692 " gl_Position = x[0] + x[1];\n"
7693 "}\n";
7694 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007695 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007696 "\n"
7697 "layout(location=0) out vec4 color;\n"
7698 "void main(){\n"
7699 " color = vec4(1);\n"
7700 "}\n";
7701
7702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7704
7705 VkPipelineObj pipe(m_device);
7706 pipe.AddColorAttachment();
7707 pipe.AddShader(&vs);
7708 pipe.AddShader(&fs);
7709
7710 pipe.AddVertexInputBindings(&input_binding, 1);
7711 pipe.AddVertexInputAttribs(input_attribs, 2);
7712
7713 VkDescriptorSetObj descriptorSet(m_device);
7714 descriptorSet.AppendDummy();
7715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7716
7717 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7718
7719 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007720 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13007721}
7722
Chris Forbes2682b242015-11-24 11:13:14 +13007723TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
7724{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007725 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13007726
7727 ASSERT_NO_FATAL_FAILURE(InitState());
7728 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7729
7730 VkVertexInputBindingDescription input_binding;
7731 memset(&input_binding, 0, sizeof(input_binding));
7732
7733 VkVertexInputAttributeDescription input_attribs[2];
7734 memset(input_attribs, 0, sizeof(input_attribs));
7735
7736 for (int i = 0; i < 2; i++) {
7737 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
7738 input_attribs[i].location = i;
7739 }
7740
7741 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007742 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007743 "\n"
7744 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07007745 "out gl_PerVertex {\n"
7746 " vec4 gl_Position;\n"
7747 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007748 "void main(){\n"
7749 " gl_Position = x[0] + x[1];\n"
7750 "}\n";
7751 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007752 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007753 "\n"
7754 "layout(location=0) out vec4 color;\n"
7755 "void main(){\n"
7756 " color = vec4(1);\n"
7757 "}\n";
7758
7759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7761
7762 VkPipelineObj pipe(m_device);
7763 pipe.AddColorAttachment();
7764 pipe.AddShader(&vs);
7765 pipe.AddShader(&fs);
7766
7767 pipe.AddVertexInputBindings(&input_binding, 1);
7768 pipe.AddVertexInputAttribs(input_attribs, 2);
7769
7770 VkDescriptorSetObj descriptorSet(m_device);
7771 descriptorSet.AppendDummy();
7772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7773
7774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7775
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007776 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13007777}
Chris Forbes2682b242015-11-24 11:13:14 +13007778
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007779TEST_F(VkLayerTest, CreatePipelineSimplePositive)
7780{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007781 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007782
7783 ASSERT_NO_FATAL_FAILURE(InitState());
7784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7785
7786 char const *vsSource =
7787 "#version 450\n"
7788 "out gl_PerVertex {\n"
7789 " vec4 gl_Position;\n"
7790 "};\n"
7791 "void main(){\n"
7792 " gl_Position = vec4(0);\n"
7793 "}\n";
7794 char const *fsSource =
7795 "#version 450\n"
7796 "\n"
7797 "layout(location=0) out vec4 color;\n"
7798 "void main(){\n"
7799 " color = vec4(1);\n"
7800 "}\n";
7801
7802 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7803 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7804
7805 VkPipelineObj pipe(m_device);
7806 pipe.AddColorAttachment();
7807 pipe.AddShader(&vs);
7808 pipe.AddShader(&fs);
7809
7810 VkDescriptorSetObj descriptorSet(m_device);
7811 descriptorSet.AppendDummy();
7812 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7813
7814 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7815
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007816 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007817}
7818
Chris Forbes912c9192016-04-05 17:50:35 +12007819TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
7820{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007821 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12007822
7823 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
7824
7825 ASSERT_NO_FATAL_FAILURE(InitState());
7826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7827
7828 char const *vsSource =
7829 "#version 450\n"
7830 "out gl_PerVertex {\n"
7831 " vec4 gl_Position;\n"
7832 "};\n"
7833 "layout(location=0) out vec3 x;\n"
7834 "layout(location=1) out ivec3 y;\n"
7835 "layout(location=2) out vec3 z;\n"
7836 "void main(){\n"
7837 " gl_Position = vec4(0);\n"
7838 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
7839 "}\n";
7840 char const *fsSource =
7841 "#version 450\n"
7842 "\n"
7843 "layout(location=0) out vec4 color;\n"
7844 "layout(location=0) in float x;\n"
7845 "layout(location=1) flat in int y;\n"
7846 "layout(location=2) in vec2 z;\n"
7847 "void main(){\n"
7848 " color = vec4(1 + x + y + z.x);\n"
7849 "}\n";
7850
7851 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7852 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7853
7854 VkPipelineObj pipe(m_device);
7855 pipe.AddColorAttachment();
7856 pipe.AddShader(&vs);
7857 pipe.AddShader(&fs);
7858
7859 VkDescriptorSetObj descriptorSet(m_device);
7860 descriptorSet.AppendDummy();
7861 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7862
7863 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7864
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007865 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12007866}
7867
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007868TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
7869{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007870 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007871
7872 ASSERT_NO_FATAL_FAILURE(InitState());
7873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7874
Chris Forbesc1e852d2016-04-04 19:26:42 +12007875 if (!m_device->phy().features().tessellationShader) {
7876 printf("Device does not support tessellation shaders; skipped.\n");
7877 return;
7878 }
7879
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007880 char const *vsSource =
7881 "#version 450\n"
7882 "void main(){}\n";
7883 char const *tcsSource =
7884 "#version 450\n"
7885 "layout(location=0) out int x[];\n"
7886 "layout(vertices=3) out;\n"
7887 "void main(){\n"
7888 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
7889 " gl_TessLevelInner[0] = 1;\n"
7890 " x[gl_InvocationID] = gl_InvocationID;\n"
7891 "}\n";
7892 char const *tesSource =
7893 "#version 450\n"
7894 "layout(triangles, equal_spacing, cw) in;\n"
7895 "layout(location=0) in int x[];\n"
7896 "out gl_PerVertex { vec4 gl_Position; };\n"
7897 "void main(){\n"
7898 " gl_Position.xyz = gl_TessCoord;\n"
7899 " gl_Position.w = x[0] + x[1] + x[2];\n"
7900 "}\n";
7901 char const *fsSource =
7902 "#version 450\n"
7903 "layout(location=0) out vec4 color;\n"
7904 "void main(){\n"
7905 " color = vec4(1);\n"
7906 "}\n";
7907
7908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7909 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
7910 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
7911 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7912
7913 VkPipelineInputAssemblyStateCreateInfo iasci{
7914 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
7915 nullptr,
7916 0,
7917 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
7918 VK_FALSE};
7919
Chris Forbesb4cacb62016-04-04 19:15:00 +12007920 VkPipelineTessellationStateCreateInfo tsci{
7921 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
7922 nullptr,
7923 0,
7924 3};
7925
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007926 VkPipelineObj pipe(m_device);
7927 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12007928 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007929 pipe.AddColorAttachment();
7930 pipe.AddShader(&vs);
7931 pipe.AddShader(&tcs);
7932 pipe.AddShader(&tes);
7933 pipe.AddShader(&fs);
7934
7935 VkDescriptorSetObj descriptorSet(m_device);
7936 descriptorSet.AppendDummy();
7937 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7938
7939 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7940
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007941 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007942}
7943
Chris Forbesa0ab8152016-04-20 13:34:27 +12007944TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
7945{
7946 m_errorMonitor->ExpectSuccess();
7947
7948 ASSERT_NO_FATAL_FAILURE(InitState());
7949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7950
7951 if (!m_device->phy().features().geometryShader) {
7952 printf("Device does not support geometry shaders; skipped.\n");
7953 return;
7954 }
7955
7956 char const *vsSource =
7957 "#version 450\n"
7958 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
7959 "void main(){\n"
7960 " vs_out.x = vec4(1);\n"
7961 "}\n";
7962 char const *gsSource =
7963 "#version 450\n"
7964 "layout(triangles) in;\n"
7965 "layout(triangle_strip, max_vertices=3) out;\n"
7966 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
7967 "out gl_PerVertex { vec4 gl_Position; };\n"
7968 "void main() {\n"
7969 " gl_Position = gs_in[0].x;\n"
7970 " EmitVertex();\n"
7971 "}\n";
7972 char const *fsSource =
7973 "#version 450\n"
7974 "layout(location=0) out vec4 color;\n"
7975 "void main(){\n"
7976 " color = vec4(1);\n"
7977 "}\n";
7978
7979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7980 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
7981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7982
7983 VkPipelineObj pipe(m_device);
7984 pipe.AddColorAttachment();
7985 pipe.AddShader(&vs);
7986 pipe.AddShader(&gs);
7987 pipe.AddShader(&fs);
7988
7989 VkDescriptorSetObj descriptorSet(m_device);
7990 descriptorSet.AppendDummy();
7991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7992
7993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7994
7995 m_errorMonitor->VerifyNotFound();
7996}
7997
Chris Forbesa0193bc2016-04-04 19:19:47 +12007998TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
7999{
8000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8001 "is per-vertex in tessellation control shader stage "
8002 "but per-patch in tessellation evaluation shader stage");
8003
8004 ASSERT_NO_FATAL_FAILURE(InitState());
8005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8006
Chris Forbesc1e852d2016-04-04 19:26:42 +12008007 if (!m_device->phy().features().tessellationShader) {
8008 printf("Device does not support tessellation shaders; skipped.\n");
8009 return;
8010 }
8011
Chris Forbesa0193bc2016-04-04 19:19:47 +12008012 char const *vsSource =
8013 "#version 450\n"
8014 "void main(){}\n";
8015 char const *tcsSource =
8016 "#version 450\n"
8017 "layout(location=0) out int x[];\n"
8018 "layout(vertices=3) out;\n"
8019 "void main(){\n"
8020 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
8021 " gl_TessLevelInner[0] = 1;\n"
8022 " x[gl_InvocationID] = gl_InvocationID;\n"
8023 "}\n";
8024 char const *tesSource =
8025 "#version 450\n"
8026 "layout(triangles, equal_spacing, cw) in;\n"
8027 "layout(location=0) patch in int x;\n"
8028 "out gl_PerVertex { vec4 gl_Position; };\n"
8029 "void main(){\n"
8030 " gl_Position.xyz = gl_TessCoord;\n"
8031 " gl_Position.w = x;\n"
8032 "}\n";
8033 char const *fsSource =
8034 "#version 450\n"
8035 "layout(location=0) out vec4 color;\n"
8036 "void main(){\n"
8037 " color = vec4(1);\n"
8038 "}\n";
8039
8040 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8041 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
8042 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
8043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8044
8045 VkPipelineInputAssemblyStateCreateInfo iasci{
8046 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
8047 nullptr,
8048 0,
8049 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
8050 VK_FALSE};
8051
8052 VkPipelineTessellationStateCreateInfo tsci{
8053 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
8054 nullptr,
8055 0,
8056 3};
8057
8058 VkPipelineObj pipe(m_device);
8059 pipe.SetInputAssembly(&iasci);
8060 pipe.SetTessellation(&tsci);
8061 pipe.AddColorAttachment();
8062 pipe.AddShader(&vs);
8063 pipe.AddShader(&tcs);
8064 pipe.AddShader(&tes);
8065 pipe.AddShader(&fs);
8066
8067 VkDescriptorSetObj descriptorSet(m_device);
8068 descriptorSet.AppendDummy();
8069 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8070
8071 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8072
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008073 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12008074}
8075
Karl Schultz6addd812016-02-02 17:17:23 -07008076TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
8077 m_errorMonitor->SetDesiredFailureMsg(
8078 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008079 "Duplicate vertex input binding descriptions for binding 0");
8080
Chris Forbes280ba2c2015-06-12 11:16:41 +12008081 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12008083
8084 /* Two binding descriptions for binding 0 */
8085 VkVertexInputBindingDescription input_bindings[2];
8086 memset(input_bindings, 0, sizeof(input_bindings));
8087
8088 VkVertexInputAttributeDescription input_attrib;
8089 memset(&input_attrib, 0, sizeof(input_attrib));
8090 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8091
8092 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008093 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008094 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008095 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07008096 "out gl_PerVertex {\n"
8097 " vec4 gl_Position;\n"
8098 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008099 "void main(){\n"
8100 " gl_Position = vec4(x);\n"
8101 "}\n";
8102 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008103 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008104 "\n"
8105 "layout(location=0) out vec4 color;\n"
8106 "void main(){\n"
8107 " color = vec4(1);\n"
8108 "}\n";
8109
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12008112
8113 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008114 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12008115 pipe.AddShader(&vs);
8116 pipe.AddShader(&fs);
8117
8118 pipe.AddVertexInputBindings(input_bindings, 2);
8119 pipe.AddVertexInputAttribs(&input_attrib, 1);
8120
Chris Forbes280ba2c2015-06-12 11:16:41 +12008121 VkDescriptorSetObj descriptorSet(m_device);
8122 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008123 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12008124
Tony Barbour5781e8f2015-08-04 16:23:11 -06008125 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12008126
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008127 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12008128}
Chris Forbes8f68b562015-05-25 11:13:32 +12008129
Chris Forbes35efec72016-04-21 14:32:08 +12008130TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
8131 m_errorMonitor->ExpectSuccess();
8132
8133 ASSERT_NO_FATAL_FAILURE(InitState());
8134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8135
8136 if (!m_device->phy().features().tessellationShader) {
8137 printf("Device does not support 64bit vertex attributes; skipped.\n");
8138 return;
8139 }
8140
8141 VkVertexInputBindingDescription input_bindings[1];
8142 memset(input_bindings, 0, sizeof(input_bindings));
8143
8144 VkVertexInputAttributeDescription input_attribs[4];
8145 memset(input_attribs, 0, sizeof(input_attribs));
8146 input_attribs[0].location = 0;
8147 input_attribs[0].offset = 0;
8148 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8149 input_attribs[1].location = 2;
8150 input_attribs[1].offset = 32;
8151 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8152 input_attribs[2].location = 4;
8153 input_attribs[2].offset = 64;
8154 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8155 input_attribs[3].location = 6;
8156 input_attribs[3].offset = 96;
8157 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8158
8159 char const *vsSource =
8160 "#version 450\n"
8161 "\n"
8162 "layout(location=0) in dmat4 x;\n"
8163 "out gl_PerVertex {\n"
8164 " vec4 gl_Position;\n"
8165 "};\n"
8166 "void main(){\n"
8167 " gl_Position = vec4(x[0][0]);\n"
8168 "}\n";
8169 char const *fsSource =
8170 "#version 450\n"
8171 "\n"
8172 "layout(location=0) out vec4 color;\n"
8173 "void main(){\n"
8174 " color = vec4(1);\n"
8175 "}\n";
8176
8177 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8178 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8179
8180 VkPipelineObj pipe(m_device);
8181 pipe.AddColorAttachment();
8182 pipe.AddShader(&vs);
8183 pipe.AddShader(&fs);
8184
8185 pipe.AddVertexInputBindings(input_bindings, 1);
8186 pipe.AddVertexInputAttribs(input_attribs, 4);
8187
8188 VkDescriptorSetObj descriptorSet(m_device);
8189 descriptorSet.AppendDummy();
8190 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8191
8192 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8193
8194 m_errorMonitor->VerifyNotFound();
8195}
8196
Karl Schultz6addd812016-02-02 17:17:23 -07008197TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008199 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008200
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008201 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008202
8203 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008204 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008205 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008206 "out gl_PerVertex {\n"
8207 " vec4 gl_Position;\n"
8208 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008209 "void main(){\n"
8210 " gl_Position = vec4(1);\n"
8211 "}\n";
8212 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008213 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008214 "\n"
8215 "void main(){\n"
8216 "}\n";
8217
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008218 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8219 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008220
8221 VkPipelineObj pipe(m_device);
8222 pipe.AddShader(&vs);
8223 pipe.AddShader(&fs);
8224
Chia-I Wu08accc62015-07-07 11:50:03 +08008225 /* set up CB 0, not written */
8226 pipe.AddColorAttachment();
8227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008228
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008229 VkDescriptorSetObj descriptorSet(m_device);
8230 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008232
Tony Barbour5781e8f2015-08-04 16:23:11 -06008233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008234
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008235 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008236}
8237
Karl Schultz6addd812016-02-02 17:17:23 -07008238TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07008239 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008240 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008241 "FS writes to output location 1 with no matching attachment");
8242
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008243 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008244
8245 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008246 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008247 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008248 "out gl_PerVertex {\n"
8249 " vec4 gl_Position;\n"
8250 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008251 "void main(){\n"
8252 " gl_Position = vec4(1);\n"
8253 "}\n";
8254 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008255 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008256 "\n"
8257 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008258 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008259 "void main(){\n"
8260 " x = vec4(1);\n"
8261 " y = vec4(1);\n"
8262 "}\n";
8263
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008264 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8265 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008266
8267 VkPipelineObj pipe(m_device);
8268 pipe.AddShader(&vs);
8269 pipe.AddShader(&fs);
8270
Chia-I Wu08accc62015-07-07 11:50:03 +08008271 /* set up CB 0, not written */
8272 pipe.AddColorAttachment();
8273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008274 /* FS writes CB 1, but we don't configure it */
8275
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008276 VkDescriptorSetObj descriptorSet(m_device);
8277 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008278 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008279
Tony Barbour5781e8f2015-08-04 16:23:11 -06008280 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008282 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008283}
8284
Karl Schultz6addd812016-02-02 17:17:23 -07008285TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008287 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008288
Chris Forbesa36d69e2015-05-25 11:13:44 +12008289 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008290
8291 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008292 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008293 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008294 "out gl_PerVertex {\n"
8295 " vec4 gl_Position;\n"
8296 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008297 "void main(){\n"
8298 " gl_Position = vec4(1);\n"
8299 "}\n";
8300 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008301 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008302 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008303 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12008304 "void main(){\n"
8305 " x = ivec4(1);\n"
8306 "}\n";
8307
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8309 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12008310
8311 VkPipelineObj pipe(m_device);
8312 pipe.AddShader(&vs);
8313 pipe.AddShader(&fs);
8314
Chia-I Wu08accc62015-07-07 11:50:03 +08008315 /* set up CB 0; type is UNORM by default */
8316 pipe.AddColorAttachment();
8317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008318
Chris Forbesa36d69e2015-05-25 11:13:44 +12008319 VkDescriptorSetObj descriptorSet(m_device);
8320 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008321 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12008322
Tony Barbour5781e8f2015-08-04 16:23:11 -06008323 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008324
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008325 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12008326}
Chris Forbes7b1b8932015-06-05 14:43:36 +12008327
Karl Schultz6addd812016-02-02 17:17:23 -07008328TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008330 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008331
Chris Forbes556c76c2015-08-14 12:04:59 +12008332 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12008333
8334 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008335 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008336 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008337 "out gl_PerVertex {\n"
8338 " vec4 gl_Position;\n"
8339 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008340 "void main(){\n"
8341 " gl_Position = vec4(1);\n"
8342 "}\n";
8343 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008344 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008345 "\n"
8346 "layout(location=0) out vec4 x;\n"
8347 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8348 "void main(){\n"
8349 " x = vec4(bar.y);\n"
8350 "}\n";
8351
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12008354
Chris Forbes556c76c2015-08-14 12:04:59 +12008355 VkPipelineObj pipe(m_device);
8356 pipe.AddShader(&vs);
8357 pipe.AddShader(&fs);
8358
8359 /* set up CB 0; type is UNORM by default */
8360 pipe.AddColorAttachment();
8361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8362
8363 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12008365
8366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8367
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008368 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12008369}
8370
Chris Forbes5c59e902016-02-26 16:56:09 +13008371TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
8372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8373 "not declared in layout");
8374
8375 ASSERT_NO_FATAL_FAILURE(InitState());
8376
8377 char const *vsSource =
8378 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13008379 "\n"
8380 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
8381 "out gl_PerVertex {\n"
8382 " vec4 gl_Position;\n"
8383 "};\n"
8384 "void main(){\n"
8385 " gl_Position = vec4(consts.x);\n"
8386 "}\n";
8387 char const *fsSource =
8388 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13008389 "\n"
8390 "layout(location=0) out vec4 x;\n"
8391 "void main(){\n"
8392 " x = vec4(1);\n"
8393 "}\n";
8394
8395 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8397
8398 VkPipelineObj pipe(m_device);
8399 pipe.AddShader(&vs);
8400 pipe.AddShader(&fs);
8401
8402 /* set up CB 0; type is UNORM by default */
8403 pipe.AddColorAttachment();
8404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8405
8406 VkDescriptorSetObj descriptorSet(m_device);
8407 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8408
8409 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8410
8411 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008412 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13008413}
8414
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008415#endif // SHADER_CHECKER_TESTS
8416
8417#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06008418TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07008419 m_errorMonitor->SetDesiredFailureMsg(
8420 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008421 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008422
8423 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008424
8425 // Create an image
8426 VkImage image;
8427
Karl Schultz6addd812016-02-02 17:17:23 -07008428 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8429 const int32_t tex_width = 32;
8430 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008431
8432 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8434 image_create_info.pNext = NULL;
8435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8436 image_create_info.format = tex_format;
8437 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008438 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07008439 image_create_info.extent.depth = 1;
8440 image_create_info.mipLevels = 1;
8441 image_create_info.arrayLayers = 1;
8442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8444 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8445 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008446
8447 // Introduce error by sending down a bogus width extent
8448 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008449 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008450
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008451 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008452}
8453
Mark Youngc48c4c12016-04-11 14:26:49 -06008454TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
8455 m_errorMonitor->SetDesiredFailureMsg(
8456 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8457 "CreateImage extents is 0 for at least one required dimension");
8458
8459 ASSERT_NO_FATAL_FAILURE(InitState());
8460
8461 // Create an image
8462 VkImage image;
8463
8464 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8465 const int32_t tex_width = 32;
8466 const int32_t tex_height = 32;
8467
8468 VkImageCreateInfo image_create_info = {};
8469 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8470 image_create_info.pNext = NULL;
8471 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8472 image_create_info.format = tex_format;
8473 image_create_info.extent.width = tex_width;
8474 image_create_info.extent.height = tex_height;
8475 image_create_info.extent.depth = 1;
8476 image_create_info.mipLevels = 1;
8477 image_create_info.arrayLayers = 1;
8478 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8479 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8480 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8481 image_create_info.flags = 0;
8482
8483 // Introduce error by sending down a bogus width extent
8484 image_create_info.extent.width = 0;
8485 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8486
8487 m_errorMonitor->VerifyFound();
8488}
8489
Karl Schultz6addd812016-02-02 17:17:23 -07008490TEST_F(VkLayerTest, UpdateBufferAlignment) {
8491 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06008492
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008494 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008495
Mike Stroyana3082432015-09-25 13:39:21 -06008496 ASSERT_NO_FATAL_FAILURE(InitState());
8497
8498 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8499 vk_testing::Buffer buffer;
8500 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
8501
8502 BeginCommandBuffer();
8503 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008504 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008505 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008506
Mike Stroyana3082432015-09-25 13:39:21 -06008507 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008509 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008510
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008511 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008512 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008513 EndCommandBuffer();
8514}
8515
Karl Schultz6addd812016-02-02 17:17:23 -07008516TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008518 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06008519
8520 ASSERT_NO_FATAL_FAILURE(InitState());
8521
8522 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8523 vk_testing::Buffer buffer;
8524 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
8525
8526 BeginCommandBuffer();
8527 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008528 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008529 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008530
Mike Stroyana3082432015-09-25 13:39:21 -06008531 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008533 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008534
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008535 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008536
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008537 m_errorMonitor->VerifyFound();
8538
Mike Stroyana3082432015-09-25 13:39:21 -06008539 EndCommandBuffer();
8540}
8541
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008542#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12008543
Tobin Ehliscde08892015-09-22 10:11:37 -06008544#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008545TEST_F(VkLayerTest, InvalidImageView) {
8546 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06008547
Karl Schultz6addd812016-02-02 17:17:23 -07008548 m_errorMonitor->SetDesiredFailureMsg(
8549 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008550 "vkCreateImageView called with baseMipLevel 10 ");
8551
Tobin Ehliscde08892015-09-22 10:11:37 -06008552 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06008553
Mike Stroyana3082432015-09-25 13:39:21 -06008554 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07008555 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06008556
Karl Schultz6addd812016-02-02 17:17:23 -07008557 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8558 const int32_t tex_width = 32;
8559 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06008560
8561 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008562 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8563 image_create_info.pNext = NULL;
8564 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8565 image_create_info.format = tex_format;
8566 image_create_info.extent.width = tex_width;
8567 image_create_info.extent.height = tex_height;
8568 image_create_info.extent.depth = 1;
8569 image_create_info.mipLevels = 1;
8570 image_create_info.arrayLayers = 1;
8571 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8572 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8573 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8574 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06008575
Chia-I Wuf7458c52015-10-26 21:10:41 +08008576 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06008577 ASSERT_VK_SUCCESS(err);
8578
8579 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008580 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8581 image_view_create_info.image = image;
8582 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8583 image_view_create_info.format = tex_format;
8584 image_view_create_info.subresourceRange.layerCount = 1;
8585 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
8586 image_view_create_info.subresourceRange.levelCount = 1;
8587 image_view_create_info.subresourceRange.aspectMask =
8588 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06008589
8590 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07008591 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
8592 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06008593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008594 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06008595}
Mike Stroyana3082432015-09-25 13:39:21 -06008596
Karl Schultz6addd812016-02-02 17:17:23 -07008597TEST_F(VkLayerTest, InvalidImageViewAspect) {
8598 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008599
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008601 "vkCreateImageView: Color image "
8602 "formats must have ONLY the "
8603 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008604
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008605 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008606
8607 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07008608 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008609
Karl Schultz6addd812016-02-02 17:17:23 -07008610 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8611 const int32_t tex_width = 32;
8612 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008613
8614 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008615 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8616 image_create_info.pNext = NULL;
8617 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8618 image_create_info.format = tex_format;
8619 image_create_info.extent.width = tex_width;
8620 image_create_info.extent.height = tex_height;
8621 image_create_info.extent.depth = 1;
8622 image_create_info.mipLevels = 1;
8623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8624 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8625 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8626 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008627
Chia-I Wuf7458c52015-10-26 21:10:41 +08008628 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008629 ASSERT_VK_SUCCESS(err);
8630
8631 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008632 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8633 image_view_create_info.image = image;
8634 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8635 image_view_create_info.format = tex_format;
8636 image_view_create_info.subresourceRange.baseMipLevel = 0;
8637 image_view_create_info.subresourceRange.levelCount = 1;
8638 // Cause an error by setting an invalid image aspect
8639 image_view_create_info.subresourceRange.aspectMask =
8640 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008641
8642 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07008643 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
8644 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008645
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008646 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008647}
8648
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008649TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07008650 VkResult err;
8651 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06008652
Karl Schultz6addd812016-02-02 17:17:23 -07008653 m_errorMonitor->SetDesiredFailureMsg(
8654 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008655 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008656
Mike Stroyana3082432015-09-25 13:39:21 -06008657 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06008658
8659 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07008660 VkImage srcImage;
8661 VkImage dstImage;
8662 VkDeviceMemory srcMem;
8663 VkDeviceMemory destMem;
8664 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06008665
8666 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008667 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8668 image_create_info.pNext = NULL;
8669 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8670 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
8671 image_create_info.extent.width = 32;
8672 image_create_info.extent.height = 32;
8673 image_create_info.extent.depth = 1;
8674 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008675 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -07008676 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8677 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8678 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8679 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008680
Karl Schultz6addd812016-02-02 17:17:23 -07008681 err =
8682 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008683 ASSERT_VK_SUCCESS(err);
8684
Karl Schultz6addd812016-02-02 17:17:23 -07008685 err =
8686 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008687 ASSERT_VK_SUCCESS(err);
8688
8689 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008690 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008691 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8692 memAlloc.pNext = NULL;
8693 memAlloc.allocationSize = 0;
8694 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008695
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06008696 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008697 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008698 pass =
8699 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06008700 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008701 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008702 ASSERT_VK_SUCCESS(err);
8703
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008705 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008706 pass =
8707 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008708 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008709 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008710 ASSERT_VK_SUCCESS(err);
8711
8712 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
8713 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008714 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008715 ASSERT_VK_SUCCESS(err);
8716
8717 BeginCommandBuffer();
8718 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008719 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06008720 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06008721 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008722 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06008723 copyRegion.srcOffset.x = 0;
8724 copyRegion.srcOffset.y = 0;
8725 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008726 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008727 copyRegion.dstSubresource.mipLevel = 0;
8728 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008729 // Introduce failure by forcing the dst layerCount to differ from src
8730 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008731 copyRegion.dstOffset.x = 0;
8732 copyRegion.dstOffset.y = 0;
8733 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008734 copyRegion.extent.width = 1;
8735 copyRegion.extent.height = 1;
8736 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008737 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
8738 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06008739 EndCommandBuffer();
8740
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008741 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008742
Chia-I Wuf7458c52015-10-26 21:10:41 +08008743 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008744 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08008745 vkFreeMemory(m_device->device(), srcMem, NULL);
8746 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06008747}
8748
Tony Barbourd6673642016-05-05 14:46:39 -06008749TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
8750
8751 TEST_DESCRIPTION("Creating images with unsuported formats ");
8752
8753 ASSERT_NO_FATAL_FAILURE(InitState());
8754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8755 VkImageObj image(m_device);
8756 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8757 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8758 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8759 VK_IMAGE_TILING_OPTIMAL, 0);
8760 ASSERT_TRUE(image.initialized());
8761
8762 VkFormat unsupported = VK_FORMAT_UNDEFINED;
8763 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
8764 VkFormat format = static_cast<VkFormat>(f);
8765 VkFormatProperties fProps = m_device->format_properties(format);
8766 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
8767 fProps.optimalTilingFeatures == 0) {
8768 unsupported = format;
8769 break;
8770 }
8771 }
8772 if (unsupported != VK_FORMAT_UNDEFINED) {
8773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8774 "vkCreateImage parameter, "
8775 "VkFormat pCreateInfo->format, "
8776 "contains unsupported format");
8777 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
8778 VkImageCreateInfo image_create_info;
8779 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8780 image_create_info.pNext = NULL;
8781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8782 image_create_info.format = unsupported;
8783 image_create_info.extent.width = 32;
8784 image_create_info.extent.height = 32;
8785 image_create_info.extent.depth = 1;
8786 image_create_info.mipLevels = 1;
8787 image_create_info.arrayLayers = 1;
8788 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8789 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8790 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8791 image_create_info.flags = 0;
8792
8793 VkImage localImage;
8794 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
8795 m_errorMonitor->VerifyFound();
8796
8797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8798 "vkCreateRenderPass parameter, "
8799 "VkFormat in "
8800 "pCreateInfo->pAttachments");
8801 // Create renderpass with unsupported format - Expect FORMAT_UNSUPPORTED
8802 VkAttachmentDescription att;
8803 att.format = unsupported;
8804 att.samples = VK_SAMPLE_COUNT_1_BIT;
8805 att.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
8806 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8807 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8808 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8809 att.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8810 att.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8811
8812 VkRenderPassCreateInfo rp_info = {};
8813 VkRenderPass rp;
8814 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8815 rp_info.attachmentCount = 1;
8816 rp_info.pAttachments = &att;
8817 rp_info.subpassCount = 0;
8818 rp_info.pSubpasses = NULL;
8819 vkCreateRenderPass(m_device->handle(), &rp_info, NULL, &rp);
8820 m_errorMonitor->VerifyFound();
8821 }
8822}
8823
8824TEST_F(VkLayerTest, ImageLayerViewTests) {
8825 VkResult ret;
8826 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
8827
8828 ASSERT_NO_FATAL_FAILURE(InitState());
8829
8830 VkImageObj image(m_device);
8831 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8832 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8833 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8834 VK_IMAGE_TILING_OPTIMAL, 0);
8835 ASSERT_TRUE(image.initialized());
8836
8837 VkImageView imgView;
8838 VkImageViewCreateInfo imgViewInfo = {};
8839 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8840 imgViewInfo.image = image.handle();
8841 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
8842 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8843 imgViewInfo.subresourceRange.layerCount = 1;
8844 imgViewInfo.subresourceRange.baseMipLevel = 0;
8845 imgViewInfo.subresourceRange.levelCount = 1;
8846 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8847
8848 m_errorMonitor->SetDesiredFailureMsg(
8849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8850 "vkCreateImageView called with baseMipLevel");
8851 // View can't have baseMipLevel >= image's mipLevels - Expect
8852 // VIEW_CREATE_ERROR
8853 imgViewInfo.subresourceRange.baseMipLevel = 1;
8854 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8855 m_errorMonitor->VerifyFound();
8856 imgViewInfo.subresourceRange.baseMipLevel = 0;
8857
8858 m_errorMonitor->SetDesiredFailureMsg(
8859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8860 "vkCreateImageView called with baseArrayLayer");
8861 // View can't have baseArrayLayer >= image's arraySize - Expect
8862 // VIEW_CREATE_ERROR
8863 imgViewInfo.subresourceRange.baseArrayLayer = 1;
8864 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8865 m_errorMonitor->VerifyFound();
8866 imgViewInfo.subresourceRange.baseArrayLayer = 0;
8867
8868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8869 "vkCreateImageView called with 0 in "
8870 "pCreateInfo->subresourceRange."
8871 "levelCount");
8872 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
8873 imgViewInfo.subresourceRange.levelCount = 0;
8874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8875 m_errorMonitor->VerifyFound();
8876 imgViewInfo.subresourceRange.levelCount = 1;
8877
8878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8879 "vkCreateImageView called with 0 in "
8880 "pCreateInfo->subresourceRange."
8881 "layerCount");
8882 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
8883 imgViewInfo.subresourceRange.layerCount = 0;
8884 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8885 m_errorMonitor->VerifyFound();
8886 imgViewInfo.subresourceRange.layerCount = 1;
8887
8888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "but both must be color formats");
8890 // Can't use depth format for view into color image - Expect INVALID_FORMAT
8891 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
8892 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8893 m_errorMonitor->VerifyFound();
8894 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8895
8896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8897 "Formats MUST be IDENTICAL unless "
8898 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
8899 "was set on image creation.");
8900 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
8901 // VIEW_CREATE_ERROR
8902 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
8903 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8904 m_errorMonitor->VerifyFound();
8905 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8906
8907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8908 "can support ImageViews with "
8909 "differing formats but they must be "
8910 "in the same compatibility class.");
8911 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
8912 // VIEW_CREATE_ERROR
8913 VkImageCreateInfo mutImgInfo = image.create_info();
8914 VkImage mutImage;
8915 mutImgInfo.format = VK_FORMAT_R8_UINT;
8916 assert(
8917 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
8918 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
8919 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
8920 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
8921 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
8922 ASSERT_VK_SUCCESS(ret);
8923 imgViewInfo.image = mutImage;
8924 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8925 m_errorMonitor->VerifyFound();
8926 imgViewInfo.image = image.handle();
8927 vkDestroyImage(m_device->handle(), mutImage, NULL);
8928}
8929
8930TEST_F(VkLayerTest, MiscImageLayerTests) {
8931
8932 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
8933
8934 ASSERT_NO_FATAL_FAILURE(InitState());
8935
8936 VkImageObj image(m_device);
8937 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8938 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8939 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8940 VK_IMAGE_TILING_OPTIMAL, 0);
8941 ASSERT_TRUE(image.initialized());
8942
8943 m_errorMonitor->SetDesiredFailureMsg(
8944 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8945 "number of layers in image subresource is zero");
8946 vk_testing::Buffer buffer;
8947 VkMemoryPropertyFlags reqs = 0;
8948 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
8949 VkBufferImageCopy region = {};
8950 region.bufferRowLength = 128;
8951 region.bufferImageHeight = 128;
8952 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8953 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
8954 region.imageSubresource.layerCount = 0;
8955 region.imageExtent.height = 4;
8956 region.imageExtent.width = 4;
8957 region.imageExtent.depth = 1;
8958 m_commandBuffer->BeginCommandBuffer();
8959 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
8960 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
8961 1, &region);
8962 m_errorMonitor->VerifyFound();
8963 region.imageSubresource.layerCount = 1;
8964
8965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8966 "aspectMasks for each region must "
8967 "specify only COLOR or DEPTH or "
8968 "STENCIL");
8969 // Expect MISMATCHED_IMAGE_ASPECT
8970 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
8971 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
8972 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
8973 1, &region);
8974 m_errorMonitor->VerifyFound();
8975 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8976
8977 m_errorMonitor->SetDesiredFailureMsg(
8978 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8979 "If the format of srcImage is a depth, stencil, depth stencil or "
8980 "integer-based format then filter must be VK_FILTER_NEAREST");
8981 // Expect INVALID_FILTER
8982 VkImageObj intImage1(m_device);
8983 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
8984 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
8985 0);
8986 VkImageObj intImage2(m_device);
8987 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
8988 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
8989 0);
8990 VkImageBlit blitRegion = {};
8991 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8992 blitRegion.srcSubresource.baseArrayLayer = 0;
8993 blitRegion.srcSubresource.layerCount = 1;
8994 blitRegion.srcSubresource.mipLevel = 0;
8995 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8996 blitRegion.dstSubresource.baseArrayLayer = 0;
8997 blitRegion.dstSubresource.layerCount = 1;
8998 blitRegion.dstSubresource.mipLevel = 0;
8999
9000 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
9001 intImage1.layout(), intImage2.handle(), intImage2.layout(),
9002 16, &blitRegion, VK_FILTER_LINEAR);
9003 m_errorMonitor->VerifyFound();
9004
9005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9006 "called with 0 in ppMemoryBarriers");
9007 VkImageMemoryBarrier img_barrier;
9008 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9009 img_barrier.pNext = NULL;
9010 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9011 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9012 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9013 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9014 img_barrier.image = image.handle();
9015 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9016 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9018 img_barrier.subresourceRange.baseArrayLayer = 0;
9019 img_barrier.subresourceRange.baseMipLevel = 0;
9020 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
9021 img_barrier.subresourceRange.layerCount = 0;
9022 img_barrier.subresourceRange.levelCount = 1;
9023 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
9024 VK_PIPELINE_STAGE_HOST_BIT,
9025 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
9026 nullptr, 1, &img_barrier);
9027 m_errorMonitor->VerifyFound();
9028 img_barrier.subresourceRange.layerCount = 1;
9029}
9030
9031TEST_F(VkLayerTest, ImageFormatLimits) {
9032
9033 TEST_DESCRIPTION("Exceed the limits of image format ");
9034
9035 m_errorMonitor->SetDesiredFailureMsg(
9036 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9037 "CreateImage extents exceed allowable limits for format");
9038 VkImageCreateInfo image_create_info = {};
9039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9040 image_create_info.pNext = NULL;
9041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9042 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9043 image_create_info.extent.width = 32;
9044 image_create_info.extent.height = 32;
9045 image_create_info.extent.depth = 1;
9046 image_create_info.mipLevels = 1;
9047 image_create_info.arrayLayers = 1;
9048 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9049 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9050 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9051 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9052 image_create_info.flags = 0;
9053
9054 VkImage nullImg;
9055 VkImageFormatProperties imgFmtProps;
9056 vkGetPhysicalDeviceImageFormatProperties(
9057 gpu(), image_create_info.format, image_create_info.imageType,
9058 image_create_info.tiling, image_create_info.usage,
9059 image_create_info.flags, &imgFmtProps);
9060 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
9061 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9062 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9063 m_errorMonitor->VerifyFound();
9064 image_create_info.extent.depth = 1;
9065
9066 m_errorMonitor->SetDesiredFailureMsg(
9067 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9068 "exceeds allowable maximum supported by format of");
9069 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
9070 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9071 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9072 m_errorMonitor->VerifyFound();
9073 image_create_info.mipLevels = 1;
9074
9075 m_errorMonitor->SetDesiredFailureMsg(
9076 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9077 "exceeds allowable maximum supported by format of");
9078 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
9079 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9080 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9081 m_errorMonitor->VerifyFound();
9082 image_create_info.arrayLayers = 1;
9083
9084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9085 "is not supported by format");
9086 int samples = imgFmtProps.sampleCounts >> 1;
9087 image_create_info.samples = (VkSampleCountFlagBits)samples;
9088 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9089 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9090 m_errorMonitor->VerifyFound();
9091 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9092
9093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9094 "pCreateInfo->initialLayout, must be "
9095 "VK_IMAGE_LAYOUT_UNDEFINED or "
9096 "VK_IMAGE_LAYOUT_PREINITIALIZED");
9097 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9098 // Expect INVALID_LAYOUT
9099 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9100 m_errorMonitor->VerifyFound();
9101 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9102}
9103
Karl Schultz6addd812016-02-02 17:17:23 -07009104TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -06009105 VkResult err;
9106 bool pass;
9107
9108 // Create color images with different format sizes and try to copy between them
9109 m_errorMonitor->SetDesiredFailureMsg(
9110 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9111 "vkCmdCopyImage called with unmatched source and dest image format sizes");
9112
9113 ASSERT_NO_FATAL_FAILURE(InitState());
9114
9115 // Create two images of different types and try to copy between them
9116 VkImage srcImage;
9117 VkImage dstImage;
9118 VkDeviceMemory srcMem;
9119 VkDeviceMemory destMem;
9120 VkMemoryRequirements memReqs;
9121
9122 VkImageCreateInfo image_create_info = {};
9123 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9124 image_create_info.pNext = NULL;
9125 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9126 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9127 image_create_info.extent.width = 32;
9128 image_create_info.extent.height = 32;
9129 image_create_info.extent.depth = 1;
9130 image_create_info.mipLevels = 1;
9131 image_create_info.arrayLayers = 1;
9132 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9133 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9134 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9135 image_create_info.flags = 0;
9136
9137 err =
9138 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
9139 ASSERT_VK_SUCCESS(err);
9140
9141 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
9142 // Introduce failure by creating second image with a different-sized format.
9143 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
9144
9145 err =
9146 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
9147 ASSERT_VK_SUCCESS(err);
9148
9149 // Allocate memory
9150 VkMemoryAllocateInfo memAlloc = {};
9151 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9152 memAlloc.pNext = NULL;
9153 memAlloc.allocationSize = 0;
9154 memAlloc.memoryTypeIndex = 0;
9155
9156 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
9157 memAlloc.allocationSize = memReqs.size;
9158 pass =
9159 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
9160 ASSERT_TRUE(pass);
9161 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
9162 ASSERT_VK_SUCCESS(err);
9163
9164 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
9165 memAlloc.allocationSize = memReqs.size;
9166 pass =
9167 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
9168 ASSERT_TRUE(pass);
9169 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
9170 ASSERT_VK_SUCCESS(err);
9171
9172 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9173 ASSERT_VK_SUCCESS(err);
9174 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
9175 ASSERT_VK_SUCCESS(err);
9176
9177 BeginCommandBuffer();
9178 VkImageCopy copyRegion;
9179 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9180 copyRegion.srcSubresource.mipLevel = 0;
9181 copyRegion.srcSubresource.baseArrayLayer = 0;
9182 copyRegion.srcSubresource.layerCount = 0;
9183 copyRegion.srcOffset.x = 0;
9184 copyRegion.srcOffset.y = 0;
9185 copyRegion.srcOffset.z = 0;
9186 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9187 copyRegion.dstSubresource.mipLevel = 0;
9188 copyRegion.dstSubresource.baseArrayLayer = 0;
9189 copyRegion.dstSubresource.layerCount = 0;
9190 copyRegion.dstOffset.x = 0;
9191 copyRegion.dstOffset.y = 0;
9192 copyRegion.dstOffset.z = 0;
9193 copyRegion.extent.width = 1;
9194 copyRegion.extent.height = 1;
9195 copyRegion.extent.depth = 1;
9196 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9197 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9198 EndCommandBuffer();
9199
9200 m_errorMonitor->VerifyFound();
9201
9202 vkDestroyImage(m_device->device(), srcImage, NULL);
9203 vkDestroyImage(m_device->device(), dstImage, NULL);
9204 vkFreeMemory(m_device->device(), srcMem, NULL);
9205 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009206}
9207
Karl Schultz6addd812016-02-02 17:17:23 -07009208TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
9209 VkResult err;
9210 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009211
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009212 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009213 m_errorMonitor->SetDesiredFailureMsg(
9214 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009215 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009216
Mike Stroyana3082432015-09-25 13:39:21 -06009217 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009218
9219 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009220 VkImage srcImage;
9221 VkImage dstImage;
9222 VkDeviceMemory srcMem;
9223 VkDeviceMemory destMem;
9224 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009225
9226 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009227 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9228 image_create_info.pNext = NULL;
9229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9230 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9231 image_create_info.extent.width = 32;
9232 image_create_info.extent.height = 32;
9233 image_create_info.extent.depth = 1;
9234 image_create_info.mipLevels = 1;
9235 image_create_info.arrayLayers = 1;
9236 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9237 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9238 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9239 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009240
Karl Schultz6addd812016-02-02 17:17:23 -07009241 err =
9242 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009243 ASSERT_VK_SUCCESS(err);
9244
Karl Schultzbdb75952016-04-19 11:36:49 -06009245 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
9246
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009247 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -07009248 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009249 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
9250 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009251
Karl Schultz6addd812016-02-02 17:17:23 -07009252 err =
9253 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009254 ASSERT_VK_SUCCESS(err);
9255
9256 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009257 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009258 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9259 memAlloc.pNext = NULL;
9260 memAlloc.allocationSize = 0;
9261 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009262
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009263 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009264 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009265 pass =
9266 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009267 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009268 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009269 ASSERT_VK_SUCCESS(err);
9270
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009271 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009272 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009273 pass =
9274 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009275 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009276 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009277 ASSERT_VK_SUCCESS(err);
9278
9279 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9280 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009281 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009282 ASSERT_VK_SUCCESS(err);
9283
9284 BeginCommandBuffer();
9285 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009286 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009287 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009288 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009289 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009290 copyRegion.srcOffset.x = 0;
9291 copyRegion.srcOffset.y = 0;
9292 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009293 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009294 copyRegion.dstSubresource.mipLevel = 0;
9295 copyRegion.dstSubresource.baseArrayLayer = 0;
9296 copyRegion.dstSubresource.layerCount = 0;
9297 copyRegion.dstOffset.x = 0;
9298 copyRegion.dstOffset.y = 0;
9299 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009300 copyRegion.extent.width = 1;
9301 copyRegion.extent.height = 1;
9302 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009303 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9304 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009305 EndCommandBuffer();
9306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009307 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009308
Chia-I Wuf7458c52015-10-26 21:10:41 +08009309 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009310 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009311 vkFreeMemory(m_device->device(), srcMem, NULL);
9312 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009313}
9314
Karl Schultz6addd812016-02-02 17:17:23 -07009315TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
9316 VkResult err;
9317 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009318
Karl Schultz6addd812016-02-02 17:17:23 -07009319 m_errorMonitor->SetDesiredFailureMsg(
9320 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009321 "vkCmdResolveImage called with source sample count less than 2.");
9322
Mike Stroyana3082432015-09-25 13:39:21 -06009323 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009324
9325 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07009326 VkImage srcImage;
9327 VkImage dstImage;
9328 VkDeviceMemory srcMem;
9329 VkDeviceMemory destMem;
9330 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009331
9332 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9334 image_create_info.pNext = NULL;
9335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9336 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9337 image_create_info.extent.width = 32;
9338 image_create_info.extent.height = 1;
9339 image_create_info.extent.depth = 1;
9340 image_create_info.mipLevels = 1;
9341 image_create_info.arrayLayers = 1;
9342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9344 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9345 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009346
Karl Schultz6addd812016-02-02 17:17:23 -07009347 err =
9348 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009349 ASSERT_VK_SUCCESS(err);
9350
Karl Schultz6addd812016-02-02 17:17:23 -07009351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009352
Karl Schultz6addd812016-02-02 17:17:23 -07009353 err =
9354 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009355 ASSERT_VK_SUCCESS(err);
9356
9357 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009358 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009359 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9360 memAlloc.pNext = NULL;
9361 memAlloc.allocationSize = 0;
9362 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009363
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009364 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009365 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009366 pass =
9367 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009368 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009369 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009370 ASSERT_VK_SUCCESS(err);
9371
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009372 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009373 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009374 pass =
9375 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009376 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009377 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009378 ASSERT_VK_SUCCESS(err);
9379
9380 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9381 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009382 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009383 ASSERT_VK_SUCCESS(err);
9384
9385 BeginCommandBuffer();
9386 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009387 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9388 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009389 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009390 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009391 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009392 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009393 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009394 resolveRegion.srcOffset.x = 0;
9395 resolveRegion.srcOffset.y = 0;
9396 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009397 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009398 resolveRegion.dstSubresource.mipLevel = 0;
9399 resolveRegion.dstSubresource.baseArrayLayer = 0;
9400 resolveRegion.dstSubresource.layerCount = 0;
9401 resolveRegion.dstOffset.x = 0;
9402 resolveRegion.dstOffset.y = 0;
9403 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009404 resolveRegion.extent.width = 1;
9405 resolveRegion.extent.height = 1;
9406 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009407 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9408 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009409 EndCommandBuffer();
9410
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009411 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009412
Chia-I Wuf7458c52015-10-26 21:10:41 +08009413 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009414 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009415 vkFreeMemory(m_device->device(), srcMem, NULL);
9416 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009417}
9418
Karl Schultz6addd812016-02-02 17:17:23 -07009419TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
9420 VkResult err;
9421 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009422
Karl Schultz6addd812016-02-02 17:17:23 -07009423 m_errorMonitor->SetDesiredFailureMsg(
9424 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009425 "vkCmdResolveImage called with dest sample count greater than 1.");
9426
Mike Stroyana3082432015-09-25 13:39:21 -06009427 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009428
Chris Forbesa7530692016-05-08 12:35:39 +12009429 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07009430 VkImage srcImage;
9431 VkImage dstImage;
9432 VkDeviceMemory srcMem;
9433 VkDeviceMemory destMem;
9434 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009435
9436 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009437 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9438 image_create_info.pNext = NULL;
9439 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9440 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9441 image_create_info.extent.width = 32;
9442 image_create_info.extent.height = 1;
9443 image_create_info.extent.depth = 1;
9444 image_create_info.mipLevels = 1;
9445 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +12009446 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07009447 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9448 // Note: Some implementations expect color attachment usage for any
9449 // multisample surface
9450 image_create_info.usage =
9451 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9452 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009453
Karl Schultz6addd812016-02-02 17:17:23 -07009454 err =
9455 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009456 ASSERT_VK_SUCCESS(err);
9457
Karl Schultz6addd812016-02-02 17:17:23 -07009458 // Note: Some implementations expect color attachment usage for any
9459 // multisample surface
9460 image_create_info.usage =
9461 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009462
Karl Schultz6addd812016-02-02 17:17:23 -07009463 err =
9464 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009465 ASSERT_VK_SUCCESS(err);
9466
9467 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009468 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009469 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9470 memAlloc.pNext = NULL;
9471 memAlloc.allocationSize = 0;
9472 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009473
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009474 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009475 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009476 pass =
9477 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009478 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009479 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009480 ASSERT_VK_SUCCESS(err);
9481
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009482 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009483 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009484 pass =
9485 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009486 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009487 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009488 ASSERT_VK_SUCCESS(err);
9489
9490 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9491 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009492 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009493 ASSERT_VK_SUCCESS(err);
9494
9495 BeginCommandBuffer();
9496 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009497 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9498 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009499 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009500 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009501 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009502 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009503 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009504 resolveRegion.srcOffset.x = 0;
9505 resolveRegion.srcOffset.y = 0;
9506 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009507 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009508 resolveRegion.dstSubresource.mipLevel = 0;
9509 resolveRegion.dstSubresource.baseArrayLayer = 0;
9510 resolveRegion.dstSubresource.layerCount = 0;
9511 resolveRegion.dstOffset.x = 0;
9512 resolveRegion.dstOffset.y = 0;
9513 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009514 resolveRegion.extent.width = 1;
9515 resolveRegion.extent.height = 1;
9516 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009517 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9518 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009519 EndCommandBuffer();
9520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009521 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009522
Chia-I Wuf7458c52015-10-26 21:10:41 +08009523 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009525 vkFreeMemory(m_device->device(), srcMem, NULL);
9526 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009527}
9528
Karl Schultz6addd812016-02-02 17:17:23 -07009529TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
9530 VkResult err;
9531 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009532
Karl Schultz6addd812016-02-02 17:17:23 -07009533 m_errorMonitor->SetDesiredFailureMsg(
9534 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009535 "vkCmdResolveImage called with unmatched source and dest formats.");
9536
Mike Stroyana3082432015-09-25 13:39:21 -06009537 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009538
9539 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009540 VkImage srcImage;
9541 VkImage dstImage;
9542 VkDeviceMemory srcMem;
9543 VkDeviceMemory destMem;
9544 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009545
9546 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9548 image_create_info.pNext = NULL;
9549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9550 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9551 image_create_info.extent.width = 32;
9552 image_create_info.extent.height = 1;
9553 image_create_info.extent.depth = 1;
9554 image_create_info.mipLevels = 1;
9555 image_create_info.arrayLayers = 1;
9556 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
9557 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9558 // Note: Some implementations expect color attachment usage for any
9559 // multisample surface
9560 image_create_info.usage =
9561 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9562 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009563
Karl Schultz6addd812016-02-02 17:17:23 -07009564 err =
9565 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009566 ASSERT_VK_SUCCESS(err);
9567
Karl Schultz6addd812016-02-02 17:17:23 -07009568 // Set format to something other than source image
9569 image_create_info.format = VK_FORMAT_R32_SFLOAT;
9570 // Note: Some implementations expect color attachment usage for any
9571 // multisample surface
9572 image_create_info.usage =
9573 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9574 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009575
Karl Schultz6addd812016-02-02 17:17:23 -07009576 err =
9577 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009578 ASSERT_VK_SUCCESS(err);
9579
9580 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009581 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009582 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9583 memAlloc.pNext = NULL;
9584 memAlloc.allocationSize = 0;
9585 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009586
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009587 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009588 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009589 pass =
9590 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009591 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009592 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009593 ASSERT_VK_SUCCESS(err);
9594
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009595 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009596 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009597 pass =
9598 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009599 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009600 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009601 ASSERT_VK_SUCCESS(err);
9602
9603 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009605 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009606 ASSERT_VK_SUCCESS(err);
9607
9608 BeginCommandBuffer();
9609 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009610 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9611 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009612 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009613 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009614 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009615 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009616 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009617 resolveRegion.srcOffset.x = 0;
9618 resolveRegion.srcOffset.y = 0;
9619 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009620 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009621 resolveRegion.dstSubresource.mipLevel = 0;
9622 resolveRegion.dstSubresource.baseArrayLayer = 0;
9623 resolveRegion.dstSubresource.layerCount = 0;
9624 resolveRegion.dstOffset.x = 0;
9625 resolveRegion.dstOffset.y = 0;
9626 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009627 resolveRegion.extent.width = 1;
9628 resolveRegion.extent.height = 1;
9629 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009630 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9631 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009632 EndCommandBuffer();
9633
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009634 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009635
Chia-I Wuf7458c52015-10-26 21:10:41 +08009636 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009637 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009638 vkFreeMemory(m_device->device(), srcMem, NULL);
9639 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009640}
9641
Karl Schultz6addd812016-02-02 17:17:23 -07009642TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
9643 VkResult err;
9644 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009645
Karl Schultz6addd812016-02-02 17:17:23 -07009646 m_errorMonitor->SetDesiredFailureMsg(
9647 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009648 "vkCmdResolveImage called with unmatched source and dest image types.");
9649
Mike Stroyana3082432015-09-25 13:39:21 -06009650 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009651
9652 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009653 VkImage srcImage;
9654 VkImage dstImage;
9655 VkDeviceMemory srcMem;
9656 VkDeviceMemory destMem;
9657 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009658
9659 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009660 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9661 image_create_info.pNext = NULL;
9662 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9663 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9664 image_create_info.extent.width = 32;
9665 image_create_info.extent.height = 1;
9666 image_create_info.extent.depth = 1;
9667 image_create_info.mipLevels = 1;
9668 image_create_info.arrayLayers = 1;
9669 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
9670 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9671 // Note: Some implementations expect color attachment usage for any
9672 // multisample surface
9673 image_create_info.usage =
9674 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9675 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009676
Karl Schultz6addd812016-02-02 17:17:23 -07009677 err =
9678 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009679 ASSERT_VK_SUCCESS(err);
9680
Karl Schultz6addd812016-02-02 17:17:23 -07009681 image_create_info.imageType = VK_IMAGE_TYPE_1D;
9682 // Note: Some implementations expect color attachment usage for any
9683 // multisample surface
9684 image_create_info.usage =
9685 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9686 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009687
Karl Schultz6addd812016-02-02 17:17:23 -07009688 err =
9689 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009690 ASSERT_VK_SUCCESS(err);
9691
9692 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009693 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009694 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9695 memAlloc.pNext = NULL;
9696 memAlloc.allocationSize = 0;
9697 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009698
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009699 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009700 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009701 pass =
9702 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009703 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009704 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009705 ASSERT_VK_SUCCESS(err);
9706
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009707 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009708 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009709 pass =
9710 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009711 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009712 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009713 ASSERT_VK_SUCCESS(err);
9714
9715 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9716 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009717 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009718 ASSERT_VK_SUCCESS(err);
9719
9720 BeginCommandBuffer();
9721 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009722 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9723 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009724 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009725 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009726 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009727 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009728 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009729 resolveRegion.srcOffset.x = 0;
9730 resolveRegion.srcOffset.y = 0;
9731 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009732 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009733 resolveRegion.dstSubresource.mipLevel = 0;
9734 resolveRegion.dstSubresource.baseArrayLayer = 0;
9735 resolveRegion.dstSubresource.layerCount = 0;
9736 resolveRegion.dstOffset.x = 0;
9737 resolveRegion.dstOffset.y = 0;
9738 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009739 resolveRegion.extent.width = 1;
9740 resolveRegion.extent.height = 1;
9741 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009742 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9743 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009744 EndCommandBuffer();
9745
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009746 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009747
Chia-I Wuf7458c52015-10-26 21:10:41 +08009748 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009749 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009750 vkFreeMemory(m_device->device(), srcMem, NULL);
9751 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009752}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009753
Karl Schultz6addd812016-02-02 17:17:23 -07009754TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009755 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -07009756 // to using a DS format, then cause it to hit error due to COLOR_BIT not
9757 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009758 // The image format check comes 2nd in validation so we trigger it first,
9759 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -07009760 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009761
Karl Schultz6addd812016-02-02 17:17:23 -07009762 m_errorMonitor->SetDesiredFailureMsg(
9763 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009764 "Combination depth/stencil image formats can have only the ");
9765
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009766 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009767
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009768 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009769 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
9770 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009771
9772 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009773 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9774 ds_pool_ci.pNext = NULL;
9775 ds_pool_ci.maxSets = 1;
9776 ds_pool_ci.poolSizeCount = 1;
9777 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009778
9779 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009780 err =
9781 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009782 ASSERT_VK_SUCCESS(err);
9783
9784 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009785 dsl_binding.binding = 0;
9786 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
9787 dsl_binding.descriptorCount = 1;
9788 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9789 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009790
9791 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009792 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9793 ds_layout_ci.pNext = NULL;
9794 ds_layout_ci.bindingCount = 1;
9795 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009796 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009797 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9798 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009799 ASSERT_VK_SUCCESS(err);
9800
9801 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009802 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009803 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009804 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009805 alloc_info.descriptorPool = ds_pool;
9806 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009807 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9808 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009809 ASSERT_VK_SUCCESS(err);
9810
Karl Schultz6addd812016-02-02 17:17:23 -07009811 VkImage image_bad;
9812 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009813 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -07009814 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009815 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07009816 const int32_t tex_width = 32;
9817 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009818
9819 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009820 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9821 image_create_info.pNext = NULL;
9822 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9823 image_create_info.format = tex_format_bad;
9824 image_create_info.extent.width = tex_width;
9825 image_create_info.extent.height = tex_height;
9826 image_create_info.extent.depth = 1;
9827 image_create_info.mipLevels = 1;
9828 image_create_info.arrayLayers = 1;
9829 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9830 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9831 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
9832 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
9833 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009834
Karl Schultz6addd812016-02-02 17:17:23 -07009835 err =
9836 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009837 ASSERT_VK_SUCCESS(err);
9838 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -07009839 image_create_info.usage =
9840 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9841 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
9842 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009843 ASSERT_VK_SUCCESS(err);
9844
9845 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009846 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9847 image_view_create_info.image = image_bad;
9848 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9849 image_view_create_info.format = tex_format_bad;
9850 image_view_create_info.subresourceRange.baseArrayLayer = 0;
9851 image_view_create_info.subresourceRange.baseMipLevel = 0;
9852 image_view_create_info.subresourceRange.layerCount = 1;
9853 image_view_create_info.subresourceRange.levelCount = 1;
9854 image_view_create_info.subresourceRange.aspectMask =
9855 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009856
9857 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009858 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9859 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009860
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009861 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009862
Chia-I Wuf7458c52015-10-26 21:10:41 +08009863 vkDestroyImage(m_device->device(), image_bad, NULL);
9864 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009865 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9866 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009867}
Tobin Ehliscde08892015-09-22 10:11:37 -06009868#endif // IMAGE_TESTS
9869
Tony Barbour300a6082015-04-07 13:44:53 -06009870int main(int argc, char **argv) {
9871 int result;
9872
Cody Northrop8e54a402016-03-08 22:25:52 -07009873#ifdef ANDROID
9874 int vulkanSupport = InitVulkan();
9875 if (vulkanSupport == 0)
9876 return 1;
9877#endif
9878
Tony Barbour300a6082015-04-07 13:44:53 -06009879 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06009880 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06009881
9882 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
9883
9884 result = RUN_ALL_TESTS();
9885
Tony Barbour6918cd52015-04-09 12:58:51 -06009886 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06009887 return result;
9888}