blob: 9037c287c2afee571115db8898a48378cf32bda9 [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 Gravesffa90fa2016-05-06 11:20:38 -0600663#endif // PARAMETER_VALIDATION_TESTS
664
Tobin Ehlis0788f522015-05-26 16:11:58 -0600665#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700666#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800667TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500668{
669 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500670 VkFenceCreateInfo fenceInfo = {};
671 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
672 fenceInfo.pNext = NULL;
673 fenceInfo.flags = 0;
674
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600676
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500677 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -0600678
679 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
680 vk_testing::Buffer buffer;
681 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500682
Tony Barbourfe3351b2015-07-28 10:17:20 -0600683 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800684 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600685 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500686
687 testFence.init(*m_device, fenceInfo);
688
689 // Bypass framework since it does the waits automatically
690 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600691 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800692 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
693 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800694 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600695 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700696 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800697 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800698 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800699 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600700 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600701
702 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500703 ASSERT_VK_SUCCESS( err );
704
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500705 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800706 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500707
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200708 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500709}
710
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800711TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500712{
713 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500714 VkFenceCreateInfo fenceInfo = {};
715 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
716 fenceInfo.pNext = NULL;
717 fenceInfo.flags = 0;
718
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600720
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500721 ASSERT_NO_FATAL_FAILURE(InitState());
722 ASSERT_NO_FATAL_FAILURE(InitViewport());
723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
724
Tony Barbourfe3351b2015-07-28 10:17:20 -0600725 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800726 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -0600727 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500728
729 testFence.init(*m_device, fenceInfo);
730
731 // Bypass framework since it does the waits automatically
732 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600733 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +0800734 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
735 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800736 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600737 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -0700738 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800739 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800740 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +0800741 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -0600742 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -0600743
744 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500745 ASSERT_VK_SUCCESS( err );
746
Jon Ashburnf19916e2016-01-11 13:12:43 -0700747 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800748 VkCommandBufferBeginInfo info = {};
749 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
750 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600751 info.renderPass = VK_NULL_HANDLE;
752 info.subpass = 0;
753 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +0800754 info.occlusionQueryEnable = VK_FALSE;
755 info.queryFlags = 0;
756 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -0600757
758 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800759 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500760
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200761 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -0500762}
Tobin Ehlis8fab6562015-12-01 09:57:09 -0700763#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200764
Mark Lobodzinski152fe252016-05-03 16:49:15 -0600765// This is a positive test. No failures are expected.
766TEST_F(VkLayerTest, TestAliasedMemoryTracking) {
767 VkResult err;
768 bool pass;
769
770 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
771 "the buffer, create an image, and bind the same memory to "
772 "it");
773
774 m_errorMonitor->ExpectSuccess();
775
776 ASSERT_NO_FATAL_FAILURE(InitState());
777
778 VkBuffer buffer;
779 VkImage image;
780 VkDeviceMemory mem;
781 VkMemoryRequirements mem_reqs;
782
783 VkBufferCreateInfo buf_info = {};
784 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
785 buf_info.pNext = NULL;
786 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
787 buf_info.size = 256;
788 buf_info.queueFamilyIndexCount = 0;
789 buf_info.pQueueFamilyIndices = NULL;
790 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
791 buf_info.flags = 0;
792 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
793 ASSERT_VK_SUCCESS(err);
794
795 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
796
797 VkMemoryAllocateInfo alloc_info = {};
798 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
799 alloc_info.pNext = NULL;
800 alloc_info.memoryTypeIndex = 0;
801
802 // Ensure memory is big enough for both bindings
803 alloc_info.allocationSize = 0x10000;
804
805 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
806 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
807 if (!pass) {
808 vkDestroyBuffer(m_device->device(), buffer, NULL);
809 return;
810 }
811
812 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
813 ASSERT_VK_SUCCESS(err);
814
815 uint8_t *pData;
816 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0,
817 (void **)&pData);
818 ASSERT_VK_SUCCESS(err);
819
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600820 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
Mark Lobodzinski152fe252016-05-03 16:49:15 -0600821
822 vkUnmapMemory(m_device->device(), mem);
823
824 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
825 ASSERT_VK_SUCCESS(err);
826
827 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
828 // memory. In fact, it was never used by the GPU.
829 // Just be be sure, wait for idle.
830 vkDestroyBuffer(m_device->device(), buffer, NULL);
831 vkDeviceWaitIdle(m_device->device());
832
833 VkImageCreateInfo image_create_info = {};
834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
835 image_create_info.pNext = NULL;
836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
837 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
838 image_create_info.extent.width = 64;
839 image_create_info.extent.height = 64;
840 image_create_info.extent.depth = 1;
841 image_create_info.mipLevels = 1;
842 image_create_info.arrayLayers = 1;
843 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
844 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
845 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
846 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
847 image_create_info.queueFamilyIndexCount = 0;
848 image_create_info.pQueueFamilyIndices = NULL;
849 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
850 image_create_info.flags = 0;
851
852 VkMemoryAllocateInfo mem_alloc = {};
853 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
854 mem_alloc.pNext = NULL;
855 mem_alloc.allocationSize = 0;
856 mem_alloc.memoryTypeIndex = 0;
857
858 /* Create a mappable image. It will be the texture if linear images are ok
859 * to be textures or it will be the staging image if they are not.
860 */
861 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
862 ASSERT_VK_SUCCESS(err);
863
864 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
865
866 mem_alloc.allocationSize = mem_reqs.size;
867
868 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc,
869 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
870 if (!pass) {
871 vkDestroyImage(m_device->device(), image, NULL);
872 return;
873 }
874
875 // VALDIATION FAILURE:
876 err = vkBindImageMemory(m_device->device(), image, mem, 0);
877 ASSERT_VK_SUCCESS(err);
878
879 m_errorMonitor->VerifyNotFound();
880
881 vkDestroyBuffer(m_device->device(), buffer, NULL);
882 vkDestroyImage(m_device->device(), image, NULL);
883}
884
Ian Elliott1c32c772016-04-28 14:47:13 -0600885TEST_F(VkLayerTest, EnableWsiBeforeUse) {
886 VkResult err;
887 bool pass;
888
Ian Elliott489eec02016-05-05 14:12:44 -0600889// FIXME: After we turn on this code for non-Linux platforms, uncomment the
890// following declaration (which is temporarily being moved below):
891// VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -0600892 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
893 VkSwapchainCreateInfoKHR swapchain_create_info = {};
894 uint32_t swapchain_image_count = 0;
895// VkImage swapchain_images[1] = {VK_NULL_HANDLE};
896 uint32_t image_index = 0;
897// VkPresentInfoKHR present_info = {};
898
899 ASSERT_NO_FATAL_FAILURE(InitState());
900
Ian Elliott3f06ce52016-04-29 14:46:21 -0600901#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
902#if defined(VK_USE_PLATFORM_ANDROID_KHR)
903 // Use the functions from the VK_KHR_android_surface extension without
904 // enabling that extension:
905
906 // Create a surface:
907 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
908#if 0
909#endif
910 m_errorMonitor->SetDesiredFailureMsg(
911 VK_DEBUG_REPORT_ERROR_BIT_EXT,
912 "extension was not enabled for this");
913 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL,
914 &surface);
915 pass = (err != VK_SUCCESS);
916 ASSERT_TRUE(pass);
917 m_errorMonitor->VerifyFound();
918#endif // VK_USE_PLATFORM_ANDROID_KHR
919
920
921#if defined(VK_USE_PLATFORM_MIR_KHR)
922 // Use the functions from the VK_KHR_mir_surface extension without enabling
923 // that extension:
924
925 // Create a surface:
926 VkMirSurfaceCreateInfoKHR mir_create_info = {};
927#if 0
928#endif
929 m_errorMonitor->SetDesiredFailureMsg(
930 VK_DEBUG_REPORT_ERROR_BIT_EXT,
931 "extension was not enabled for this");
932 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
933 pass = (err != VK_SUCCESS);
934 ASSERT_TRUE(pass);
935 m_errorMonitor->VerifyFound();
936
937 // Tell whether an mir_connection supports presentation:
938 MirConnection *mir_connection = NULL;
939 m_errorMonitor->SetDesiredFailureMsg(
940 VK_DEBUG_REPORT_ERROR_BIT_EXT,
941 "extension was not enabled for this");
942 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection,
943 visual_id);
944 m_errorMonitor->VerifyFound();
945#endif // VK_USE_PLATFORM_MIR_KHR
946
947
948#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
949 // Use the functions from the VK_KHR_wayland_surface extension without
950 // enabling that extension:
951
952 // Create a surface:
953 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
954#if 0
955#endif
956 m_errorMonitor->SetDesiredFailureMsg(
957 VK_DEBUG_REPORT_ERROR_BIT_EXT,
958 "extension was not enabled for this");
959 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL,
960 &surface);
961 pass = (err != VK_SUCCESS);
962 ASSERT_TRUE(pass);
963 m_errorMonitor->VerifyFound();
964
965 // Tell whether an wayland_display supports presentation:
966 struct wl_display wayland_display = {};
967 m_errorMonitor->SetDesiredFailureMsg(
968 VK_DEBUG_REPORT_ERROR_BIT_EXT,
969 "extension was not enabled for this");
970 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0,
971 &wayland_display);
972 m_errorMonitor->VerifyFound();
973#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -0600974#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -0600975
976
977#if defined(VK_USE_PLATFORM_WIN32_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -0600978// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
979// TO NON-LINUX PLATFORMS:
980VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -0600981 // Use the functions from the VK_KHR_win32_surface extension without
982 // enabling that extension:
983
984 // Create a surface:
985 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
986#if 0
987#endif
988 m_errorMonitor->SetDesiredFailureMsg(
989 VK_DEBUG_REPORT_ERROR_BIT_EXT,
990 "extension was not enabled for this");
991 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL,
992 &surface);
993 pass = (err != VK_SUCCESS);
994 ASSERT_TRUE(pass);
995 m_errorMonitor->VerifyFound();
996
997 // Tell whether win32 supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -0600998 m_errorMonitor->SetDesiredFailureMsg(
999 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1000 "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001001 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001002 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001003// Set this (for now, until all platforms are supported and tested):
1004#define NEED_TO_TEST_THIS_ON_PLATFORM
1005#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001006
1007
Ian Elliott1c32c772016-04-28 14:47:13 -06001008#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott489eec02016-05-05 14:12:44 -06001009// FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1010// TO NON-LINUX PLATFORMS:
1011VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001012 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1013 // that extension:
1014
1015 // Create a surface:
1016 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
1017#if 0
1018#endif
1019 m_errorMonitor->SetDesiredFailureMsg(
1020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1021 "extension was not enabled for this");
1022 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1023 pass = (err != VK_SUCCESS);
1024 ASSERT_TRUE(pass);
1025 m_errorMonitor->VerifyFound();
1026
1027 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001028 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001029 xcb_visualid_t visual_id = 0;
1030 m_errorMonitor->SetDesiredFailureMsg(
1031 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1032 "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001033 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection,
Ian Elliott1c32c772016-04-28 14:47:13 -06001034 visual_id);
1035 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001036// Set this (for now, until all platforms are supported and tested):
1037#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001038#endif // VK_USE_PLATFORM_XCB_KHR
1039
1040
Ian Elliott12630812016-04-29 14:35:43 -06001041#if defined(VK_USE_PLATFORM_XLIB_KHR)
1042 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1043 // that extension:
1044
1045 // Create a surface:
1046 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
1047#if 0
1048#endif
1049 m_errorMonitor->SetDesiredFailureMsg(
1050 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1051 "extension was not enabled for this");
1052 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1053 pass = (err != VK_SUCCESS);
1054 ASSERT_TRUE(pass);
1055 m_errorMonitor->VerifyFound();
1056
1057 // Tell whether an Xlib VisualID supports presentation:
1058 Display *dpy = NULL;
1059 VisualID visual = 0;
1060 m_errorMonitor->SetDesiredFailureMsg(
1061 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1062 "extension was not enabled for this");
1063 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1064 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001065// Set this (for now, until all platforms are supported and tested):
1066#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001067#endif // VK_USE_PLATFORM_XLIB_KHR
1068
1069
Ian Elliott1c32c772016-04-28 14:47:13 -06001070 // Use the functions from the VK_KHR_surface extension without enabling
1071 // that extension:
1072
Ian Elliott489eec02016-05-05 14:12:44 -06001073#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001074 // Destroy a surface:
1075 m_errorMonitor->SetDesiredFailureMsg(
1076 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1077 "extension was not enabled for this");
1078 vkDestroySurfaceKHR(instance(), surface, NULL);
1079 m_errorMonitor->VerifyFound();
1080
1081 // Check if surface supports presentation:
1082 VkBool32 supported = false;
1083 m_errorMonitor->SetDesiredFailureMsg(
1084 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1085 "extension was not enabled for this");
1086 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1087 pass = (err != VK_SUCCESS);
1088 ASSERT_TRUE(pass);
1089 m_errorMonitor->VerifyFound();
1090
1091 // Check surface capabilities:
1092 VkSurfaceCapabilitiesKHR capabilities = {};
1093 m_errorMonitor->SetDesiredFailureMsg(
1094 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1095 "extension was not enabled for this");
1096 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface,
1097 &capabilities);
1098 pass = (err != VK_SUCCESS);
1099 ASSERT_TRUE(pass);
1100 m_errorMonitor->VerifyFound();
1101
1102 // Check surface formats:
1103 uint32_t format_count = 0;
1104 VkSurfaceFormatKHR *formats = NULL;
1105 m_errorMonitor->SetDesiredFailureMsg(
1106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1107 "extension was not enabled for this");
1108 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1109 &format_count, formats);
1110 pass = (err != VK_SUCCESS);
1111 ASSERT_TRUE(pass);
1112 m_errorMonitor->VerifyFound();
1113
1114 // Check surface present modes:
1115 uint32_t present_mode_count = 0;
1116 VkSurfaceFormatKHR *present_modes = NULL;
1117 m_errorMonitor->SetDesiredFailureMsg(
1118 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1119 "extension was not enabled for this");
1120 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface,
1121 &present_mode_count, present_modes);
1122 pass = (err != VK_SUCCESS);
1123 ASSERT_TRUE(pass);
1124 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001125#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001126
1127
1128 // Use the functions from the VK_KHR_swapchain extension without enabling
1129 // that extension:
1130
1131 // Create a swapchain:
1132 m_errorMonitor->SetDesiredFailureMsg(
1133 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1134 "extension was not enabled for this");
1135 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1136 swapchain_create_info.pNext = NULL;
1137#if 0
1138 swapchain_create_info.flags = 0;
1139 swapchain_create_info.surface = 0;
1140 swapchain_create_info.minImageCount = 0;
1141 swapchain_create_info.imageFormat = 0;
1142 swapchain_create_info.imageColorSpace = 0;
1143 swapchain_create_info.imageExtent.width = 0;
1144 swapchain_create_info.imageExtent.height = 0;
1145 swapchain_create_info.imageArrayLayers = 0;
1146 swapchain_create_info.imageUsage = 0;
1147 swapchain_create_info.imageSharingMode = 0;
1148 swapchain_create_info.queueFamilyIndexCount = 0;
1149 swapchain_create_info.preTransform = 0;
1150 swapchain_create_info.compositeAlpha = 0;
1151 swapchain_create_info.presentMode = 0;
1152 swapchain_create_info.clipped = 0;
1153 swapchain_create_info.oldSwapchain = NULL;
1154#endif
1155 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info,
1156 NULL, &swapchain);
1157 pass = (err != VK_SUCCESS);
1158 ASSERT_TRUE(pass);
1159 m_errorMonitor->VerifyFound();
1160
1161 // Get the images from the swapchain:
1162 m_errorMonitor->SetDesiredFailureMsg(
1163 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1164 "extension was not enabled for this");
1165 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain,
1166 &swapchain_image_count, NULL);
1167 pass = (err != VK_SUCCESS);
1168 ASSERT_TRUE(pass);
1169 m_errorMonitor->VerifyFound();
1170
1171 // Try to acquire an image:
1172 m_errorMonitor->SetDesiredFailureMsg(
1173 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1174 "extension was not enabled for this");
1175 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0,
1176 VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index);
1177 pass = (err != VK_SUCCESS);
1178 ASSERT_TRUE(pass);
1179 m_errorMonitor->VerifyFound();
1180
1181 // Try to present an image:
1182#if 0 // NOTE: Currently can't test this because a real swapchain is needed
1183 // (as opposed to the fake one we created) in order for the layer to
1184 // lookup the VkDevice used to enable the extension:
1185 m_errorMonitor->SetDesiredFailureMsg(
1186 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1187 "extension was not enabled for this");
1188 present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
1189 present_info.pNext = NULL;
1190#if 0
1191#endif
1192 err = vkQueuePresentKHR(m_device->m_queue, &present_info);
1193 pass = (err != VK_SUCCESS);
1194 ASSERT_TRUE(pass);
1195 m_errorMonitor->VerifyFound();
1196#endif
1197
1198 // Destroy the swapchain:
1199 m_errorMonitor->SetDesiredFailureMsg(
1200 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1201 "extension was not enabled for this");
1202 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1203 m_errorMonitor->VerifyFound();
1204}
1205
Karl Schultz6addd812016-02-02 17:17:23 -07001206TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1207 VkResult err;
1208 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001209
Karl Schultz6addd812016-02-02 17:17:23 -07001210 m_errorMonitor->SetDesiredFailureMsg(
1211 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
1213
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001214 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001215
1216 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001217 VkImage image;
1218 VkDeviceMemory mem;
1219 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001220
Karl Schultz6addd812016-02-02 17:17:23 -07001221 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1222 const int32_t tex_width = 32;
1223 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001224
Tony Barboureb254902015-07-15 12:50:33 -06001225 VkImageCreateInfo image_create_info = {};
1226 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001227 image_create_info.pNext = NULL;
1228 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1229 image_create_info.format = tex_format;
1230 image_create_info.extent.width = tex_width;
1231 image_create_info.extent.height = tex_height;
1232 image_create_info.extent.depth = 1;
1233 image_create_info.mipLevels = 1;
1234 image_create_info.arrayLayers = 1;
1235 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1236 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1237 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1238 image_create_info.flags = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001239
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001240 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001241 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001242 mem_alloc.pNext = NULL;
1243 mem_alloc.allocationSize = 0;
1244 // Introduce failure, do NOT set memProps to
1245 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
1246 mem_alloc.memoryTypeIndex = 1;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001247
Chia-I Wuf7458c52015-10-26 21:10:41 +08001248 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001249 ASSERT_VK_SUCCESS(err);
1250
Karl Schultz6addd812016-02-02 17:17:23 -07001251 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001252
Mark Lobodzinski23065352015-05-29 09:32:35 -05001253 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001254
Karl Schultz6addd812016-02-02 17:17:23 -07001255 pass =
1256 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0,
1257 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
1258 if (!pass) { // If we can't find any unmappable memory this test doesn't
1259 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001260 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001261 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001262 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001263
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001264 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001265 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001266 ASSERT_VK_SUCCESS(err);
1267
1268 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001269 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001270 ASSERT_VK_SUCCESS(err);
1271
1272 // Map memory as if to initialize the image
1273 void *mappedAddress = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07001274 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0,
1275 &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001278
Chia-I Wuf7458c52015-10-26 21:10:41 +08001279 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001280}
1281
Karl Schultz6addd812016-02-02 17:17:23 -07001282TEST_F(VkLayerTest, RebindMemory) {
1283 VkResult err;
1284 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -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 "which has already been bound to mem object");
1289
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001290 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -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 mem1;
1295 VkDeviceMemory mem2;
1296 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001297
Karl Schultz6addd812016-02-02 17:17:23 -07001298 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1299 const int32_t tex_width = 32;
1300 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001301
Tony Barboureb254902015-07-15 12:50:33 -06001302 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001303 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1304 image_create_info.pNext = NULL;
1305 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1306 image_create_info.format = tex_format;
1307 image_create_info.extent.width = tex_width;
1308 image_create_info.extent.height = tex_height;
1309 image_create_info.extent.depth = 1;
1310 image_create_info.mipLevels = 1;
1311 image_create_info.arrayLayers = 1;
1312 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1313 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1314 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1315 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001316
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001317 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001318 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1319 mem_alloc.pNext = NULL;
1320 mem_alloc.allocationSize = 0;
1321 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001322
Karl Schultz6addd812016-02-02 17:17:23 -07001323 // Introduce failure, do NOT set memProps to
1324 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001325 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001326 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001327 ASSERT_VK_SUCCESS(err);
1328
Karl Schultz6addd812016-02-02 17:17:23 -07001329 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001330
1331 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07001332 pass =
1333 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001334 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001335
1336 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001337 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001338 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001339 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001340 ASSERT_VK_SUCCESS(err);
1341
1342 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001343 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001344 ASSERT_VK_SUCCESS(err);
1345
Karl Schultz6addd812016-02-02 17:17:23 -07001346 // Introduce validation failure, try to bind a different memory object to
1347 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001348 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001349
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001350 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001351
Chia-I Wuf7458c52015-10-26 21:10:41 +08001352 vkDestroyImage(m_device->device(), image, NULL);
1353 vkFreeMemory(m_device->device(), mem1, NULL);
1354 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001355}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001356
Karl Schultz6addd812016-02-02 17:17:23 -07001357TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001358 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001359
Karl Schultz6addd812016-02-02 17:17:23 -07001360 m_errorMonitor->SetDesiredFailureMsg(
1361 VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1362 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001363
1364 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001365 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1366 fenceInfo.pNext = NULL;
1367 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001368
Tony Barbour300a6082015-04-07 13:44:53 -06001369 ASSERT_NO_FATAL_FAILURE(InitState());
1370 ASSERT_NO_FATAL_FAILURE(InitViewport());
1371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1372
Tony Barbourfe3351b2015-07-28 10:17:20 -06001373 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07001374 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
1375 m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001376 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001377
1378 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001379
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001380 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001381 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1382 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001383 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001384 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001385 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001386 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001387 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001388 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001389 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001390
1391 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001392 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001393
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001394 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001395}
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001396// This is a positive test. We used to expect error in this case but spec now
1397// allows it
Karl Schultz6addd812016-02-02 17:17:23 -07001398TEST_F(VkLayerTest, ResetUnsignaledFence) {
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001399 m_errorMonitor->ExpectSuccess();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001400 vk_testing::Fence testFence;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001401 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001402 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1403 fenceInfo.pNext = NULL;
1404
Tony Barbour0b4d9562015-04-09 10:48:04 -06001405 ASSERT_NO_FATAL_FAILURE(InitState());
1406 testFence.init(*m_device, fenceInfo);
Chia-I Wud9e8e822015-07-03 11:45:55 +08001407 VkFence fences[1] = {testFence.handle()};
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001408 VkResult result = vkResetFences(m_device->device(), 1, fences);
1409 ASSERT_VK_SUCCESS(result);
Tony Barbour300a6082015-04-07 13:44:53 -06001410
Tobin Ehlisaff7ae92016-04-18 15:45:20 -06001411 m_errorMonitor->VerifyNotFound();
Tony Barbour300a6082015-04-07 13:44:53 -06001412}
Tobin Ehlis41376e12015-07-03 08:45:14 -06001413
1414TEST_F(VkLayerTest, InvalidUsageBits)
1415{
Tony Barbourf92621a2016-05-02 14:28:12 -06001416 TEST_DESCRIPTION(
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001417 "Specify wrong usage for image then create conflicting view of image "
Tony Barbourf92621a2016-05-02 14:28:12 -06001418 "Initialize buffer with wrong usage then perform copy expecting errors "
1419 "from both the image and the buffer (2 calls)");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001421 "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001422
1423 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001424 VkImageObj image(m_device);
1425 // Initialize image with USAGE_INPUT_ATTACHMENT
1426 image.init(128, 128, VK_FORMAT_D32_SFLOAT_S8_UINT,
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001427 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
1428 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001429
Tony Barbourf92621a2016-05-02 14:28:12 -06001430 VkImageView dsv;
1431 VkImageViewCreateInfo dsvci = {};
1432 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1433 dsvci.image = image.handle();
1434 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1435 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1436 dsvci.subresourceRange.layerCount = 1;
1437 dsvci.subresourceRange.baseMipLevel = 0;
1438 dsvci.subresourceRange.levelCount = 1;
1439 dsvci.subresourceRange.aspectMask =
1440 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001441
Tony Barbourf92621a2016-05-02 14:28:12 -06001442 // Create a view with depth / stencil aspect for image with different usage
1443 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001445 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001446
1447 // Initialize buffer with TRANSFER_DST usage
1448 vk_testing::Buffer buffer;
1449 VkMemoryPropertyFlags reqs = 0;
1450 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1451 VkBufferImageCopy region = {};
1452 region.bufferRowLength = 128;
1453 region.bufferImageHeight = 128;
1454 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1455 region.imageSubresource.layerCount = 1;
1456 region.imageExtent.height = 16;
1457 region.imageExtent.width = 16;
1458 region.imageExtent.depth = 1;
1459
1460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1461 "Invalid usage flag for buffer ");
1462 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1463 // TRANSFER_DST
1464 BeginCommandBuffer();
1465 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
1466 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1467 1, &region);
1468 m_errorMonitor->VerifyFound();
1469
1470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1471 "Invalid usage flag for image ");
1472 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
1473 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1474 1, &region);
1475 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001476}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001477#endif // MEM_TRACKER_TESTS
1478
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001479#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001480
1481TEST_F(VkLayerTest, LeakAnObject) {
1482 VkResult err;
1483
1484 TEST_DESCRIPTION(
1485 "Create a fence and destroy its device without first destroying the fence.");
1486
1487 // Note that we have to create a new device since destroying the
1488 // framework's device causes Teardown() to fail and just calling Teardown
1489 // will destroy the errorMonitor.
1490
1491 m_errorMonitor->SetDesiredFailureMsg(
1492 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1493 "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object");
1494
1495 ASSERT_NO_FATAL_FAILURE(InitState());
1496
1497 const std::vector<VkQueueFamilyProperties> queue_props =
1498 m_device->queue_props;
1499 std::vector<VkDeviceQueueCreateInfo> queue_info;
1500 queue_info.reserve(queue_props.size());
1501 std::vector<std::vector<float>> queue_priorities;
1502 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1503 VkDeviceQueueCreateInfo qi = {};
1504 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1505 qi.pNext = NULL;
1506 qi.queueFamilyIndex = i;
1507 qi.queueCount = queue_props[i].queueCount;
1508 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1509 qi.pQueuePriorities = queue_priorities[i].data();
1510 queue_info.push_back(qi);
1511 }
1512
1513 std::vector<const char *> device_layer_names;
1514 std::vector<const char *> device_extension_names;
1515 device_layer_names.push_back("VK_LAYER_GOOGLE_threading");
1516 device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
1517 device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
1518 device_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
1519 device_layer_names.push_back("VK_LAYER_LUNARG_device_limits");
1520 device_layer_names.push_back("VK_LAYER_LUNARG_image");
1521 device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
1522
1523 // The sacrificial device object
1524 VkDevice testDevice;
1525 VkDeviceCreateInfo device_create_info = {};
1526 auto features = m_device->phy().features();
1527 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1528 device_create_info.pNext = NULL;
1529 device_create_info.queueCreateInfoCount = queue_info.size();
1530 device_create_info.pQueueCreateInfos = queue_info.data();
1531 device_create_info.enabledLayerCount = device_layer_names.size();
1532 device_create_info.ppEnabledLayerNames = device_layer_names.data();
1533 device_create_info.pEnabledFeatures = &features;
1534 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1535 ASSERT_VK_SUCCESS(err);
1536
1537 VkFence fence;
1538 VkFenceCreateInfo fence_create_info = {};
1539 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1540 fence_create_info.pNext = NULL;
1541 fence_create_info.flags = 0;
1542 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
1543 ASSERT_VK_SUCCESS(err);
1544
1545 // Induce failure by not calling vkDestroyFence
1546 vkDestroyDevice(testDevice, NULL);
1547 m_errorMonitor->VerifyFound();
1548}
1549
1550TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
1551
1552 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
1553 "attempt to delete them from another.");
1554
1555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1556 "FreeCommandBuffers is attempting to free Command Buffer");
1557
1558 VkCommandPool command_pool_one;
1559 VkCommandPool command_pool_two;
1560
1561 VkCommandPoolCreateInfo pool_create_info{};
1562 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1563 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1564 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1565
1566 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1567 &command_pool_one);
1568
1569 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1570 &command_pool_two);
1571
1572 VkCommandBuffer command_buffer[9];
1573 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1574 command_buffer_allocate_info.sType =
1575 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1576 command_buffer_allocate_info.commandPool = command_pool_one;
1577 command_buffer_allocate_info.commandBufferCount = 9;
1578 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1579 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1580 command_buffer);
1581
1582 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4,
1583 &command_buffer[3]);
1584
1585 m_errorMonitor->VerifyFound();
1586
1587 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
1588 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
1589}
1590
1591TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
1592 VkResult err;
1593
1594 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
1595 "attempt to delete them from another.");
1596
1597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1598 "FreeDescriptorSets is attempting to free descriptorSet");
1599
1600 ASSERT_NO_FATAL_FAILURE(InitState());
1601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1602
1603 VkDescriptorPoolSize ds_type_count = {};
1604 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
1605 ds_type_count.descriptorCount = 1;
1606
1607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
1608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1609 ds_pool_ci.pNext = NULL;
1610 ds_pool_ci.flags = 0;
1611 ds_pool_ci.maxSets = 1;
1612 ds_pool_ci.poolSizeCount = 1;
1613 ds_pool_ci.pPoolSizes = &ds_type_count;
1614
1615 VkDescriptorPool ds_pool_one;
1616 err =
1617 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
1618 ASSERT_VK_SUCCESS(err);
1619
1620 // Create a second descriptor pool
1621 VkDescriptorPool ds_pool_two;
1622 err =
1623 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
1624 ASSERT_VK_SUCCESS(err);
1625
1626 VkDescriptorSetLayoutBinding dsl_binding = {};
1627 dsl_binding.binding = 0;
1628 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
1629 dsl_binding.descriptorCount = 1;
1630 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1631 dsl_binding.pImmutableSamplers = NULL;
1632
1633 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
1634 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1635 ds_layout_ci.pNext = NULL;
1636 ds_layout_ci.bindingCount = 1;
1637 ds_layout_ci.pBindings = &dsl_binding;
1638
1639 VkDescriptorSetLayout ds_layout;
1640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1641 &ds_layout);
1642 ASSERT_VK_SUCCESS(err);
1643
1644 VkDescriptorSet descriptorSet;
1645 VkDescriptorSetAllocateInfo alloc_info = {};
1646 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
1647 alloc_info.descriptorSetCount = 1;
1648 alloc_info.descriptorPool = ds_pool_one;
1649 alloc_info.pSetLayouts = &ds_layout;
1650 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1651 &descriptorSet);
1652 ASSERT_VK_SUCCESS(err);
1653
1654 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
1655
1656 m_errorMonitor->VerifyFound();
1657
1658 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1659 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
1660 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
1661}
1662
1663TEST_F(VkLayerTest, CreateUnknownObject) {
1664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1665 "Invalid VkImage Object ");
1666
1667 TEST_DESCRIPTION(
1668 "Pass an invalid image object handle into a Vulkan API call.");
1669
1670 ASSERT_NO_FATAL_FAILURE(InitState());
1671
1672 // Pass bogus handle into GetImageMemoryRequirements
1673 VkMemoryRequirements mem_reqs;
1674 uint64_t fakeImageHandle = 0xCADECADE;
1675 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
1676
1677 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
1678
1679 m_errorMonitor->VerifyFound();
1680}
1681
Karl Schultz6addd812016-02-02 17:17:23 -07001682TEST_F(VkLayerTest, PipelineNotBound) {
1683 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001684
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001685 TEST_DESCRIPTION(
1686 "Pass in an invalid pipeline object handle into a Vulkan API call.");
1687
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07001689 "Invalid VkPipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001690
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001691 ASSERT_NO_FATAL_FAILURE(InitState());
1692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001693
Chia-I Wu1b99bb22015-10-27 19:25:11 +08001694 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001695 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1696 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001697
1698 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001699 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
1700 ds_pool_ci.pNext = NULL;
1701 ds_pool_ci.maxSets = 1;
1702 ds_pool_ci.poolSizeCount = 1;
1703 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001704
1705 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07001706 err =
1707 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001708 ASSERT_VK_SUCCESS(err);
1709
1710 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001711 dsl_binding.binding = 0;
1712 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
1713 dsl_binding.descriptorCount = 1;
1714 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
1715 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001716
1717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1719 ds_layout_ci.pNext = NULL;
1720 ds_layout_ci.bindingCount = 1;
1721 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001722
1723 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
1725 &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001726 ASSERT_VK_SUCCESS(err);
1727
1728 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001729 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001730 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07001731 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001732 alloc_info.descriptorPool = ds_pool;
1733 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001734 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
1735 &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001736 ASSERT_VK_SUCCESS(err);
1737
1738 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001739 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1740 pipeline_layout_ci.pNext = NULL;
1741 pipeline_layout_ci.setLayoutCount = 1;
1742 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001743
1744 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07001745 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
1746 &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001747 ASSERT_VK_SUCCESS(err);
1748
Mark Youngad779052016-01-06 14:26:04 -07001749 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001750
1751 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07001752 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
1753 VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001754
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001755 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001756
Chia-I Wuf7458c52015-10-26 21:10:41 +08001757 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
1758 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
1759 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001760}
1761
Karl Schultz6addd812016-02-02 17:17:23 -07001762TEST_F(VkLayerTest, BindInvalidMemory) {
1763 VkResult err;
1764 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001765
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07001767 "Invalid VkDeviceMemory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001768
Tobin Ehlisec598302015-09-15 15:02:17 -06001769 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001770
1771 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001772 VkImage image;
1773 VkDeviceMemory mem;
1774 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06001775
Karl Schultz6addd812016-02-02 17:17:23 -07001776 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1777 const int32_t tex_width = 32;
1778 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06001779
1780 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001781 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1782 image_create_info.pNext = NULL;
1783 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1784 image_create_info.format = tex_format;
1785 image_create_info.extent.width = tex_width;
1786 image_create_info.extent.height = tex_height;
1787 image_create_info.extent.depth = 1;
1788 image_create_info.mipLevels = 1;
1789 image_create_info.arrayLayers = 1;
1790 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1791 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1792 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1793 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001794
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001795 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001796 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1797 mem_alloc.pNext = NULL;
1798 mem_alloc.allocationSize = 0;
1799 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001800
Chia-I Wuf7458c52015-10-26 21:10:41 +08001801 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001802 ASSERT_VK_SUCCESS(err);
1803
Karl Schultz6addd812016-02-02 17:17:23 -07001804 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001805
1806 mem_alloc.allocationSize = mem_reqs.size;
1807
Karl Schultz6addd812016-02-02 17:17:23 -07001808 pass =
1809 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001810 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001811
1812 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001813 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001817 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001818
1819 // Try to bind free memory that has been freed
1820 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1821 // This may very well return an error.
1822 (void)err;
1823
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001824 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001825
Chia-I Wuf7458c52015-10-26 21:10:41 +08001826 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001827}
1828
Karl Schultz6addd812016-02-02 17:17:23 -07001829TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
1830 VkResult err;
1831 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06001832
Karl Schultz6addd812016-02-02 17:17:23 -07001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1834 "Invalid VkImage Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001835
Tobin Ehlisec598302015-09-15 15:02:17 -06001836 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06001837
Karl Schultz6addd812016-02-02 17:17:23 -07001838 // Create an image object, allocate memory, destroy the object and then try
1839 // to bind it
1840 VkImage image;
1841 VkDeviceMemory mem;
1842 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06001843
Karl Schultz6addd812016-02-02 17:17:23 -07001844 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1845 const int32_t tex_width = 32;
1846 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06001847
1848 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1850 image_create_info.pNext = NULL;
1851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1852 image_create_info.format = tex_format;
1853 image_create_info.extent.width = tex_width;
1854 image_create_info.extent.height = tex_height;
1855 image_create_info.extent.depth = 1;
1856 image_create_info.mipLevels = 1;
1857 image_create_info.arrayLayers = 1;
1858 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1859 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1860 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1861 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001862
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001863 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001864 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1865 mem_alloc.pNext = NULL;
1866 mem_alloc.allocationSize = 0;
1867 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06001868
Chia-I Wuf7458c52015-10-26 21:10:41 +08001869 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06001870 ASSERT_VK_SUCCESS(err);
1871
Karl Schultz6addd812016-02-02 17:17:23 -07001872 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06001873
1874 mem_alloc.allocationSize = mem_reqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07001875 pass =
1876 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001877 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06001878
1879 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08001884 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06001885 ASSERT_VK_SUCCESS(err);
1886
1887 // Now Try to bind memory to this destroyed object
1888 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1889 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07001890 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06001891
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001892 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001893
Chia-I Wuf7458c52015-10-26 21:10:41 +08001894 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001895}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06001896
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001897#endif // OBJ_TRACKER_TESTS
1898
Tobin Ehlis0788f522015-05-26 16:11:58 -06001899#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06001900
1901// This is a positive test. No errors should be generated.
1902TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
1903
1904 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
1905 "submitted on separate queues followed by a QueueWaitIdle.");
1906
Dustin Graves48458142016-04-29 16:11:55 -06001907 if ((m_device->queue_props.empty()) ||
1908 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06001909 return;
1910
Mark Lobodzinskic808d442016-04-14 10:57:23 -06001911 m_errorMonitor->ExpectSuccess();
1912
1913 VkSemaphore semaphore;
1914 VkSemaphoreCreateInfo semaphore_create_info{};
1915 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
1916 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
1917 &semaphore);
1918
1919 VkCommandPool command_pool;
1920 VkCommandPoolCreateInfo pool_create_info{};
1921 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
1922 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
1923 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
1924 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
1925 &command_pool);
1926
1927 VkCommandBuffer command_buffer[2];
1928 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
1929 command_buffer_allocate_info.sType =
1930 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1931 command_buffer_allocate_info.commandPool = command_pool;
1932 command_buffer_allocate_info.commandBufferCount = 2;
1933 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1934 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
1935 command_buffer);
1936
1937 VkQueue queue = VK_NULL_HANDLE;
1938 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
1939 1, &queue);
1940
1941 {
1942 VkCommandBufferBeginInfo begin_info{};
1943 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1944 vkBeginCommandBuffer(command_buffer[0], &begin_info);
1945
1946 vkCmdPipelineBarrier(command_buffer[0],
1947 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
1948 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
1949 0, nullptr, 0, nullptr);
1950
1951 VkViewport viewport{};
1952 viewport.maxDepth = 1.0f;
1953 viewport.minDepth = 0.0f;
1954 viewport.width = 512;
1955 viewport.height = 512;
1956 viewport.x = 0;
1957 viewport.y = 0;
1958 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
1959 vkEndCommandBuffer(command_buffer[0]);
1960 }
1961 {
1962 VkCommandBufferBeginInfo begin_info{};
1963 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1964 vkBeginCommandBuffer(command_buffer[1], &begin_info);
1965
1966 VkViewport viewport{};
1967 viewport.maxDepth = 1.0f;
1968 viewport.minDepth = 0.0f;
1969 viewport.width = 512;
1970 viewport.height = 512;
1971 viewport.x = 0;
1972 viewport.y = 0;
1973 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
1974 vkEndCommandBuffer(command_buffer[1]);
1975 }
1976 {
1977 VkSubmitInfo submit_info{};
1978 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1979 submit_info.commandBufferCount = 1;
1980 submit_info.pCommandBuffers = &command_buffer[0];
1981 submit_info.signalSemaphoreCount = 1;
1982 submit_info.pSignalSemaphores = &semaphore;
1983 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
1984 }
1985 {
1986 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1987 VkSubmitInfo submit_info{};
1988 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1989 submit_info.commandBufferCount = 1;
1990 submit_info.pCommandBuffers = &command_buffer[1];
1991 submit_info.waitSemaphoreCount = 1;
1992 submit_info.pWaitSemaphores = &semaphore;
1993 submit_info.pWaitDstStageMask = flags;
1994 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1995 }
1996
1997 vkQueueWaitIdle(m_device->m_queue);
1998
1999 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2000 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2001 &command_buffer[0]);
2002 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2003
2004 m_errorMonitor->VerifyNotFound();
2005}
2006
2007// This is a positive test. No errors should be generated.
2008TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
2009
2010 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2011 "submitted on separate queues, the second having a fence"
2012 "followed by a QueueWaitIdle.");
2013
Dustin Graves48458142016-04-29 16:11:55 -06002014 if ((m_device->queue_props.empty()) ||
2015 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002016 return;
2017
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002018 m_errorMonitor->ExpectSuccess();
2019
2020 VkFence fence;
2021 VkFenceCreateInfo fence_create_info{};
2022 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2023 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2024
2025 VkSemaphore semaphore;
2026 VkSemaphoreCreateInfo semaphore_create_info{};
2027 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2028 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2029 &semaphore);
2030
2031 VkCommandPool command_pool;
2032 VkCommandPoolCreateInfo pool_create_info{};
2033 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2034 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2035 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2036 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2037 &command_pool);
2038
2039 VkCommandBuffer command_buffer[2];
2040 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2041 command_buffer_allocate_info.sType =
2042 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2043 command_buffer_allocate_info.commandPool = command_pool;
2044 command_buffer_allocate_info.commandBufferCount = 2;
2045 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2046 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2047 command_buffer);
2048
2049 VkQueue queue = VK_NULL_HANDLE;
2050 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2051 1, &queue);
2052
2053 {
2054 VkCommandBufferBeginInfo begin_info{};
2055 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2056 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2057
2058 vkCmdPipelineBarrier(command_buffer[0],
2059 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2060 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2061 0, nullptr, 0, nullptr);
2062
2063 VkViewport viewport{};
2064 viewport.maxDepth = 1.0f;
2065 viewport.minDepth = 0.0f;
2066 viewport.width = 512;
2067 viewport.height = 512;
2068 viewport.x = 0;
2069 viewport.y = 0;
2070 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2071 vkEndCommandBuffer(command_buffer[0]);
2072 }
2073 {
2074 VkCommandBufferBeginInfo begin_info{};
2075 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2076 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2077
2078 VkViewport viewport{};
2079 viewport.maxDepth = 1.0f;
2080 viewport.minDepth = 0.0f;
2081 viewport.width = 512;
2082 viewport.height = 512;
2083 viewport.x = 0;
2084 viewport.y = 0;
2085 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2086 vkEndCommandBuffer(command_buffer[1]);
2087 }
2088 {
2089 VkSubmitInfo submit_info{};
2090 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2091 submit_info.commandBufferCount = 1;
2092 submit_info.pCommandBuffers = &command_buffer[0];
2093 submit_info.signalSemaphoreCount = 1;
2094 submit_info.pSignalSemaphores = &semaphore;
2095 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2096 }
2097 {
2098 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2099 VkSubmitInfo submit_info{};
2100 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2101 submit_info.commandBufferCount = 1;
2102 submit_info.pCommandBuffers = &command_buffer[1];
2103 submit_info.waitSemaphoreCount = 1;
2104 submit_info.pWaitSemaphores = &semaphore;
2105 submit_info.pWaitDstStageMask = flags;
2106 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2107 }
2108
2109 vkQueueWaitIdle(m_device->m_queue);
2110
2111 vkDestroyFence(m_device->device(), fence, nullptr);
2112 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2113 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2114 &command_buffer[0]);
2115 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2116
2117 m_errorMonitor->VerifyNotFound();
2118}
2119
2120// This is a positive test. No errors should be generated.
2121TEST_F(VkLayerTest,
2122 TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
2123
2124 TEST_DESCRIPTION(
2125 "Two command buffers, each in a separate QueueSubmit call "
2126 "submitted on separate queues, the second having a fence"
2127 "followed by two consecutive WaitForFences calls on the same fence.");
2128
Dustin Graves48458142016-04-29 16:11:55 -06002129 if ((m_device->queue_props.empty()) ||
2130 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002131 return;
2132
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002133 m_errorMonitor->ExpectSuccess();
2134
2135 VkFence fence;
2136 VkFenceCreateInfo fence_create_info{};
2137 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2138 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2139
2140 VkSemaphore semaphore;
2141 VkSemaphoreCreateInfo semaphore_create_info{};
2142 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2143 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2144 &semaphore);
2145
2146 VkCommandPool command_pool;
2147 VkCommandPoolCreateInfo pool_create_info{};
2148 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2149 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2150 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2151 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2152 &command_pool);
2153
2154 VkCommandBuffer command_buffer[2];
2155 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2156 command_buffer_allocate_info.sType =
2157 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2158 command_buffer_allocate_info.commandPool = command_pool;
2159 command_buffer_allocate_info.commandBufferCount = 2;
2160 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2161 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2162 command_buffer);
2163
2164 VkQueue queue = VK_NULL_HANDLE;
2165 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2166 1, &queue);
2167
2168 {
2169 VkCommandBufferBeginInfo begin_info{};
2170 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2171 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2172
2173 vkCmdPipelineBarrier(command_buffer[0],
2174 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2175 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2176 0, nullptr, 0, nullptr);
2177
2178 VkViewport viewport{};
2179 viewport.maxDepth = 1.0f;
2180 viewport.minDepth = 0.0f;
2181 viewport.width = 512;
2182 viewport.height = 512;
2183 viewport.x = 0;
2184 viewport.y = 0;
2185 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2186 vkEndCommandBuffer(command_buffer[0]);
2187 }
2188 {
2189 VkCommandBufferBeginInfo begin_info{};
2190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2191 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2192
2193 VkViewport viewport{};
2194 viewport.maxDepth = 1.0f;
2195 viewport.minDepth = 0.0f;
2196 viewport.width = 512;
2197 viewport.height = 512;
2198 viewport.x = 0;
2199 viewport.y = 0;
2200 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2201 vkEndCommandBuffer(command_buffer[1]);
2202 }
2203 {
2204 VkSubmitInfo submit_info{};
2205 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2206 submit_info.commandBufferCount = 1;
2207 submit_info.pCommandBuffers = &command_buffer[0];
2208 submit_info.signalSemaphoreCount = 1;
2209 submit_info.pSignalSemaphores = &semaphore;
2210 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2211 }
2212 {
2213 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2214 VkSubmitInfo submit_info{};
2215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2216 submit_info.commandBufferCount = 1;
2217 submit_info.pCommandBuffers = &command_buffer[1];
2218 submit_info.waitSemaphoreCount = 1;
2219 submit_info.pWaitSemaphores = &semaphore;
2220 submit_info.pWaitDstStageMask = flags;
2221 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2222 }
2223
2224 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2225 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2226
2227 vkDestroyFence(m_device->device(), fence, nullptr);
2228 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2229 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2230 &command_buffer[0]);
2231 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2232
2233 m_errorMonitor->VerifyNotFound();
2234}
2235
2236// This is a positive test. No errors should be generated.
2237TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
2238
2239 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2240 "submitted on separate queues, the second having a fence, "
2241 "followed by a WaitForFences call.");
2242
Dustin Graves48458142016-04-29 16:11:55 -06002243 if ((m_device->queue_props.empty()) ||
2244 (m_device->queue_props[0].queueCount < 2))
Tony Barbourdc18b262016-04-22 14:49:48 -06002245 return;
2246
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002247 m_errorMonitor->ExpectSuccess();
2248
2249 VkFence fence;
2250 VkFenceCreateInfo fence_create_info{};
2251 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2252 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2253
2254 VkSemaphore semaphore;
2255 VkSemaphoreCreateInfo semaphore_create_info{};
2256 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2257 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2258 &semaphore);
2259
2260 VkCommandPool command_pool;
2261 VkCommandPoolCreateInfo pool_create_info{};
2262 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2263 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2264 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2265 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2266 &command_pool);
2267
2268 VkCommandBuffer command_buffer[2];
2269 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2270 command_buffer_allocate_info.sType =
2271 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2272 command_buffer_allocate_info.commandPool = command_pool;
2273 command_buffer_allocate_info.commandBufferCount = 2;
2274 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2275 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2276 command_buffer);
2277
2278 VkQueue queue = VK_NULL_HANDLE;
2279 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_,
2280 1, &queue);
2281
2282
2283 {
2284 VkCommandBufferBeginInfo begin_info{};
2285 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2286 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2287
2288 vkCmdPipelineBarrier(command_buffer[0],
2289 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2290 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2291 0, nullptr, 0, nullptr);
2292
2293 VkViewport viewport{};
2294 viewport.maxDepth = 1.0f;
2295 viewport.minDepth = 0.0f;
2296 viewport.width = 512;
2297 viewport.height = 512;
2298 viewport.x = 0;
2299 viewport.y = 0;
2300 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2301 vkEndCommandBuffer(command_buffer[0]);
2302 }
2303 {
2304 VkCommandBufferBeginInfo begin_info{};
2305 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2306 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2307
2308 VkViewport viewport{};
2309 viewport.maxDepth = 1.0f;
2310 viewport.minDepth = 0.0f;
2311 viewport.width = 512;
2312 viewport.height = 512;
2313 viewport.x = 0;
2314 viewport.y = 0;
2315 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2316 vkEndCommandBuffer(command_buffer[1]);
2317 }
2318 {
2319 VkSubmitInfo submit_info{};
2320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2321 submit_info.commandBufferCount = 1;
2322 submit_info.pCommandBuffers = &command_buffer[0];
2323 submit_info.signalSemaphoreCount = 1;
2324 submit_info.pSignalSemaphores = &semaphore;
2325 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
2326 }
2327 {
2328 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2329 VkSubmitInfo submit_info{};
2330 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2331 submit_info.commandBufferCount = 1;
2332 submit_info.pCommandBuffers = &command_buffer[1];
2333 submit_info.waitSemaphoreCount = 1;
2334 submit_info.pWaitSemaphores = &semaphore;
2335 submit_info.pWaitDstStageMask = flags;
2336 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2337 }
2338
2339 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2340
2341 vkDestroyFence(m_device->device(), fence, nullptr);
2342 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2343 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2344 &command_buffer[0]);
2345 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2346
2347 m_errorMonitor->VerifyNotFound();
2348}
2349
2350// This is a positive test. No errors should be generated.
2351TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
2352
2353 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2354 "on the same queue, sharing a signal/wait semaphore, the "
2355 "second having a fence, "
2356 "followed by a WaitForFences call.");
2357
2358 m_errorMonitor->ExpectSuccess();
2359
2360 VkFence fence;
2361 VkFenceCreateInfo fence_create_info{};
2362 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2363 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2364
2365 VkSemaphore semaphore;
2366 VkSemaphoreCreateInfo semaphore_create_info{};
2367 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2368 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2369 &semaphore);
2370
2371 VkCommandPool command_pool;
2372 VkCommandPoolCreateInfo pool_create_info{};
2373 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2374 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2375 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2376 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2377 &command_pool);
2378
2379 VkCommandBuffer command_buffer[2];
2380 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2381 command_buffer_allocate_info.sType =
2382 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2383 command_buffer_allocate_info.commandPool = command_pool;
2384 command_buffer_allocate_info.commandBufferCount = 2;
2385 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2386 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2387 command_buffer);
2388
2389 {
2390 VkCommandBufferBeginInfo begin_info{};
2391 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2392 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2393
2394 vkCmdPipelineBarrier(command_buffer[0],
2395 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2396 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2397 0, nullptr, 0, nullptr);
2398
2399 VkViewport viewport{};
2400 viewport.maxDepth = 1.0f;
2401 viewport.minDepth = 0.0f;
2402 viewport.width = 512;
2403 viewport.height = 512;
2404 viewport.x = 0;
2405 viewport.y = 0;
2406 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2407 vkEndCommandBuffer(command_buffer[0]);
2408 }
2409 {
2410 VkCommandBufferBeginInfo begin_info{};
2411 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2412 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2413
2414 VkViewport viewport{};
2415 viewport.maxDepth = 1.0f;
2416 viewport.minDepth = 0.0f;
2417 viewport.width = 512;
2418 viewport.height = 512;
2419 viewport.x = 0;
2420 viewport.y = 0;
2421 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2422 vkEndCommandBuffer(command_buffer[1]);
2423 }
2424 {
2425 VkSubmitInfo submit_info{};
2426 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2427 submit_info.commandBufferCount = 1;
2428 submit_info.pCommandBuffers = &command_buffer[0];
2429 submit_info.signalSemaphoreCount = 1;
2430 submit_info.pSignalSemaphores = &semaphore;
2431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2432 }
2433 {
2434 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2435 VkSubmitInfo submit_info{};
2436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2437 submit_info.commandBufferCount = 1;
2438 submit_info.pCommandBuffers = &command_buffer[1];
2439 submit_info.waitSemaphoreCount = 1;
2440 submit_info.pWaitSemaphores = &semaphore;
2441 submit_info.pWaitDstStageMask = flags;
2442 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2443 }
2444
2445 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2446
2447 vkDestroyFence(m_device->device(), fence, nullptr);
2448 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
2449 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2450 &command_buffer[0]);
2451 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2452
2453 m_errorMonitor->VerifyNotFound();
2454}
2455
2456// This is a positive test. No errors should be generated.
2457TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
2458
2459 TEST_DESCRIPTION(
2460 "Two command buffers, each in a separate QueueSubmit call "
2461 "on the same queue, no fences, followed by a third QueueSubmit with NO "
2462 "SubmitInfos but with a fence, followed by a WaitForFences call.");
2463
2464 m_errorMonitor->ExpectSuccess();
2465
2466 VkFence fence;
2467 VkFenceCreateInfo fence_create_info{};
2468 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2469 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2470
2471 VkCommandPool command_pool;
2472 VkCommandPoolCreateInfo pool_create_info{};
2473 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2474 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2475 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2476 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2477 &command_pool);
2478
2479 VkCommandBuffer command_buffer[2];
2480 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2481 command_buffer_allocate_info.sType =
2482 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2483 command_buffer_allocate_info.commandPool = command_pool;
2484 command_buffer_allocate_info.commandBufferCount = 2;
2485 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2486 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2487 command_buffer);
2488
2489 {
2490 VkCommandBufferBeginInfo begin_info{};
2491 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2492 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2493
2494 vkCmdPipelineBarrier(command_buffer[0],
2495 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2496 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2497 0, nullptr, 0, nullptr);
2498
2499 VkViewport viewport{};
2500 viewport.maxDepth = 1.0f;
2501 viewport.minDepth = 0.0f;
2502 viewport.width = 512;
2503 viewport.height = 512;
2504 viewport.x = 0;
2505 viewport.y = 0;
2506 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2507 vkEndCommandBuffer(command_buffer[0]);
2508 }
2509 {
2510 VkCommandBufferBeginInfo begin_info{};
2511 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2512 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2513
2514 VkViewport viewport{};
2515 viewport.maxDepth = 1.0f;
2516 viewport.minDepth = 0.0f;
2517 viewport.width = 512;
2518 viewport.height = 512;
2519 viewport.x = 0;
2520 viewport.y = 0;
2521 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2522 vkEndCommandBuffer(command_buffer[1]);
2523 }
2524 {
2525 VkSubmitInfo submit_info{};
2526 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2527 submit_info.commandBufferCount = 1;
2528 submit_info.pCommandBuffers = &command_buffer[0];
2529 submit_info.signalSemaphoreCount = 0;
2530 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
2531 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2532 }
2533 {
2534 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2535 VkSubmitInfo submit_info{};
2536 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2537 submit_info.commandBufferCount = 1;
2538 submit_info.pCommandBuffers = &command_buffer[1];
2539 submit_info.waitSemaphoreCount = 0;
2540 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
2541 submit_info.pWaitDstStageMask = flags;
2542 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2543 }
2544
2545 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
2546
2547 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2548
2549 vkDestroyFence(m_device->device(), fence, nullptr);
2550 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2551 &command_buffer[0]);
2552 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2553
2554 m_errorMonitor->VerifyNotFound();
2555}
2556
2557// This is a positive test. No errors should be generated.
2558TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) {
2559
2560 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
2561 "on the same queue, the second having a fence, followed "
2562 "by a WaitForFences call.");
2563
2564 m_errorMonitor->ExpectSuccess();
2565
2566 VkFence fence;
2567 VkFenceCreateInfo fence_create_info{};
2568 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2569 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2570
2571 VkCommandPool command_pool;
2572 VkCommandPoolCreateInfo pool_create_info{};
2573 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2574 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2575 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2576 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2577 &command_pool);
2578
2579 VkCommandBuffer command_buffer[2];
2580 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2581 command_buffer_allocate_info.sType =
2582 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2583 command_buffer_allocate_info.commandPool = command_pool;
2584 command_buffer_allocate_info.commandBufferCount = 2;
2585 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2586 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2587 command_buffer);
2588
2589 {
2590 VkCommandBufferBeginInfo begin_info{};
2591 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2592 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2593
2594 vkCmdPipelineBarrier(command_buffer[0],
2595 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2596 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2597 0, nullptr, 0, nullptr);
2598
2599 VkViewport viewport{};
2600 viewport.maxDepth = 1.0f;
2601 viewport.minDepth = 0.0f;
2602 viewport.width = 512;
2603 viewport.height = 512;
2604 viewport.x = 0;
2605 viewport.y = 0;
2606 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2607 vkEndCommandBuffer(command_buffer[0]);
2608 }
2609 {
2610 VkCommandBufferBeginInfo begin_info{};
2611 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2612 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2613
2614 VkViewport viewport{};
2615 viewport.maxDepth = 1.0f;
2616 viewport.minDepth = 0.0f;
2617 viewport.width = 512;
2618 viewport.height = 512;
2619 viewport.x = 0;
2620 viewport.y = 0;
2621 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2622 vkEndCommandBuffer(command_buffer[1]);
2623 }
2624 {
2625 VkSubmitInfo submit_info{};
2626 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2627 submit_info.commandBufferCount = 1;
2628 submit_info.pCommandBuffers = &command_buffer[0];
2629 submit_info.signalSemaphoreCount = 0;
2630 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
2631 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
2632 }
2633 {
2634 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2635 VkSubmitInfo submit_info{};
2636 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2637 submit_info.commandBufferCount = 1;
2638 submit_info.pCommandBuffers = &command_buffer[1];
2639 submit_info.waitSemaphoreCount = 0;
2640 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
2641 submit_info.pWaitDstStageMask = flags;
2642 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
2643 }
2644
2645 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2646
2647 vkDestroyFence(m_device->device(), fence, nullptr);
2648 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2649 &command_buffer[0]);
2650 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2651
2652 m_errorMonitor->VerifyNotFound();
2653}
2654
2655// This is a positive test. No errors should be generated.
2656TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
2657
2658 TEST_DESCRIPTION(
2659 "Two command buffers each in a separate SubmitInfo sent in a single "
2660 "QueueSubmit call followed by a WaitForFences call.");
2661
2662 m_errorMonitor->ExpectSuccess();
2663
2664 VkFence fence;
2665 VkFenceCreateInfo fence_create_info{};
2666 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2667 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
2668
2669 VkSemaphore semaphore;
2670 VkSemaphoreCreateInfo semaphore_create_info{};
2671 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
2672 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr,
2673 &semaphore);
2674
2675 VkCommandPool command_pool;
2676 VkCommandPoolCreateInfo pool_create_info{};
2677 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2678 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2679 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2680 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr,
2681 &command_pool);
2682
2683 VkCommandBuffer command_buffer[2];
2684 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
2685 command_buffer_allocate_info.sType =
2686 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
2687 command_buffer_allocate_info.commandPool = command_pool;
2688 command_buffer_allocate_info.commandBufferCount = 2;
2689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2690 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info,
2691 command_buffer);
2692
2693 {
2694 VkCommandBufferBeginInfo begin_info{};
2695 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2696 vkBeginCommandBuffer(command_buffer[0], &begin_info);
2697
2698 vkCmdPipelineBarrier(command_buffer[0],
2699 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
2700 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr,
2701 0, nullptr, 0, nullptr);
2702
2703 VkViewport viewport{};
2704 viewport.maxDepth = 1.0f;
2705 viewport.minDepth = 0.0f;
2706 viewport.width = 512;
2707 viewport.height = 512;
2708 viewport.x = 0;
2709 viewport.y = 0;
2710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
2711 vkEndCommandBuffer(command_buffer[0]);
2712 }
2713 {
2714 VkCommandBufferBeginInfo begin_info{};
2715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
2717
2718 VkViewport viewport{};
2719 viewport.maxDepth = 1.0f;
2720 viewport.minDepth = 0.0f;
2721 viewport.width = 512;
2722 viewport.height = 512;
2723 viewport.x = 0;
2724 viewport.y = 0;
2725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
2726 vkEndCommandBuffer(command_buffer[1]);
2727 }
2728 {
2729 VkSubmitInfo submit_info[2];
2730 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
2731
2732 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2733 submit_info[0].pNext = NULL;
2734 submit_info[0].commandBufferCount = 1;
2735 submit_info[0].pCommandBuffers = &command_buffer[0];
2736 submit_info[0].signalSemaphoreCount = 1;
2737 submit_info[0].pSignalSemaphores = &semaphore;
2738 submit_info[0].waitSemaphoreCount = 0;
2739 submit_info[0].pWaitSemaphores = NULL;
2740 submit_info[0].pWaitDstStageMask = 0;
2741
2742 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2743 submit_info[1].pNext = NULL;
2744 submit_info[1].commandBufferCount = 1;
2745 submit_info[1].pCommandBuffers = &command_buffer[1];
2746 submit_info[1].waitSemaphoreCount = 1;
2747 submit_info[1].pWaitSemaphores = &semaphore;
2748 submit_info[1].pWaitDstStageMask = flags;
2749 submit_info[1].signalSemaphoreCount = 0;
2750 submit_info[1].pSignalSemaphores = NULL;
2751 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
2752 }
2753
2754 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
2755
2756 vkDestroyFence(m_device->device(), fence, nullptr);
2757 vkFreeCommandBuffers(m_device->device(), command_pool, 2,
2758 &command_buffer[0]);
2759 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
2760
2761 m_errorMonitor->VerifyNotFound();
2762}
2763
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002764TEST_F(VkLayerTest, DynamicStatesNotBound) {
2765 TEST_DESCRIPTION(
2766 "Run a series of simple draw calls to validate all the different "
2767 "failure cases that can occur when dynamic state is required but not "
2768 "correctly bound."
2769 "Here are the different dynamic state cases verified by this test:\n"
2770 "-Line Width\n-Depth Bias\n-Viewport State\n-Scissor State\n-Blend "
2771 "State\n-Depth Bounds\n-Stencil Read Mask\n-Stencil Write "
2772 "Mask\n-Stencil Reference");
2773
2774 // Dynamic line width
Karl Schultz6addd812016-02-02 17:17:23 -07002775 m_errorMonitor->SetDesiredFailureMsg(
2776 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002777 "Dynamic line width state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002778 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2779 BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002780 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002781 // Dynamic depth bias
Karl Schultz6addd812016-02-02 17:17:23 -07002782 m_errorMonitor->SetDesiredFailureMsg(
2783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002784 "Dynamic depth bias state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002785 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2786 BsoFailDepthBias);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002787 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002788 // Dynamic viewport state
Karl Schultz6addd812016-02-02 17:17:23 -07002789 m_errorMonitor->SetDesiredFailureMsg(
2790 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002791 "Dynamic viewport state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002792 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2793 BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002794 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002795 // Dynamic scissor state
Karl Schultz6addd812016-02-02 17:17:23 -07002796 m_errorMonitor->SetDesiredFailureMsg(
2797 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002798 "Dynamic scissor state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002799 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2800 BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002801 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002802 // Dynamic blend state
Karl Schultz6addd812016-02-02 17:17:23 -07002803 m_errorMonitor->SetDesiredFailureMsg(
2804 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002805 "Dynamic depth bounds state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002806 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2807 BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002808 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002809 // Dynamic stencil read mask
Karl Schultz6addd812016-02-02 17:17:23 -07002810 m_errorMonitor->SetDesiredFailureMsg(
2811 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002812 "Dynamic stencil read mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002813 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2814 BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002815 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002816 // Dynamic stencil write mask
Karl Schultz6addd812016-02-02 17:17:23 -07002817 m_errorMonitor->SetDesiredFailureMsg(
2818 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002819 "Dynamic stencil write mask state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002820 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2821 BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002822 m_errorMonitor->VerifyFound();
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06002823 // Dynamic stencil reference
Karl Schultz6addd812016-02-02 17:17:23 -07002824 m_errorMonitor->SetDesiredFailureMsg(
2825 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002826 "Dynamic stencil reference state not set for this command buffer");
Karl Schultz6addd812016-02-02 17:17:23 -07002827 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText,
2828 BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002829 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06002830}
2831
Karl Schultz6addd812016-02-02 17:17:23 -07002832TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002833 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002834
Karl Schultz6addd812016-02-02 17:17:23 -07002835 m_errorMonitor->SetDesiredFailureMsg(
2836 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2837 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
2838 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002839
2840 VkFenceCreateInfo fenceInfo = {};
2841 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2842 fenceInfo.pNext = NULL;
2843 fenceInfo.flags = 0;
2844
2845 ASSERT_NO_FATAL_FAILURE(InitState());
2846 ASSERT_NO_FATAL_FAILURE(InitViewport());
2847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2848
Karl Schultz6addd812016-02-02 17:17:23 -07002849 // We luck out b/c by default the framework creates CB w/ the
2850 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002851 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07002852 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color,
2853 m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002854 EndCommandBuffer();
2855
2856 testFence.init(*m_device, fenceInfo);
2857
2858 // Bypass framework since it does the waits automatically
2859 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002860 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2862 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002863 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002864 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002865 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002866 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002867 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002868 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002869 submit_info.pSignalSemaphores = NULL;
2870
Karl Schultz6addd812016-02-02 17:17:23 -07002871 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
2872 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002873
Karl Schultz6addd812016-02-02 17:17:23 -07002874 // Cause validation error by re-submitting cmd buffer that should only be
2875 // submitted once
2876 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002878 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002879}
2880
Karl Schultz6addd812016-02-02 17:17:23 -07002881TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002882 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07002883 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002884
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07002886 "Unable to allocate 1 descriptors of "
2887 "type "
2888 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002889
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002890 ASSERT_NO_FATAL_FAILURE(InitState());
2891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002892
Karl Schultz6addd812016-02-02 17:17:23 -07002893 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
2894 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002895 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002896 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2897 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002898
2899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2901 ds_pool_ci.pNext = NULL;
2902 ds_pool_ci.flags = 0;
2903 ds_pool_ci.maxSets = 1;
2904 ds_pool_ci.poolSizeCount = 1;
2905 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002906
2907 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002908 err =
2909 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002910 ASSERT_VK_SUCCESS(err);
2911
2912 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002913 dsl_binding.binding = 0;
2914 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2915 dsl_binding.descriptorCount = 1;
2916 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2917 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002918
2919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2921 ds_layout_ci.pNext = NULL;
2922 ds_layout_ci.bindingCount = 1;
2923 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002924
2925 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002926 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2927 &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002928 ASSERT_VK_SUCCESS(err);
2929
2930 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002931 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002932 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002933 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002934 alloc_info.descriptorPool = ds_pool;
2935 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002936 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
2937 &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002938
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002939 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002940
Chia-I Wuf7458c52015-10-26 21:10:41 +08002941 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2942 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002943}
2944
Karl Schultz6addd812016-02-02 17:17:23 -07002945TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
2946 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06002947
Karl Schultz6addd812016-02-02 17:17:23 -07002948 m_errorMonitor->SetDesiredFailureMsg(
2949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
2950 "It is invalid to call vkFreeDescriptorSets() with a pool created "
2951 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002952
Tobin Ehlise735c692015-10-08 13:13:50 -06002953 ASSERT_NO_FATAL_FAILURE(InitState());
2954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06002955
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002956 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002957 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2958 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06002959
2960 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002961 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2962 ds_pool_ci.pNext = NULL;
2963 ds_pool_ci.maxSets = 1;
2964 ds_pool_ci.poolSizeCount = 1;
2965 ds_pool_ci.flags = 0;
2966 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
2967 // app can only call vkResetDescriptorPool on this pool.;
2968 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06002969
2970 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07002971 err =
2972 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06002973 ASSERT_VK_SUCCESS(err);
2974
2975 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002976 dsl_binding.binding = 0;
2977 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2978 dsl_binding.descriptorCount = 1;
2979 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2980 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06002981
2982 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002983 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2984 ds_layout_ci.pNext = NULL;
2985 ds_layout_ci.bindingCount = 1;
2986 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06002987
2988 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002989 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
2990 &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06002991 ASSERT_VK_SUCCESS(err);
2992
2993 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002994 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002995 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002996 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002997 alloc_info.descriptorPool = ds_pool;
2998 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07002999 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3000 &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003001 ASSERT_VK_SUCCESS(err);
3002
3003 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003004 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003005
Chia-I Wuf7458c52015-10-26 21:10:41 +08003006 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3007 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003008}
3009
Karl Schultz6addd812016-02-02 17:17:23 -07003010TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003011 // Attempt to clear Descriptor Pool with bad object.
3012 // ObjectTracker should catch this.
3013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3014 "Invalid VkDescriptorPool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003015 uint64_t fake_pool_handle = 0xbaad6001;
3016 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3017 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003018 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003019}
3020
Karl Schultz6addd812016-02-02 17:17:23 -07003021TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003022 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3023 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003024 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003025 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003026
3027 uint64_t fake_set_handle = 0xbaad6001;
3028 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003029 VkResult err;
3030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3031 "Invalid VkDescriptorSet Object 0xbaad6001");
3032
3033 ASSERT_NO_FATAL_FAILURE(InitState());
3034
3035 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3036 layout_bindings[0].binding = 0;
3037 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3038 layout_bindings[0].descriptorCount = 1;
3039 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3040 layout_bindings[0].pImmutableSamplers = NULL;
3041
3042 VkDescriptorSetLayout descriptor_set_layout;
3043 VkDescriptorSetLayoutCreateInfo dslci = {};
3044 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3045 dslci.pNext = NULL;
3046 dslci.bindingCount = 1;
3047 dslci.pBindings = layout_bindings;
3048 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003049 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003050
3051 VkPipelineLayout pipeline_layout;
3052 VkPipelineLayoutCreateInfo plci = {};
3053 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3054 plci.pNext = NULL;
3055 plci.setLayoutCount = 1;
3056 plci.pSetLayouts = &descriptor_set_layout;
3057 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003058 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003059
3060 BeginCommandBuffer();
3061 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003062 pipeline_layout, 0, 1, &bad_set, 0, NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003063 m_errorMonitor->VerifyFound();
3064 EndCommandBuffer();
3065 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3066 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003067}
3068
Karl Schultz6addd812016-02-02 17:17:23 -07003069TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003070 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3071 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003072 uint64_t fake_layout_handle = 0xbaad6001;
3073 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3075 "Invalid VkDescriptorSetLayout Object 0xbaad6001");
3076
3077 VkPipelineLayout pipeline_layout;
3078 VkPipelineLayoutCreateInfo plci = {};
3079 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3080 plci.pNext = NULL;
3081 plci.setLayoutCount = 1;
3082 plci.pSetLayouts = &bad_layout;
3083 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3084
3085 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003086}
3087
Karl Schultz6addd812016-02-02 17:17:23 -07003088TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003089 // Attempt to bind an invalid Pipeline to a valid Command Buffer
3090 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003091 // Create a valid cmd buffer
3092 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003093 uint64_t fake_pipeline_handle = 0xbaad6001;
3094 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3096 "Invalid VkPipeline Object 0xbaad6001");
3097 ASSERT_NO_FATAL_FAILURE(InitState());
3098 BeginCommandBuffer();
3099 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3100 VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
3101 m_errorMonitor->VerifyFound();
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06003102
3103 // Now issue a draw call with no pipeline bound
3104 m_errorMonitor->SetDesiredFailureMsg(
3105 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3106 "At Draw/Dispatch time no valid VkPipeline is bound!");
3107 ASSERT_NO_FATAL_FAILURE(InitState());
3108 BeginCommandBuffer();
3109 Draw(1, 0, 0, 0);
3110 m_errorMonitor->VerifyFound();
3111 // Finally same check once more but with Dispatch/Compute
3112 m_errorMonitor->SetDesiredFailureMsg(
3113 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "At Draw/Dispatch time no valid VkPipeline is bound!");
3115 ASSERT_NO_FATAL_FAILURE(InitState());
3116 BeginCommandBuffer();
3117 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
3118 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003119}
3120
Karl Schultz6addd812016-02-02 17:17:23 -07003121TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
3122 // Create and update CommandBuffer then call QueueSubmit w/o calling End on
3123 // CommandBuffer
3124 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003125
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003127 " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003128
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003129 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06003130 ASSERT_NO_FATAL_FAILURE(InitViewport());
3131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003132 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003133 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3134 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06003135
3136 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003137 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3138 ds_pool_ci.pNext = NULL;
3139 ds_pool_ci.maxSets = 1;
3140 ds_pool_ci.poolSizeCount = 1;
3141 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06003142
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003143 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003144 err =
3145 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003147
Tony Barboureb254902015-07-15 12:50:33 -06003148 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003149 dsl_binding.binding = 0;
3150 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3151 dsl_binding.descriptorCount = 1;
3152 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3153 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003154
Tony Barboureb254902015-07-15 12:50:33 -06003155 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003156 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3157 ds_layout_ci.pNext = NULL;
3158 ds_layout_ci.bindingCount = 1;
3159 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003160 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3162 &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003163 ASSERT_VK_SUCCESS(err);
3164
3165 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003166 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003167 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003168 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003169 alloc_info.descriptorPool = ds_pool;
3170 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003171 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3172 &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003173 ASSERT_VK_SUCCESS(err);
3174
Tony Barboureb254902015-07-15 12:50:33 -06003175 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003176 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3177 pipeline_layout_ci.pNext = NULL;
3178 pipeline_layout_ci.setLayoutCount = 1;
3179 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003180
3181 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3183 &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003184 ASSERT_VK_SUCCESS(err);
3185
Karl Schultz6addd812016-02-02 17:17:23 -07003186 VkShaderObj vs(m_device, bindStateVertShaderText,
3187 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06003188 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07003189 // on more devices
3190 VkShaderObj fs(m_device, bindStateFragShaderText,
3191 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003192
Tony Barbourc95e4ac2015-08-04 17:05:26 -06003193 VkPipelineObj pipe(m_device);
3194 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06003195 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06003196 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06003197 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06003198
3199 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003200 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3201 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3202 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3203 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3204 1, &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06003205
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003206 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003207
Chia-I Wuf7458c52015-10-26 21:10:41 +08003208 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3209 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3210 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003211}
3212
Karl Schultz6addd812016-02-02 17:17:23 -07003213TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003214 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07003215 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003216
Karl Schultz6addd812016-02-02 17:17:23 -07003217 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003218 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
3219 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003220
3221 ASSERT_NO_FATAL_FAILURE(InitState());
3222 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003223 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3224 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003225
3226 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003227 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3228 ds_pool_ci.pNext = NULL;
3229 ds_pool_ci.maxSets = 1;
3230 ds_pool_ci.poolSizeCount = 1;
3231 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003232
3233 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003234 err =
3235 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003236 ASSERT_VK_SUCCESS(err);
3237
3238 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003239 dsl_binding.binding = 0;
3240 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3241 dsl_binding.descriptorCount = 1;
3242 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3243 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003244
3245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3247 ds_layout_ci.pNext = NULL;
3248 ds_layout_ci.bindingCount = 1;
3249 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003250 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3252 &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003253 ASSERT_VK_SUCCESS(err);
3254
3255 VkDescriptorSet descriptorSet;
3256 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003257 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003258 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003259 alloc_info.descriptorPool = ds_pool;
3260 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003261 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3262 &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003263 ASSERT_VK_SUCCESS(err);
3264
Karl Schultz6addd812016-02-02 17:17:23 -07003265 VkBufferView view =
3266 (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003267 VkWriteDescriptorSet descriptor_write;
3268 memset(&descriptor_write, 0, sizeof(descriptor_write));
3269 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3270 descriptor_write.dstSet = descriptorSet;
3271 descriptor_write.dstBinding = 0;
3272 descriptor_write.descriptorCount = 1;
3273 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
3274 descriptor_write.pTexelBufferView = &view;
3275
3276 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003278 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07003279
3280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3282}
3283
Karl Schultz6addd812016-02-02 17:17:23 -07003284TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
3285 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
3286 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07003287 // 1. No dynamicOffset supplied
3288 // 2. Too many dynamicOffsets supplied
3289 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07003290 VkResult err;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003292 " requires 1 dynamicOffsets, but only "
3293 "0 dynamicOffsets are left in "
3294 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003295
3296 ASSERT_NO_FATAL_FAILURE(InitState());
3297 ASSERT_NO_FATAL_FAILURE(InitViewport());
3298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3299
3300 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003301 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3302 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003303
3304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3306 ds_pool_ci.pNext = NULL;
3307 ds_pool_ci.maxSets = 1;
3308 ds_pool_ci.poolSizeCount = 1;
3309 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003310
3311 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003312 err =
3313 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003314 ASSERT_VK_SUCCESS(err);
3315
3316 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003317 dsl_binding.binding = 0;
3318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3319 dsl_binding.descriptorCount = 1;
3320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3321 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003322
3323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3325 ds_layout_ci.pNext = NULL;
3326 ds_layout_ci.bindingCount = 1;
3327 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003328 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3330 &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003331 ASSERT_VK_SUCCESS(err);
3332
3333 VkDescriptorSet descriptorSet;
3334 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003336 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003337 alloc_info.descriptorPool = ds_pool;
3338 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3340 &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003341 ASSERT_VK_SUCCESS(err);
3342
3343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3345 pipeline_layout_ci.pNext = NULL;
3346 pipeline_layout_ci.setLayoutCount = 1;
3347 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003348
3349 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3351 &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003352 ASSERT_VK_SUCCESS(err);
3353
3354 // Create a buffer to update the descriptor with
3355 uint32_t qfi = 0;
3356 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003357 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3358 buffCI.size = 1024;
3359 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3360 buffCI.queueFamilyIndexCount = 1;
3361 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003362
3363 VkBuffer dyub;
3364 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3365 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003366 // Allocate memory and bind to buffer so we can make it to the appropriate
3367 // error
3368 VkMemoryAllocateInfo mem_alloc = {};
3369 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3370 mem_alloc.pNext = NULL;
3371 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12003372 mem_alloc.memoryTypeIndex = 0;
3373
3374 VkMemoryRequirements memReqs;
3375 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
3376 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc,
3377 0);
3378 if (!pass) {
3379 vkDestroyBuffer(m_device->device(), dyub, NULL);
3380 return;
3381 }
3382
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003383 VkDeviceMemory mem;
3384 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
3385 ASSERT_VK_SUCCESS(err);
3386 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
3387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003388 // Correctly update descriptor to avoid "NOT_UPDATED" error
3389 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003390 buffInfo.buffer = dyub;
3391 buffInfo.offset = 0;
3392 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003393
3394 VkWriteDescriptorSet descriptor_write;
3395 memset(&descriptor_write, 0, sizeof(descriptor_write));
3396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3397 descriptor_write.dstSet = descriptorSet;
3398 descriptor_write.dstBinding = 0;
3399 descriptor_write.descriptorCount = 1;
3400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
3401 descriptor_write.pBufferInfo = &buffInfo;
3402
3403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3404
3405 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07003406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3407 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3408 1, &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003409 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07003410 uint32_t pDynOff[2] = {512, 756};
3411 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Karl Schultz6addd812016-02-02 17:17:23 -07003412 m_errorMonitor->SetDesiredFailureMsg(
3413 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlisf6585052015-12-17 11:48:42 -07003414 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
Karl Schultz6addd812016-02-02 17:17:23 -07003415 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3416 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3417 1, &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12003418 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07003419 // Finally cause error due to dynamicOffset being too big
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3421 " dynamic offset 512 combined with "
3422 "offset 0 and range 1024 that "
3423 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07003424 // Create PSO to be used for draw-time errors below
3425 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003426 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003427 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07003428 "out gl_PerVertex { \n"
3429 " vec4 gl_Position;\n"
3430 "};\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003431 "void main(){\n"
3432 " gl_Position = vec4(1);\n"
3433 "}\n";
3434 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003435 "#version 450\n"
Tobin Ehlisf6585052015-12-17 11:48:42 -07003436 "\n"
3437 "layout(location=0) out vec4 x;\n"
3438 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3439 "void main(){\n"
3440 " x = vec4(bar.y);\n"
3441 "}\n";
3442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3444 VkPipelineObj pipe(m_device);
3445 pipe.AddShader(&vs);
3446 pipe.AddShader(&fs);
3447 pipe.AddColorAttachment();
3448 pipe.CreateVKPipeline(pipeline_layout, renderPass());
3449
Karl Schultz6addd812016-02-02 17:17:23 -07003450 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3451 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3452 // This update should succeed, but offset size of 512 will overstep buffer
3453 // /w range 1024 & size 1024
3454 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3455 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3456 1, &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07003457 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003458 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003459
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003460 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06003461 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06003462
Tobin Ehlis49f903e2015-11-04 13:30:34 -07003463 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3464 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3465}
3466
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003467TEST_F(VkLayerTest, InvalidPushConstants) {
3468 // Hit push constant error cases:
3469 // 1. Create PipelineLayout where push constant overstep maxPushConstantSize
3470 // 2. Incorrectly set push constant size to 0
3471 // 3. Incorrectly set push constant size to non-multiple of 4
3472 // 4. Attempt push constant update that exceeds maxPushConstantSize
3473 VkResult err;
3474 m_errorMonitor->SetDesiredFailureMsg(
3475 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3476 "vkCreatePipelineLayout() call has push constants with offset ");
3477
3478 ASSERT_NO_FATAL_FAILURE(InitState());
3479 ASSERT_NO_FATAL_FAILURE(InitViewport());
3480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3481
3482 VkPushConstantRange pc_range = {};
3483 pc_range.size = 0xFFFFFFFFu;
3484 pc_range.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3485 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3486 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3487 pipeline_layout_ci.pushConstantRangeCount = 1;
3488 pipeline_layout_ci.pPushConstantRanges = &pc_range;
3489
3490 VkPipelineLayout pipeline_layout;
3491 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3492 &pipeline_layout);
3493
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003494 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003495 // Now cause errors due to size 0 and non-4 byte aligned size
3496 pc_range.size = 0;
3497 m_errorMonitor->SetDesiredFailureMsg(
3498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3499 "vkCreatePipelineLayout() call has push constant index 0 with size 0");
3500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3501 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003502 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003503 pc_range.size = 1;
3504 m_errorMonitor->SetDesiredFailureMsg(
3505 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3506 "vkCreatePipelineLayout() call has push constant index 0 with size 1");
3507 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3508 &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003509 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003510 // Cause error due to bad size in vkCmdPushConstants() call
3511 m_errorMonitor->SetDesiredFailureMsg(
3512 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3513 "vkCmdPushConstants() call has push constants with offset ");
3514 pipeline_layout_ci.pushConstantRangeCount = 0;
3515 pipeline_layout_ci.pPushConstantRanges = NULL;
3516 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3517 &pipeline_layout);
3518 ASSERT_VK_SUCCESS(err);
3519 BeginCommandBuffer();
3520 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout,
3521 VK_SHADER_STAGE_VERTEX_BIT, 0, 0xFFFFFFFFu, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07003523 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3524}
3525
Karl Schultz6addd812016-02-02 17:17:23 -07003526TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07003527 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07003528 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003529
3530 ASSERT_NO_FATAL_FAILURE(InitState());
3531 ASSERT_NO_FATAL_FAILURE(InitViewport());
3532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3533
3534 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
3535 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003536 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3537 ds_type_count[0].descriptorCount = 10;
3538 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
3539 ds_type_count[1].descriptorCount = 2;
3540 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
3541 ds_type_count[2].descriptorCount = 2;
3542 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
3543 ds_type_count[3].descriptorCount = 5;
3544 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
3545 // type
3546 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3547 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3548 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003549
3550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3552 ds_pool_ci.pNext = NULL;
3553 ds_pool_ci.maxSets = 5;
3554 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
3555 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003556
3557 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07003558 err =
3559 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003560 ASSERT_VK_SUCCESS(err);
3561
3562 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
3563 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003564 dsl_binding[0].binding = 0;
3565 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3566 dsl_binding[0].descriptorCount = 5;
3567 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3568 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003569
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003570 // Create layout identical to set0 layout but w/ different stageFlags
3571 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003572 dsl_fs_stage_only.binding = 0;
3573 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3574 dsl_fs_stage_only.descriptorCount = 5;
3575 dsl_fs_stage_only.stageFlags =
3576 VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
3577 // bind time
3578 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3581 ds_layout_ci.pNext = NULL;
3582 ds_layout_ci.bindingCount = 1;
3583 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003584 static const uint32_t NUM_LAYOUTS = 4;
3585 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003586 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003587 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
3588 // layout for error case
3589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3590 &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003591 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003592 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3594 &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003595 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003596 dsl_binding[0].binding = 0;
3597 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003598 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003599 dsl_binding[1].binding = 1;
3600 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
3601 dsl_binding[1].descriptorCount = 2;
3602 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
3603 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003604 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003605 ds_layout_ci.bindingCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07003606 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3607 &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003608 ASSERT_VK_SUCCESS(err);
3609 dsl_binding[0].binding = 0;
3610 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003611 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003612 ds_layout_ci.bindingCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07003613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3614 &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003615 ASSERT_VK_SUCCESS(err);
3616 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003617 dsl_binding[0].descriptorCount = 2;
Karl Schultz6addd812016-02-02 17:17:23 -07003618 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
3619 &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003620 ASSERT_VK_SUCCESS(err);
3621
3622 static const uint32_t NUM_SETS = 4;
3623 VkDescriptorSet descriptorSet[NUM_SETS] = {};
3624 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003625 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003626 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003627 alloc_info.descriptorPool = ds_pool;
3628 alloc_info.pSetLayouts = ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003629 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
3630 descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003632 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07003633 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003634 alloc_info.pSetLayouts = &ds_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003635 err =
3636 vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003637 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003638
3639 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003640 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3641 pipeline_layout_ci.pNext = NULL;
3642 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
3643 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003644
3645 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003646 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3647 &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003648 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003649 // Create pipelineLayout with only one setLayout
3650 pipeline_layout_ci.setLayoutCount = 1;
3651 VkPipelineLayout single_pipe_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07003652 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3653 &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003654 ASSERT_VK_SUCCESS(err);
3655 // Create pipelineLayout with 2 descriptor setLayout at index 0
3656 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
3657 VkPipelineLayout pipe_layout_one_desc;
Karl Schultz6addd812016-02-02 17:17:23 -07003658 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3659 &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003660 ASSERT_VK_SUCCESS(err);
3661 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
3662 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
3663 VkPipelineLayout pipe_layout_five_samp;
Karl Schultz6addd812016-02-02 17:17:23 -07003664 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3665 &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003666 ASSERT_VK_SUCCESS(err);
3667 // Create pipelineLayout with UB type, but stageFlags for FS only
3668 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
3669 VkPipelineLayout pipe_layout_fs_only;
Karl Schultz6addd812016-02-02 17:17:23 -07003670 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3671 &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003672 ASSERT_VK_SUCCESS(err);
3673 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
3674 VkDescriptorSetLayout pl_bad_s0[2] = {};
3675 pl_bad_s0[0] = ds_layout_fs_only;
3676 pl_bad_s0[1] = ds_layout[1];
3677 pipeline_layout_ci.setLayoutCount = 2;
3678 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
3679 VkPipelineLayout pipe_layout_bad_set0;
Karl Schultz6addd812016-02-02 17:17:23 -07003680 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
3681 &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003682 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003683
3684 // Create a buffer to update the descriptor with
3685 uint32_t qfi = 0;
3686 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003687 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3688 buffCI.size = 1024;
3689 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3690 buffCI.queueFamilyIndexCount = 1;
3691 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003692
3693 VkBuffer dyub;
3694 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3695 ASSERT_VK_SUCCESS(err);
3696 // Correctly update descriptor to avoid "NOT_UPDATED" error
3697 static const uint32_t NUM_BUFFS = 5;
3698 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003699 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07003700 buffInfo[i].buffer = dyub;
3701 buffInfo[i].offset = 0;
3702 buffInfo[i].range = 1024;
3703 }
Karl Schultz6addd812016-02-02 17:17:23 -07003704 VkImage image;
3705 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
3706 const int32_t tex_width = 32;
3707 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003708 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3710 image_create_info.pNext = NULL;
3711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3712 image_create_info.format = tex_format;
3713 image_create_info.extent.width = tex_width;
3714 image_create_info.extent.height = tex_height;
3715 image_create_info.extent.depth = 1;
3716 image_create_info.mipLevels = 1;
3717 image_create_info.arrayLayers = 1;
3718 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3719 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
3720 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
3721 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
3723 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003724
Karl Schultz6addd812016-02-02 17:17:23 -07003725 VkMemoryRequirements memReqs;
3726 VkDeviceMemory imageMem;
3727 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003728 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3730 memAlloc.pNext = NULL;
3731 memAlloc.allocationSize = 0;
3732 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003733 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
3734 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07003735 pass =
3736 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07003737 ASSERT_TRUE(pass);
3738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
3739 ASSERT_VK_SUCCESS(err);
3740 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
3741 ASSERT_VK_SUCCESS(err);
3742
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003743 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003744 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3745 image_view_create_info.image = image;
3746 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
3747 image_view_create_info.format = tex_format;
3748 image_view_create_info.subresourceRange.layerCount = 1;
3749 image_view_create_info.subresourceRange.baseMipLevel = 0;
3750 image_view_create_info.subresourceRange.levelCount = 1;
3751 image_view_create_info.subresourceRange.aspectMask =
3752 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07003753
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003754 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07003755 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
3756 &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003758 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003759 imageInfo[0].imageView = view;
3760 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3761 imageInfo[1].imageView = view;
3762 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003763 imageInfo[2].imageView = view;
3764 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3765 imageInfo[3].imageView = view;
3766 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003767
3768 static const uint32_t NUM_SET_UPDATES = 3;
3769 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
3770 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3771 descriptor_write[0].dstSet = descriptorSet[0];
3772 descriptor_write[0].dstBinding = 0;
3773 descriptor_write[0].descriptorCount = 5;
3774 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3775 descriptor_write[0].pBufferInfo = buffInfo;
3776 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3777 descriptor_write[1].dstSet = descriptorSet[1];
3778 descriptor_write[1].dstBinding = 0;
3779 descriptor_write[1].descriptorCount = 2;
3780 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
3781 descriptor_write[1].pImageInfo = imageInfo;
3782 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3783 descriptor_write[2].dstSet = descriptorSet[1];
3784 descriptor_write[2].dstBinding = 1;
3785 descriptor_write[2].descriptorCount = 2;
3786 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003787 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003788
3789 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003790
Tobin Ehlis88452832015-12-03 09:40:56 -07003791 // Create PSO to be used for draw-time errors below
3792 char const *vsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003793 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003794 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07003795 "out gl_PerVertex {\n"
3796 " vec4 gl_Position;\n"
3797 "};\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003798 "void main(){\n"
3799 " gl_Position = vec4(1);\n"
3800 "}\n";
3801 char const *fsSource =
Chris Forbes7b342802016-04-07 13:20:10 +12003802 "#version 450\n"
Tobin Ehlis88452832015-12-03 09:40:56 -07003803 "\n"
3804 "layout(location=0) out vec4 x;\n"
3805 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
3806 "void main(){\n"
3807 " x = vec4(bar.y);\n"
3808 "}\n";
3809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003811 VkPipelineObj pipe(m_device);
3812 pipe.AddShader(&vs);
3813 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07003814 pipe.AddColorAttachment();
3815 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07003816
3817 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07003818
Karl Schultz6addd812016-02-02 17:17:23 -07003819 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
3820 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3821 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
3822 // of PSO
3823 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
3824 // cmd_pipeline.c
3825 // due to the fact that cmd_alloc_dset_data() has not been called in
3826 // cmd_bind_graphics_pipeline()
3827 // TODO : Want to cause various binding incompatibility issues here to test
3828 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07003829 // First cause various verify_layout_compatibility() fails
3830 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003831 // verify_set_layout_compatibility fail cases:
3832 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultz6addd812016-02-02 17:17:23 -07003833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3834 " due to: invalid VkPipelineLayout ");
3835 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3836 VK_PIPELINE_BIND_POINT_GRAPHICS,
3837 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1,
3838 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003839 m_errorMonitor->VerifyFound();
3840
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003841 // 2. layoutIndex exceeds # of layouts in layout
Karl Schultz6addd812016-02-02 17:17:23 -07003842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3843 " attempting to bind set to index 1");
3844 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3845 VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout,
3846 0, 2, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003847 m_errorMonitor->VerifyFound();
3848
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003849 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003850 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
3851 // descriptors
3852 m_errorMonitor->SetDesiredFailureMsg(
3853 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003854 " has 2 descriptors, but DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07003855 vkCmdBindDescriptorSets(
3856 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3857 pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003858 m_errorMonitor->VerifyFound();
3859
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003860 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
3861 // 4. same # of descriptors but mismatch in type
Karl Schultz6addd812016-02-02 17:17:23 -07003862 m_errorMonitor->SetDesiredFailureMsg(
3863 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003864 " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
Karl Schultz6addd812016-02-02 17:17:23 -07003865 vkCmdBindDescriptorSets(
3866 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3867 pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003868 m_errorMonitor->VerifyFound();
3869
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003870 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
3871 // 5. same # of descriptors but mismatch in stageFlags
Karl Schultz6addd812016-02-02 17:17:23 -07003872 m_errorMonitor->SetDesiredFailureMsg(
3873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06003874 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
Karl Schultz6addd812016-02-02 17:17:23 -07003875 vkCmdBindDescriptorSets(
3876 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3877 pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003878 m_errorMonitor->VerifyFound();
3879
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003880 // Cause INFO messages due to disturbing previously bound Sets
3881 // First bind sets 0 & 1
Karl Schultz6addd812016-02-02 17:17:23 -07003882 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3883 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3884 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003885 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Karl Schultz6addd812016-02-02 17:17:23 -07003886 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003887 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003888 " previously bound as set #0 was disturbed ");
3889 vkCmdBindDescriptorSets(
3890 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3891 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003892 m_errorMonitor->VerifyFound();
3893
Karl Schultz6addd812016-02-02 17:17:23 -07003894 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3895 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3896 2, &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003897 // 2. Disturb set after last bound set
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07003898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07003899 " newly bound as set #0 so set #1 and "
3900 "any subsequent sets were disturbed ");
3901 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3902 VK_PIPELINE_BIND_POINT_GRAPHICS,
3903 pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003904 m_errorMonitor->VerifyFound();
3905
Tobin Ehlis88452832015-12-03 09:40:56 -07003906 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07003907 // 1. Error due to not binding required set (we actually use same code as
3908 // above to disturb set0)
3909 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3910 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3911 2, &descriptorSet[0], 0, NULL);
3912 vkCmdBindDescriptorSets(
3913 m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
3914 pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL);
3915 m_errorMonitor->SetDesiredFailureMsg(
3916 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3917 " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07003918 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003919 m_errorMonitor->VerifyFound();
3920
Tobin Ehlis991d45a2016-01-06 08:48:41 -07003921 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003922 // 2. Error due to bound set not being compatible with PSO's
3923 // VkPipelineLayout (diff stageFlags in this case)
3924 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(),
3925 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
3926 2, &descriptorSet[0], 0, NULL);
3927 m_errorMonitor->SetDesiredFailureMsg(
3928 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3929 " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07003930 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003931 m_errorMonitor->VerifyFound();
3932
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003933 // Remaining clean-up
3934 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07003935 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
3937 }
3938 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis9bfd4492016-05-05 15:09:11 -06003939 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only);
3940 vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003941 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07003942 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3943 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3944}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003945
Karl Schultz6addd812016-02-02 17:17:23 -07003946TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003947
Karl Schultz6addd812016-02-02 17:17:23 -07003948 m_errorMonitor->SetDesiredFailureMsg(
3949 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003950 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003951
3952 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003953 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003954 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003955 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003956
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003957 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06003958}
3959
Karl Schultz6addd812016-02-02 17:17:23 -07003960TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
3961 VkResult err;
3962 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003963
Karl Schultz6addd812016-02-02 17:17:23 -07003964 m_errorMonitor->SetDesiredFailureMsg(
3965 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis61b36f32015-12-16 08:19:42 -07003966 " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003967
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003968 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003969
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003970 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003971 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06003972 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003973 cmd.commandPool = m_commandPool;
3974 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003975 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06003976
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003977 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06003978 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003979
3980 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003981 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07003982 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003983 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06003984 cmd_buf_info.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07003985 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
3986 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003987 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003988
3989 // The error should be caught by validation of the BeginCommandBuffer call
3990 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
3991
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003992 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003993 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003994}
3995
Karl Schultz6addd812016-02-02 17:17:23 -07003996TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003997 // Cause error due to Begin while recording CB
3998 // Then cause 2 errors for attempting to reset CB w/o having
3999 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
4000 // which CBs were allocated. Note that this bit is off by default.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004002 "Cannot call Begin on CB");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004003
4004 ASSERT_NO_FATAL_FAILURE(InitState());
4005
4006 // Calls AllocateCommandBuffers
4007 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
4008
Karl Schultz6addd812016-02-02 17:17:23 -07004009 // Force the failure by setting the Renderpass and Framebuffer fields with
4010 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004011 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07004012 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004013 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
4014 cmd_buf_info.pNext = NULL;
4015 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004016 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004017
4018 // Begin CB to transition to recording state
4019 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
4020 // Can't re-begin. This should trigger error
4021 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004022 m_errorMonitor->VerifyFound();
4023
Karl Schultz6addd812016-02-02 17:17:23 -07004024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4025 "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004026 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
4027 // Reset attempt will trigger error due to incorrect CommandPool state
4028 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004029 m_errorMonitor->VerifyFound();
4030
Karl Schultz6addd812016-02-02 17:17:23 -07004031 m_errorMonitor->SetDesiredFailureMsg(
4032 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4033 " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004034 // Transition CB to RECORDED state
4035 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
4036 // Now attempting to Begin will implicitly reset, which triggers error
4037 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004038 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004039}
4040
Karl Schultz6addd812016-02-02 17:17:23 -07004041TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004042 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07004043 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004044
Karl Schultz6addd812016-02-02 17:17:23 -07004045 m_errorMonitor->SetDesiredFailureMsg(
4046 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004047 "Invalid Pipeline CreateInfo State: Vtx Shader required");
4048
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004049 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06004050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004051
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004052 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004053 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4054 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06004055
4056 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004057 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4058 ds_pool_ci.pNext = NULL;
4059 ds_pool_ci.maxSets = 1;
4060 ds_pool_ci.poolSizeCount = 1;
4061 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06004062
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004063 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004064 err =
4065 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004066 ASSERT_VK_SUCCESS(err);
4067
Tony Barboureb254902015-07-15 12:50:33 -06004068 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004069 dsl_binding.binding = 0;
4070 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4071 dsl_binding.descriptorCount = 1;
4072 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4073 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004074
Tony Barboureb254902015-07-15 12:50:33 -06004075 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004076 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4077 ds_layout_ci.pNext = NULL;
4078 ds_layout_ci.bindingCount = 1;
4079 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06004080
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004081 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4083 &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004084 ASSERT_VK_SUCCESS(err);
4085
4086 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004087 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004089 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004090 alloc_info.descriptorPool = ds_pool;
4091 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4093 &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004094 ASSERT_VK_SUCCESS(err);
4095
Tony Barboureb254902015-07-15 12:50:33 -06004096 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004097 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4098 pipeline_layout_ci.setLayoutCount = 1;
4099 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004100
4101 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004102 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4103 &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004104 ASSERT_VK_SUCCESS(err);
4105
Tobin Ehlise68360f2015-10-01 11:15:13 -06004106 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07004107 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06004108
4109 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004110 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4111 vp_state_ci.scissorCount = 1;
4112 vp_state_ci.pScissors = &sc;
4113 vp_state_ci.viewportCount = 1;
4114 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004115
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004116 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4117 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4118 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4119 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4120 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4121 rs_state_ci.depthClampEnable = VK_FALSE;
4122 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4123 rs_state_ci.depthBiasEnable = VK_FALSE;
4124
Tony Barboureb254902015-07-15 12:50:33 -06004125 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004126 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4127 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004128 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004129 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4130 gp_ci.layout = pipeline_layout;
4131 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06004132
4133 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004134 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4135 pc_ci.initialDataSize = 0;
4136 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004137
4138 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06004139 VkPipelineCache pipelineCache;
4140
Karl Schultz6addd812016-02-02 17:17:23 -07004141 err =
4142 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06004143 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4145 &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06004146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004147 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004148
Chia-I Wuf7458c52015-10-26 21:10:41 +08004149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004153}
Tobin Ehlis912df022015-09-17 08:46:18 -06004154/*// TODO : This test should be good, but needs Tess support in compiler to run
4155TEST_F(VkLayerTest, InvalidPatchControlPoints)
4156{
4157 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06004158 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06004159
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07004161 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
4162primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004163
Tobin Ehlis912df022015-09-17 08:46:18 -06004164 ASSERT_NO_FATAL_FAILURE(InitState());
4165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06004166
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004167 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06004168 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004169 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004170
4171 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4172 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4173 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004174 ds_pool_ci.poolSizeCount = 1;
4175 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06004176
4177 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004178 err = vkCreateDescriptorPool(m_device->device(),
4179VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06004180 ASSERT_VK_SUCCESS(err);
4181
4182 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004183 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06004184 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08004185 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004186 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4187 dsl_binding.pImmutableSamplers = NULL;
4188
4189 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004190 ds_layout_ci.sType =
4191VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06004192 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004193 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004194 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06004195
4196 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4198&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06004199 ASSERT_VK_SUCCESS(err);
4200
4201 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07004202 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
4203VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06004204 ASSERT_VK_SUCCESS(err);
4205
4206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004207 pipeline_layout_ci.sType =
4208VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06004209 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004210 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06004211 pipeline_layout_ci.pSetLayouts = &ds_layout;
4212
4213 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4215&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06004216 ASSERT_VK_SUCCESS(err);
4217
4218 VkPipelineShaderStageCreateInfo shaderStages[3];
4219 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
4220
Karl Schultz6addd812016-02-02 17:17:23 -07004221 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
4222this);
Tobin Ehlis912df022015-09-17 08:46:18 -06004223 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07004224 VkShaderObj
4225tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
4226this);
4227 VkShaderObj
4228te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
4229this);
Tobin Ehlis912df022015-09-17 08:46:18 -06004230
Karl Schultz6addd812016-02-02 17:17:23 -07004231 shaderStages[0].sType =
4232VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004233 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004234 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07004235 shaderStages[1].sType =
4236VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004237 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004238 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07004239 shaderStages[2].sType =
4240VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06004241 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06004242 shaderStages[2].shader = te.handle();
4243
4244 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004245 iaCI.sType =
4246VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08004247 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06004248
4249 VkPipelineTessellationStateCreateInfo tsCI = {};
4250 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
4251 tsCI.patchControlPoints = 0; // This will cause an error
4252
4253 VkGraphicsPipelineCreateInfo gp_ci = {};
4254 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4255 gp_ci.pNext = NULL;
4256 gp_ci.stageCount = 3;
4257 gp_ci.pStages = shaderStages;
4258 gp_ci.pVertexInputState = NULL;
4259 gp_ci.pInputAssemblyState = &iaCI;
4260 gp_ci.pTessellationState = &tsCI;
4261 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004262 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06004263 gp_ci.pMultisampleState = NULL;
4264 gp_ci.pDepthStencilState = NULL;
4265 gp_ci.pColorBlendState = NULL;
4266 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4267 gp_ci.layout = pipeline_layout;
4268 gp_ci.renderPass = renderPass();
4269
4270 VkPipelineCacheCreateInfo pc_ci = {};
4271 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4272 pc_ci.pNext = NULL;
4273 pc_ci.initialSize = 0;
4274 pc_ci.initialData = 0;
4275 pc_ci.maxSize = 0;
4276
4277 VkPipeline pipeline;
4278 VkPipelineCache pipelineCache;
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
4281&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06004282 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004283 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4284&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06004285
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004286 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06004287
Chia-I Wuf7458c52015-10-26 21:10:41 +08004288 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06004292}
4293*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06004294// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07004295TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07004296 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004297
Karl Schultz6addd812016-02-02 17:17:23 -07004298 m_errorMonitor->SetDesiredFailureMsg(
4299 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004300 "Gfx Pipeline viewport count (1) must match scissor count (0).");
4301
Tobin Ehlise68360f2015-10-01 11:15:13 -06004302 ASSERT_NO_FATAL_FAILURE(InitState());
4303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004304
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4307 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004308
4309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4311 ds_pool_ci.maxSets = 1;
4312 ds_pool_ci.poolSizeCount = 1;
4313 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004314
4315 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004316 err =
4317 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004318 ASSERT_VK_SUCCESS(err);
4319
4320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004321 dsl_binding.binding = 0;
4322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4323 dsl_binding.descriptorCount = 1;
4324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004325
4326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4328 ds_layout_ci.bindingCount = 1;
4329 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004330
4331 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004332 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4333 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004334 ASSERT_VK_SUCCESS(err);
4335
4336 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004337 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004339 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004340 alloc_info.descriptorPool = ds_pool;
4341 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4343 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004344 ASSERT_VK_SUCCESS(err);
4345
4346 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004347 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4348 pipeline_layout_ci.setLayoutCount = 1;
4349 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004350
4351 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004352 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4353 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004354 ASSERT_VK_SUCCESS(err);
4355
4356 VkViewport vp = {}; // Just need dummy vp to point to
4357
4358 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004359 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4360 vp_state_ci.scissorCount = 0;
4361 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
4362 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004363
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004364 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4365 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4366 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4367 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4368 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4369 rs_state_ci.depthClampEnable = VK_FALSE;
4370 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4371 rs_state_ci.depthBiasEnable = VK_FALSE;
4372
Cody Northropeb3a6c12015-10-05 14:44:45 -06004373 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004374 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004375
Karl Schultz6addd812016-02-02 17:17:23 -07004376 VkShaderObj vs(m_device, bindStateVertShaderText,
4377 VK_SHADER_STAGE_VERTEX_BIT, this);
4378 VkShaderObj fs(m_device, bindStateFragShaderText,
4379 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004380 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004381 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004382 shaderStages[0] = vs.GetStageCreateInfo();
4383 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004384
4385 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004386 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4387 gp_ci.stageCount = 2;
4388 gp_ci.pStages = shaderStages;
4389 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004390 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004391 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4392 gp_ci.layout = pipeline_layout;
4393 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004394
4395 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004396 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004397
4398 VkPipeline pipeline;
4399 VkPipelineCache pipelineCache;
4400
Karl Schultz6addd812016-02-02 17:17:23 -07004401 err =
4402 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004403 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004404 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4405 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004407 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004408
Chia-I Wuf7458c52015-10-26 21:10:41 +08004409 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4410 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004413}
Karl Schultz6addd812016-02-02 17:17:23 -07004414// Don't set viewport state in PSO. This is an error b/c we always need this
4415// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06004416// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07004417TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06004418 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07004419 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004420
Karl Schultz6addd812016-02-02 17:17:23 -07004421 m_errorMonitor->SetDesiredFailureMsg(
4422 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004423 "Gfx Pipeline pViewportState is null. Even if ");
4424
Tobin Ehlise68360f2015-10-01 11:15:13 -06004425 ASSERT_NO_FATAL_FAILURE(InitState());
4426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004427
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004428 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4430 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004431
4432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4434 ds_pool_ci.maxSets = 1;
4435 ds_pool_ci.poolSizeCount = 1;
4436 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004437
4438 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004439 err =
4440 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004441 ASSERT_VK_SUCCESS(err);
4442
4443 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004444 dsl_binding.binding = 0;
4445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4446 dsl_binding.descriptorCount = 1;
4447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004448
4449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4451 ds_layout_ci.bindingCount = 1;
4452 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004453
4454 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004455 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4456 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004457 ASSERT_VK_SUCCESS(err);
4458
4459 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004460 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004461 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004462 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004463 alloc_info.descriptorPool = ds_pool;
4464 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004465 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4466 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004467 ASSERT_VK_SUCCESS(err);
4468
4469 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004470 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4471 pipeline_layout_ci.setLayoutCount = 1;
4472 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004473
4474 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004475 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4476 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004477 ASSERT_VK_SUCCESS(err);
4478
4479 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
4480 // Set scissor as dynamic to avoid second error
4481 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004482 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4483 dyn_state_ci.dynamicStateCount = 1;
4484 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004485
Cody Northropeb3a6c12015-10-05 14:44:45 -06004486 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004487 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004488
Karl Schultz6addd812016-02-02 17:17:23 -07004489 VkShaderObj vs(m_device, bindStateVertShaderText,
4490 VK_SHADER_STAGE_VERTEX_BIT, this);
4491 VkShaderObj fs(m_device, bindStateFragShaderText,
4492 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004493 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004494 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004495 shaderStages[0] = vs.GetStageCreateInfo();
4496 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004497
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004498
4499 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
4500 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4501 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
4502 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
4503 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
4504 rs_state_ci.depthClampEnable = VK_FALSE;
4505 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
4506 rs_state_ci.depthBiasEnable = VK_FALSE;
4507
Tobin Ehlise68360f2015-10-01 11:15:13 -06004508 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004509 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4510 gp_ci.stageCount = 2;
4511 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07004512 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07004513 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
4514 // should cause validation error
4515 gp_ci.pDynamicState = &dyn_state_ci;
4516 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4517 gp_ci.layout = pipeline_layout;
4518 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004519
4520 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004521 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004522
4523 VkPipeline pipeline;
4524 VkPipelineCache pipelineCache;
4525
Karl Schultz6addd812016-02-02 17:17:23 -07004526 err =
4527 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004528 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004529 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4530 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004531
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004532 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004533
Chia-I Wuf7458c52015-10-26 21:10:41 +08004534 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4535 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4536 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4537 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004538}
4539// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07004540// Then run second test where dynamic scissor count doesn't match PSO scissor
4541// count
4542TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
4543 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004544
Karl Schultz6addd812016-02-02 17:17:23 -07004545 m_errorMonitor->SetDesiredFailureMsg(
4546 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004547 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
4548
Tobin Ehlise68360f2015-10-01 11:15:13 -06004549 ASSERT_NO_FATAL_FAILURE(InitState());
4550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06004551
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004552 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004553 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4554 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004555
4556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4558 ds_pool_ci.maxSets = 1;
4559 ds_pool_ci.poolSizeCount = 1;
4560 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004561
4562 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07004563 err =
4564 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004565 ASSERT_VK_SUCCESS(err);
4566
4567 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004568 dsl_binding.binding = 0;
4569 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4570 dsl_binding.descriptorCount = 1;
4571 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004572
4573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4575 ds_layout_ci.bindingCount = 1;
4576 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004577
4578 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4580 &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004581 ASSERT_VK_SUCCESS(err);
4582
4583 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004584 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004586 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004587 alloc_info.descriptorPool = ds_pool;
4588 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4590 &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004591 ASSERT_VK_SUCCESS(err);
4592
4593 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004594 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4595 pipeline_layout_ci.setLayoutCount = 1;
4596 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004597
4598 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07004599 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4600 &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004601 ASSERT_VK_SUCCESS(err);
4602
4603 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004604 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4605 vp_state_ci.viewportCount = 1;
4606 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
4607 vp_state_ci.scissorCount = 1;
4608 vp_state_ci.pScissors =
4609 NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06004610
4611 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
4612 // Set scissor as dynamic to avoid that error
4613 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004614 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4615 dyn_state_ci.dynamicStateCount = 1;
4616 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004617
Cody Northropeb3a6c12015-10-05 14:44:45 -06004618 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07004619 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06004620
Karl Schultz6addd812016-02-02 17:17:23 -07004621 VkShaderObj vs(m_device, bindStateVertShaderText,
4622 VK_SHADER_STAGE_VERTEX_BIT, this);
4623 VkShaderObj fs(m_device, bindStateFragShaderText,
4624 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004625 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004626 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08004627 shaderStages[0] = vs.GetStageCreateInfo();
4628 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004629
Cody Northropf6622dc2015-10-06 10:33:21 -06004630 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4631 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4632 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004633 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06004634 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004635 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06004636 vi_ci.pVertexAttributeDescriptions = nullptr;
4637
4638 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4639 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4640 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4641
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004642 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004643 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06004644 rs_ci.pNext = nullptr;
4645
Mark Youngc89c6312016-03-31 16:03:20 -06004646 VkPipelineColorBlendAttachmentState att = {};
4647 att.blendEnable = VK_FALSE;
4648 att.colorWriteMask = 0xf;
4649
Cody Northropf6622dc2015-10-06 10:33:21 -06004650 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4651 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4652 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06004653 cb_ci.attachmentCount = 1;
4654 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06004655
Tobin Ehlise68360f2015-10-01 11:15:13 -06004656 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004657 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4658 gp_ci.stageCount = 2;
4659 gp_ci.pStages = shaderStages;
4660 gp_ci.pVertexInputState = &vi_ci;
4661 gp_ci.pInputAssemblyState = &ia_ci;
4662 gp_ci.pViewportState = &vp_state_ci;
4663 gp_ci.pRasterizationState = &rs_ci;
4664 gp_ci.pColorBlendState = &cb_ci;
4665 gp_ci.pDynamicState = &dyn_state_ci;
4666 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4667 gp_ci.layout = pipeline_layout;
4668 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004669
4670 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004671 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06004672
4673 VkPipeline pipeline;
4674 VkPipelineCache pipelineCache;
4675
Karl Schultz6addd812016-02-02 17:17:23 -07004676 err =
4677 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004678 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07004679 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4680 &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004681
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004682 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004683
Tobin Ehlisd332f282015-10-02 11:00:56 -06004684 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07004685 // First need to successfully create the PSO from above by setting
4686 // pViewports
4687 m_errorMonitor->SetDesiredFailureMsg(
4688 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4689 "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO "
4690 "scissorCount is 1. These counts must match.");
4691
4692 VkViewport vp = {}; // Just need dummy vp to point to
4693 vp_state_ci.pViewports = &vp;
4694 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4695 &gp_ci, NULL, &pipeline);
4696 ASSERT_VK_SUCCESS(err);
4697 BeginCommandBuffer();
4698 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4699 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4700 VkRect2D scissors[2] = {}; // don't care about data
4701 // Count of 2 doesn't match PSO count of 1
4702 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors);
4703 Draw(1, 0, 0, 0);
4704
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004705 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07004706
4707 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4708 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4710 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4711}
4712// Create PSO w/o non-zero scissorCount but no scissor data
4713// Then run second test where dynamic viewportCount doesn't match PSO
4714// viewportCount
4715TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
4716 VkResult err;
4717
4718 m_errorMonitor->SetDesiredFailureMsg(
4719 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4720 "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
4721
4722 ASSERT_NO_FATAL_FAILURE(InitState());
4723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4724
4725 VkDescriptorPoolSize ds_type_count = {};
4726 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4727 ds_type_count.descriptorCount = 1;
4728
4729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4731 ds_pool_ci.maxSets = 1;
4732 ds_pool_ci.poolSizeCount = 1;
4733 ds_pool_ci.pPoolSizes = &ds_type_count;
4734
4735 VkDescriptorPool ds_pool;
4736 err =
4737 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4738 ASSERT_VK_SUCCESS(err);
4739
4740 VkDescriptorSetLayoutBinding dsl_binding = {};
4741 dsl_binding.binding = 0;
4742 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4743 dsl_binding.descriptorCount = 1;
4744 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4745
4746 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4747 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4748 ds_layout_ci.bindingCount = 1;
4749 ds_layout_ci.pBindings = &dsl_binding;
4750
4751 VkDescriptorSetLayout ds_layout;
4752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4753 &ds_layout);
4754 ASSERT_VK_SUCCESS(err);
4755
4756 VkDescriptorSet descriptorSet;
4757 VkDescriptorSetAllocateInfo alloc_info = {};
4758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4759 alloc_info.descriptorSetCount = 1;
4760 alloc_info.descriptorPool = ds_pool;
4761 alloc_info.pSetLayouts = &ds_layout;
4762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4763 &descriptorSet);
4764 ASSERT_VK_SUCCESS(err);
4765
4766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4768 pipeline_layout_ci.setLayoutCount = 1;
4769 pipeline_layout_ci.pSetLayouts = &ds_layout;
4770
4771 VkPipelineLayout pipeline_layout;
4772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4773 &pipeline_layout);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4777 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4778 vp_state_ci.scissorCount = 1;
4779 vp_state_ci.pScissors =
4780 NULL; // Null scissor w/ count of 1 should cause error
4781 vp_state_ci.viewportCount = 1;
4782 vp_state_ci.pViewports =
4783 NULL; // vp is dynamic (below) so this won't cause error
4784
4785 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
4786 // Set scissor as dynamic to avoid that error
4787 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
4788 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4789 dyn_state_ci.dynamicStateCount = 1;
4790 dyn_state_ci.pDynamicStates = &vp_state;
4791
4792 VkPipelineShaderStageCreateInfo shaderStages[2];
4793 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4794
4795 VkShaderObj vs(m_device, bindStateVertShaderText,
4796 VK_SHADER_STAGE_VERTEX_BIT, this);
4797 VkShaderObj fs(m_device, bindStateFragShaderText,
4798 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06004799 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07004800 // but add it to be able to run on more devices
4801 shaderStages[0] = vs.GetStageCreateInfo();
4802 shaderStages[1] = fs.GetStageCreateInfo();
4803
4804 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4805 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4806 vi_ci.pNext = nullptr;
4807 vi_ci.vertexBindingDescriptionCount = 0;
4808 vi_ci.pVertexBindingDescriptions = nullptr;
4809 vi_ci.vertexAttributeDescriptionCount = 0;
4810 vi_ci.pVertexAttributeDescriptions = nullptr;
4811
4812 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4813 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4814 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4815
4816 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4817 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4818 rs_ci.pNext = nullptr;
4819
Mark Youngc89c6312016-03-31 16:03:20 -06004820 VkPipelineColorBlendAttachmentState att = {};
4821 att.blendEnable = VK_FALSE;
4822 att.colorWriteMask = 0xf;
4823
Karl Schultz6addd812016-02-02 17:17:23 -07004824 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4825 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4826 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06004827 cb_ci.attachmentCount = 1;
4828 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07004829
4830 VkGraphicsPipelineCreateInfo gp_ci = {};
4831 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4832 gp_ci.stageCount = 2;
4833 gp_ci.pStages = shaderStages;
4834 gp_ci.pVertexInputState = &vi_ci;
4835 gp_ci.pInputAssemblyState = &ia_ci;
4836 gp_ci.pViewportState = &vp_state_ci;
4837 gp_ci.pRasterizationState = &rs_ci;
4838 gp_ci.pColorBlendState = &cb_ci;
4839 gp_ci.pDynamicState = &dyn_state_ci;
4840 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4841 gp_ci.layout = pipeline_layout;
4842 gp_ci.renderPass = renderPass();
4843
4844 VkPipelineCacheCreateInfo pc_ci = {};
4845 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4846
4847 VkPipeline pipeline;
4848 VkPipelineCache pipelineCache;
4849
4850 err =
4851 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
4852 ASSERT_VK_SUCCESS(err);
4853 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4854 &gp_ci, NULL, &pipeline);
4855
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004856 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07004857
4858 // Now hit second fail case where we set scissor w/ different count than PSO
4859 // First need to successfully create the PSO from above by setting
4860 // pViewports
4861 m_errorMonitor->SetDesiredFailureMsg(
4862 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4863 "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO "
4864 "viewportCount is 1. These counts must match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004865
Tobin Ehlisd332f282015-10-02 11:00:56 -06004866 VkRect2D sc = {}; // Just need dummy vp to point to
4867 vp_state_ci.pScissors = &sc;
Karl Schultz6addd812016-02-02 17:17:23 -07004868 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
4869 &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004870 ASSERT_VK_SUCCESS(err);
4871 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07004872 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
4873 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004874 VkViewport viewports[2] = {}; // don't care about data
4875 // Count of 2 doesn't match PSO count of 1
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004876 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06004877 Draw(1, 0, 0, 0);
4878
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004879 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06004880
Chia-I Wuf7458c52015-10-26 21:10:41 +08004881 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06004885}
4886
Mark Young7394fdd2016-03-31 14:56:43 -06004887TEST_F(VkLayerTest, PSOLineWidthInvalid) {
4888 VkResult err;
4889
4890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06004891 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06004892
4893 ASSERT_NO_FATAL_FAILURE(InitState());
4894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4895
4896 VkDescriptorPoolSize ds_type_count = {};
4897 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4898 ds_type_count.descriptorCount = 1;
4899
4900 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4901 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4902 ds_pool_ci.maxSets = 1;
4903 ds_pool_ci.poolSizeCount = 1;
4904 ds_pool_ci.pPoolSizes = &ds_type_count;
4905
4906 VkDescriptorPool ds_pool;
4907 err =
4908 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4909 ASSERT_VK_SUCCESS(err);
4910
4911 VkDescriptorSetLayoutBinding dsl_binding = {};
4912 dsl_binding.binding = 0;
4913 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4914 dsl_binding.descriptorCount = 1;
4915 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4916
4917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4919 ds_layout_ci.bindingCount = 1;
4920 ds_layout_ci.pBindings = &dsl_binding;
4921
4922 VkDescriptorSetLayout ds_layout;
4923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
4924 &ds_layout);
4925 ASSERT_VK_SUCCESS(err);
4926
4927 VkDescriptorSet descriptorSet;
4928 VkDescriptorSetAllocateInfo alloc_info = {};
4929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4930 alloc_info.descriptorSetCount = 1;
4931 alloc_info.descriptorPool = ds_pool;
4932 alloc_info.pSetLayouts = &ds_layout;
4933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
4934 &descriptorSet);
4935 ASSERT_VK_SUCCESS(err);
4936
4937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4939 pipeline_layout_ci.setLayoutCount = 1;
4940 pipeline_layout_ci.pSetLayouts = &ds_layout;
4941
4942 VkPipelineLayout pipeline_layout;
4943 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
4944 &pipeline_layout);
4945 ASSERT_VK_SUCCESS(err);
4946
4947 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4948 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4949 vp_state_ci.scissorCount = 1;
4950 vp_state_ci.pScissors = NULL;
4951 vp_state_ci.viewportCount = 1;
4952 vp_state_ci.pViewports = NULL;
4953
4954 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT,
4955 VK_DYNAMIC_STATE_SCISSOR,
4956 VK_DYNAMIC_STATE_LINE_WIDTH};
4957 // Set scissor as dynamic to avoid that error
4958 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
4959 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
4960 dyn_state_ci.dynamicStateCount = 2;
4961 dyn_state_ci.pDynamicStates = dynamic_states;
4962
4963 VkPipelineShaderStageCreateInfo shaderStages[2];
4964 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4965
4966 VkShaderObj vs(m_device, bindStateVertShaderText,
4967 VK_SHADER_STAGE_VERTEX_BIT, this);
4968 VkShaderObj fs(m_device, bindStateFragShaderText,
4969 VK_SHADER_STAGE_FRAGMENT_BIT,
4970 this); // TODO - We shouldn't need a fragment shader
4971 // but add it to be able to run on more devices
4972 shaderStages[0] = vs.GetStageCreateInfo();
4973 shaderStages[1] = fs.GetStageCreateInfo();
4974
4975 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4976 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4977 vi_ci.pNext = nullptr;
4978 vi_ci.vertexBindingDescriptionCount = 0;
4979 vi_ci.pVertexBindingDescriptions = nullptr;
4980 vi_ci.vertexAttributeDescriptionCount = 0;
4981 vi_ci.pVertexAttributeDescriptions = nullptr;
4982
4983 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4984 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4985 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4986
4987 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4988 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4989 rs_ci.pNext = nullptr;
4990
Mark Young47107952016-05-02 15:59:55 -06004991 // Check too low (line width of -1.0f).
4992 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06004993
4994 VkPipelineColorBlendAttachmentState att = {};
4995 att.blendEnable = VK_FALSE;
4996 att.colorWriteMask = 0xf;
4997
4998 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4999 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5000 cb_ci.pNext = nullptr;
5001 cb_ci.attachmentCount = 1;
5002 cb_ci.pAttachments = &att;
5003
5004 VkGraphicsPipelineCreateInfo gp_ci = {};
5005 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5006 gp_ci.stageCount = 2;
5007 gp_ci.pStages = shaderStages;
5008 gp_ci.pVertexInputState = &vi_ci;
5009 gp_ci.pInputAssemblyState = &ia_ci;
5010 gp_ci.pViewportState = &vp_state_ci;
5011 gp_ci.pRasterizationState = &rs_ci;
5012 gp_ci.pColorBlendState = &cb_ci;
5013 gp_ci.pDynamicState = &dyn_state_ci;
5014 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5015 gp_ci.layout = pipeline_layout;
5016 gp_ci.renderPass = renderPass();
5017
5018 VkPipelineCacheCreateInfo pc_ci = {};
5019 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5020
5021 VkPipeline pipeline;
5022 VkPipelineCache pipelineCache;
5023
5024 err =
5025 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5026 ASSERT_VK_SUCCESS(err);
5027 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5028 &gp_ci, NULL, &pipeline);
5029
5030 m_errorMonitor->VerifyFound();
5031
5032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5033 "Attempt to set lineWidth to 65536");
5034
5035 // Check too high (line width of 65536.0f).
5036 rs_ci.lineWidth = 65536.0f;
5037
5038 err =
5039 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5040 ASSERT_VK_SUCCESS(err);
5041 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5042 &gp_ci, NULL, &pipeline);
5043
5044 m_errorMonitor->VerifyFound();
5045
5046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young47107952016-05-02 15:59:55 -06005047 "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06005048
5049 dyn_state_ci.dynamicStateCount = 3;
5050
5051 rs_ci.lineWidth = 1.0f;
5052
5053 err =
5054 vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
5055 ASSERT_VK_SUCCESS(err);
5056 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
5057 &gp_ci, NULL, &pipeline);
5058 BeginCommandBuffer();
5059 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5060 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5061
5062 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06005063 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06005064 m_errorMonitor->VerifyFound();
5065
5066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5067 "Attempt to set lineWidth to 65536");
5068
5069 // Check too high with dynamic setting.
5070 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
5071 m_errorMonitor->VerifyFound();
5072 EndCommandBuffer();
5073
5074 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5075 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5076 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5078}
5079
Karl Schultz6addd812016-02-02 17:17:23 -07005080TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005081 // Bind a NULL RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005082 m_errorMonitor->SetDesiredFailureMsg(
5083 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005084 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005085
5086 ASSERT_NO_FATAL_FAILURE(InitState());
5087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005088
Tony Barbourfe3351b2015-07-28 10:17:20 -06005089 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005090 // Don't care about RenderPass handle b/c error should be flagged before
5091 // that
5092 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL,
5093 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005094
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005095 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06005096}
5097
Karl Schultz6addd812016-02-02 17:17:23 -07005098TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005099 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005100 m_errorMonitor->SetDesiredFailureMsg(
5101 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005102 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005103
5104 ASSERT_NO_FATAL_FAILURE(InitState());
5105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005106
Tony Barbourfe3351b2015-07-28 10:17:20 -06005107 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005108 // Just create a dummy Renderpass that's non-NULL so we can get to the
5109 // proper error
Tony Barboureb254902015-07-15 12:50:33 -06005110 VkRenderPassBeginInfo rp_begin = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005111 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
5112 rp_begin.pNext = NULL;
5113 rp_begin.renderPass = renderPass();
5114 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005115
Karl Schultz6addd812016-02-02 17:17:23 -07005116 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin,
5117 VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005119 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005120}
5121
Karl Schultz6addd812016-02-02 17:17:23 -07005122TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005123 // Call CmdFillBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07005124 m_errorMonitor->SetDesiredFailureMsg(
5125 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005126 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005127
5128 ASSERT_NO_FATAL_FAILURE(InitState());
5129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005130
5131 // Renderpass is started here
5132 BeginCommandBuffer();
5133
5134 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005135 vk_testing::Buffer dstBuffer;
5136 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005137
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005138 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005139
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005140 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005141}
5142
Karl Schultz6addd812016-02-02 17:17:23 -07005143TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005144 // Call CmdUpdateBuffer within an active renderpass
Karl Schultz6addd812016-02-02 17:17:23 -07005145 m_errorMonitor->SetDesiredFailureMsg(
5146 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005147 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005148
5149 ASSERT_NO_FATAL_FAILURE(InitState());
5150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005151
5152 // Renderpass is started here
5153 BeginCommandBuffer();
5154
5155 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005156 vk_testing::Buffer dstBuffer;
5157 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005158
Karl Schultz6addd812016-02-02 17:17:23 -07005159 VkDeviceSize dstOffset = 0;
5160 VkDeviceSize dataSize = 1024;
5161 const uint32_t *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005162
Karl Schultz6addd812016-02-02 17:17:23 -07005163 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(),
5164 dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005165
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005166 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005167}
5168
Karl Schultz6addd812016-02-02 17:17:23 -07005169TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005170 // Call CmdClearColorImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005171 m_errorMonitor->SetDesiredFailureMsg(
5172 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005173 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005174
5175 ASSERT_NO_FATAL_FAILURE(InitState());
5176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005177
5178 // Renderpass is started here
5179 BeginCommandBuffer();
5180
Michael Lentine0a369f62016-02-03 16:51:46 -06005181 VkClearColorValue clear_color;
5182 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07005183 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
5184 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5185 const int32_t tex_width = 32;
5186 const int32_t tex_height = 32;
5187 VkImageCreateInfo image_create_info = {};
5188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5189 image_create_info.pNext = NULL;
5190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5191 image_create_info.format = tex_format;
5192 image_create_info.extent.width = tex_width;
5193 image_create_info.extent.height = tex_height;
5194 image_create_info.extent.depth = 1;
5195 image_create_info.mipLevels = 1;
5196 image_create_info.arrayLayers = 1;
5197 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5198 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
5199 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005200
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005201 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07005202 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
5203 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005204
Karl Schultz6addd812016-02-02 17:17:23 -07005205 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
5206 image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005207
Karl Schultz6addd812016-02-02 17:17:23 -07005208 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
5209 VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005211 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005212}
5213
Karl Schultz6addd812016-02-02 17:17:23 -07005214TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005215 // Call CmdClearDepthStencilImage within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005216 m_errorMonitor->SetDesiredFailureMsg(
5217 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005218 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005219
5220 ASSERT_NO_FATAL_FAILURE(InitState());
5221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005222
5223 // Renderpass is started here
5224 BeginCommandBuffer();
5225
5226 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07005227 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005228 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
5229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5230 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
5231 image_create_info.extent.width = 64;
5232 image_create_info.extent.height = 64;
5233 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5234 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005235
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005236 vk_testing::Image dstImage;
Karl Schultz6addd812016-02-02 17:17:23 -07005237 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info,
5238 reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005239
Karl Schultz6addd812016-02-02 17:17:23 -07005240 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(
5241 image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005242
Karl Schultz6addd812016-02-02 17:17:23 -07005243 vkCmdClearDepthStencilImage(
5244 m_commandBuffer->GetBufferHandle(), dstImage.handle(),
5245 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1,
5246 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005247
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005248 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005249}
5250
Karl Schultz6addd812016-02-02 17:17:23 -07005251TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005252 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005253 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005254
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005256 "vkCmdClearAttachments: This call "
5257 "must be issued inside an active "
5258 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005259
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005260 ASSERT_NO_FATAL_FAILURE(InitState());
5261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005262
5263 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005264 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005265 ASSERT_VK_SUCCESS(err);
5266
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005267 VkClearAttachment color_attachment;
5268 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5269 color_attachment.clearValue.color.float32[0] = 0;
5270 color_attachment.clearValue.color.float32[1] = 0;
5271 color_attachment.clearValue.color.float32[2] = 0;
5272 color_attachment.clearValue.color.float32[3] = 0;
5273 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07005274 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
5275 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
5276 &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005277
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005278 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06005279}
5280
Karl Schultz9e66a292016-04-21 15:57:51 -06005281TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
5282 // Try to add a buffer memory barrier with no buffer.
5283 m_errorMonitor->SetDesiredFailureMsg(
5284 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5285 "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE");
5286
5287 ASSERT_NO_FATAL_FAILURE(InitState());
5288 BeginCommandBuffer();
5289
5290 VkBufferMemoryBarrier buf_barrier = {};
5291 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
5292 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5293 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5294 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5295 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5296 buf_barrier.buffer = VK_NULL_HANDLE;
5297 buf_barrier.offset = 0;
5298 buf_barrier.size = VK_WHOLE_SIZE;
5299 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5300 VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,
5301 0, 0, nullptr, 1, &buf_barrier, 0, nullptr);
5302
5303 m_errorMonitor->VerifyFound();
5304}
5305
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06005306TEST_F(VkLayerTest, InvalidBarriers) {
5307 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
5308
5309 m_errorMonitor->SetDesiredFailureMsg(
5310 VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
5311
5312 ASSERT_NO_FATAL_FAILURE(InitState());
5313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5314
5315 VkMemoryBarrier mem_barrier = {};
5316 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
5317 mem_barrier.pNext = NULL;
5318 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5319 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5320 BeginCommandBuffer();
5321 // BeginCommandBuffer() starts a render pass
5322 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5323 VK_PIPELINE_STAGE_HOST_BIT,
5324 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
5325 &mem_barrier, 0, nullptr, 0, nullptr);
5326 m_errorMonitor->VerifyFound();
5327
5328 m_errorMonitor->SetDesiredFailureMsg(
5329 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5330 "Image Layout cannot be transitioned to UNDEFINED");
5331 VkImageObj image(m_device);
5332 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
5333 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5334 ASSERT_TRUE(image.initialized());
5335 VkImageMemoryBarrier img_barrier = {};
5336 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
5337 img_barrier.pNext = NULL;
5338 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5339 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5340 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5341 // New layout can't be UNDEFINED
5342 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5343 img_barrier.image = image.handle();
5344 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5345 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5346 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5347 img_barrier.subresourceRange.baseArrayLayer = 0;
5348 img_barrier.subresourceRange.baseMipLevel = 0;
5349 img_barrier.subresourceRange.layerCount = 1;
5350 img_barrier.subresourceRange.levelCount = 1;
5351 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5352 VK_PIPELINE_STAGE_HOST_BIT,
5353 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5354 nullptr, 1, &img_barrier);
5355 m_errorMonitor->VerifyFound();
5356 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5357
5358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5359 "Subresource must have the sum of the "
5360 "baseArrayLayer");
5361 // baseArrayLayer + layerCount must be <= image's arrayLayers
5362 img_barrier.subresourceRange.baseArrayLayer = 1;
5363 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5364 VK_PIPELINE_STAGE_HOST_BIT,
5365 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5366 nullptr, 1, &img_barrier);
5367 m_errorMonitor->VerifyFound();
5368 img_barrier.subresourceRange.baseArrayLayer = 0;
5369
5370 m_errorMonitor->SetDesiredFailureMsg(
5371 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5372 "Subresource must have the sum of the baseMipLevel");
5373 // baseMipLevel + levelCount must be <= image's mipLevels
5374 img_barrier.subresourceRange.baseMipLevel = 1;
5375 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5376 VK_PIPELINE_STAGE_HOST_BIT,
5377 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
5378 nullptr, 1, &img_barrier);
5379 m_errorMonitor->VerifyFound();
5380 img_barrier.subresourceRange.baseMipLevel = 0;
5381
5382 m_errorMonitor->SetDesiredFailureMsg(
5383 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5384 "Buffer Barriers cannot be used during a render pass");
5385 vk_testing::Buffer buffer;
5386 buffer.init(*m_device, 256);
5387 VkBufferMemoryBarrier buf_barrier = {};
5388 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
5389 buf_barrier.pNext = NULL;
5390 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
5391 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
5392 buf_barrier.buffer = buffer.handle();
5393 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5394 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
5395 buf_barrier.offset = 0;
5396 buf_barrier.size = VK_WHOLE_SIZE;
5397 // Can't send buffer barrier during a render pass
5398 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5399 VK_PIPELINE_STAGE_HOST_BIT,
5400 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5401 &buf_barrier, 0, nullptr);
5402 m_errorMonitor->VerifyFound();
5403 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
5404
5405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5406 "which is not less than total size");
5407 buf_barrier.offset = 257;
5408 // Offset greater than total size
5409 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5410 VK_PIPELINE_STAGE_HOST_BIT,
5411 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5412 &buf_barrier, 0, nullptr);
5413 m_errorMonitor->VerifyFound();
5414 buf_barrier.offset = 0;
5415
5416 m_errorMonitor->SetDesiredFailureMsg(
5417 VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
5418 buf_barrier.size = 257;
5419 // Size greater than total size
5420 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
5421 VK_PIPELINE_STAGE_HOST_BIT,
5422 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
5423 &buf_barrier, 0, nullptr);
5424 m_errorMonitor->VerifyFound();
5425 buf_barrier.size = VK_WHOLE_SIZE;
5426
5427 m_errorMonitor->SetDesiredFailureMsg(
5428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5429 "Image is a depth and stencil format and thus must "
5430 "have both VK_IMAGE_ASPECT_DEPTH_BIT and "
5431 "VK_IMAGE_ASPECT_STENCIL_BIT set.");
5432 VkDepthStencilObj ds_image(m_device);
5433 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
5434 ASSERT_TRUE(ds_image.initialized());
5435 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5436 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
5437 img_barrier.image = ds_image.handle();
5438 // Leave aspectMask at COLOR on purpose
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}
5445
Karl Schultz6addd812016-02-02 17:17:23 -07005446TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005447 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07005448 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005449
Karl Schultz6addd812016-02-02 17:17:23 -07005450 m_errorMonitor->SetDesiredFailureMsg(
5451 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005452 "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
5453
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005454 ASSERT_NO_FATAL_FAILURE(InitState());
5455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005456 uint32_t qfi = 0;
5457 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005458 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5459 buffCI.size = 1024;
5460 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
5461 buffCI.queueFamilyIndexCount = 1;
5462 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005463
5464 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005465 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005466 ASSERT_VK_SUCCESS(err);
5467
5468 BeginCommandBuffer();
5469 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07005470 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
5471 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005472 // Should error before calling to driver so don't care about actual data
Karl Schultz6addd812016-02-02 17:17:23 -07005473 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7,
5474 VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005475
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005476 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005477
Chia-I Wuf7458c52015-10-26 21:10:41 +08005478 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06005479}
5480
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005481TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
5482 // Create an out-of-range queueFamilyIndex
5483 m_errorMonitor->SetDesiredFailureMsg(
5484 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis24aab042016-03-24 10:54:18 -06005485 "queueFamilyIndex 777, must have been given when the device was created.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005486
5487 ASSERT_NO_FATAL_FAILURE(InitState());
5488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5489 VkBufferCreateInfo buffCI = {};
5490 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5491 buffCI.size = 1024;
5492 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
5493 buffCI.queueFamilyIndexCount = 1;
5494 // Introduce failure by specifying invalid queue_family_index
5495 uint32_t qfi = 777;
5496 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06005497 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005498
5499 VkBuffer ib;
5500 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
5501
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005502 m_errorMonitor->VerifyFound();
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07005503}
5504
Karl Schultz6addd812016-02-02 17:17:23 -07005505TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
5506 // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be
5507 // secondary)
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005508
Karl Schultz6addd812016-02-02 17:17:23 -07005509 m_errorMonitor->SetDesiredFailureMsg(
5510 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005511 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005512
5513 ASSERT_NO_FATAL_FAILURE(InitState());
5514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005515
5516 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07005517 // ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005518 VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle();
5519 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005520
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005521 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005522}
5523
Karl Schultz6addd812016-02-02 17:17:23 -07005524TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005525 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07005526 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005527
Karl Schultz6addd812016-02-02 17:17:23 -07005528 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005529 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5530 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
5531 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005532
Tobin Ehlis3b780662015-05-28 12:11:26 -06005533 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005534 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005535 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5537 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005538
5539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5541 ds_pool_ci.pNext = NULL;
5542 ds_pool_ci.maxSets = 1;
5543 ds_pool_ci.poolSizeCount = 1;
5544 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005545
Tobin Ehlis3b780662015-05-28 12:11:26 -06005546 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005547 err =
5548 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005549 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06005550 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005551 dsl_binding.binding = 0;
5552 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5553 dsl_binding.descriptorCount = 1;
5554 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5555 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005556
Tony Barboureb254902015-07-15 12:50:33 -06005557 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005558 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5559 ds_layout_ci.pNext = NULL;
5560 ds_layout_ci.bindingCount = 1;
5561 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005562
Tobin Ehlis3b780662015-05-28 12:11:26 -06005563 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5565 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005566 ASSERT_VK_SUCCESS(err);
5567
5568 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005569 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005570 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005571 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005572 alloc_info.descriptorPool = ds_pool;
5573 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005574 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5575 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005576 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005577
Tobin Ehlis30db8f82016-05-05 08:19:48 -06005578 VkSamplerCreateInfo sampler_ci = {};
5579 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5580 sampler_ci.pNext = NULL;
5581 sampler_ci.magFilter = VK_FILTER_NEAREST;
5582 sampler_ci.minFilter = VK_FILTER_NEAREST;
5583 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5584 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5585 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5586 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5587 sampler_ci.mipLodBias = 1.0;
5588 sampler_ci.anisotropyEnable = VK_FALSE;
5589 sampler_ci.maxAnisotropy = 1;
5590 sampler_ci.compareEnable = VK_FALSE;
5591 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5592 sampler_ci.minLod = 1.0;
5593 sampler_ci.maxLod = 1.0;
5594 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5595 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5596 VkSampler sampler;
5597 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5598 ASSERT_VK_SUCCESS(err);
5599
5600 VkDescriptorImageInfo info = {};
5601 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005602
5603 VkWriteDescriptorSet descriptor_write;
5604 memset(&descriptor_write, 0, sizeof(descriptor_write));
5605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005606 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005607 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005608 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005610 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005611
5612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5613
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005614 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005615
Chia-I Wuf7458c52015-10-26 21:10:41 +08005616 vkDestroySampler(m_device->device(), sampler, NULL);
5617 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5618 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005619}
5620
Karl Schultz6addd812016-02-02 17:17:23 -07005621TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005622 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07005623 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005624
Karl Schultz6addd812016-02-02 17:17:23 -07005625 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005626 VK_DEBUG_REPORT_ERROR_BIT_EXT,
5627 " binding #0 with 1 total descriptors but update of 1 descriptors "
5628 "starting at binding offset of 0 combined with update array element "
5629 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005630
Tobin Ehlis3b780662015-05-28 12:11:26 -06005631 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005632 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005633 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005634 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5635 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005636
5637 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005638 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5639 ds_pool_ci.pNext = NULL;
5640 ds_pool_ci.maxSets = 1;
5641 ds_pool_ci.poolSizeCount = 1;
5642 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06005643
Tobin Ehlis3b780662015-05-28 12:11:26 -06005644 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005645 err =
5646 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005647 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005648
Tony Barboureb254902015-07-15 12:50:33 -06005649 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005650 dsl_binding.binding = 0;
5651 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5652 dsl_binding.descriptorCount = 1;
5653 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5654 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06005655
5656 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005657 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5658 ds_layout_ci.pNext = NULL;
5659 ds_layout_ci.bindingCount = 1;
5660 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005661
Tobin Ehlis3b780662015-05-28 12:11:26 -06005662 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5664 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005665 ASSERT_VK_SUCCESS(err);
5666
5667 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005668 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005669 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005670 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005671 alloc_info.descriptorPool = ds_pool;
5672 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005673 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5674 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005675 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005676
Tobin Ehlis30db8f82016-05-05 08:19:48 -06005677 // Correctly update descriptor to avoid "NOT_UPDATED" error
5678 VkDescriptorBufferInfo buff_info = {};
5679 buff_info.buffer =
5680 VkBuffer(0); // Don't care about buffer handle for this test
5681 buff_info.offset = 0;
5682 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005683
5684 VkWriteDescriptorSet descriptor_write;
5685 memset(&descriptor_write, 0, sizeof(descriptor_write));
5686 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005687 descriptor_write.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07005688 descriptor_write.dstArrayElement =
5689 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08005690 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005691 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5692 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005693
5694 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5695
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005696 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005697
Chia-I Wuf7458c52015-10-26 21:10:41 +08005698 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5699 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005700}
5701
Karl Schultz6addd812016-02-02 17:17:23 -07005702TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
5703 // Create layout w/ count of 1 and attempt update to that layout w/ binding
5704 // index 2
5705 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005706
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5708 " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005709
Tobin Ehlis3b780662015-05-28 12:11:26 -06005710 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005711 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005712 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005713 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5714 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005715
5716 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005717 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5718 ds_pool_ci.pNext = NULL;
5719 ds_pool_ci.maxSets = 1;
5720 ds_pool_ci.poolSizeCount = 1;
5721 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005722
Tobin Ehlis3b780662015-05-28 12:11:26 -06005723 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005724 err =
5725 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005726 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005727
Tony Barboureb254902015-07-15 12:50:33 -06005728 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005729 dsl_binding.binding = 0;
5730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5731 dsl_binding.descriptorCount = 1;
5732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5733 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06005734
5735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5737 ds_layout_ci.pNext = NULL;
5738 ds_layout_ci.bindingCount = 1;
5739 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005740 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5742 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005743 ASSERT_VK_SUCCESS(err);
5744
5745 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005746 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005748 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005749 alloc_info.descriptorPool = ds_pool;
5750 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5752 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005753 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005754
Tony Barboureb254902015-07-15 12:50:33 -06005755 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005756 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5757 sampler_ci.pNext = NULL;
5758 sampler_ci.magFilter = VK_FILTER_NEAREST;
5759 sampler_ci.minFilter = VK_FILTER_NEAREST;
5760 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5761 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5762 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5763 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5764 sampler_ci.mipLodBias = 1.0;
5765 sampler_ci.anisotropyEnable = VK_FALSE;
5766 sampler_ci.maxAnisotropy = 1;
5767 sampler_ci.compareEnable = VK_FALSE;
5768 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5769 sampler_ci.minLod = 1.0;
5770 sampler_ci.maxLod = 1.0;
5771 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5772 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06005773
Tobin Ehlis3b780662015-05-28 12:11:26 -06005774 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005775 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005776 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005777
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005778 VkDescriptorImageInfo info = {};
5779 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005780
5781 VkWriteDescriptorSet descriptor_write;
5782 memset(&descriptor_write, 0, sizeof(descriptor_write));
5783 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005784 descriptor_write.dstSet = descriptorSet;
5785 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005786 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005787 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005788 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005789 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005790
5791 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005793 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005794
Chia-I Wuf7458c52015-10-26 21:10:41 +08005795 vkDestroySampler(m_device->device(), sampler, NULL);
5796 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5797 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005798}
5799
Karl Schultz6addd812016-02-02 17:17:23 -07005800TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
5801 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
5802 // types
5803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005804
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07005806 "Unexpected UPDATE struct of type ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005807
Tobin Ehlis3b780662015-05-28 12:11:26 -06005808 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06005809
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005810 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005811 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5812 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005813
5814 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005815 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5816 ds_pool_ci.pNext = NULL;
5817 ds_pool_ci.maxSets = 1;
5818 ds_pool_ci.poolSizeCount = 1;
5819 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06005820
Tobin Ehlis3b780662015-05-28 12:11:26 -06005821 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005822 err =
5823 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005824 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06005825 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005826 dsl_binding.binding = 0;
5827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5828 dsl_binding.descriptorCount = 1;
5829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005831
Tony Barboureb254902015-07-15 12:50:33 -06005832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5834 ds_layout_ci.pNext = NULL;
5835 ds_layout_ci.bindingCount = 1;
5836 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06005837
Tobin Ehlis3b780662015-05-28 12:11:26 -06005838 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5840 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005841 ASSERT_VK_SUCCESS(err);
5842
5843 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005844 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005846 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005847 alloc_info.descriptorPool = ds_pool;
5848 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5850 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005851 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005852
Tony Barboureb254902015-07-15 12:50:33 -06005853 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005854 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5855 sampler_ci.pNext = NULL;
5856 sampler_ci.magFilter = VK_FILTER_NEAREST;
5857 sampler_ci.minFilter = VK_FILTER_NEAREST;
5858 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5859 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5860 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5861 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5862 sampler_ci.mipLodBias = 1.0;
5863 sampler_ci.anisotropyEnable = VK_FALSE;
5864 sampler_ci.maxAnisotropy = 1;
5865 sampler_ci.compareEnable = VK_FALSE;
5866 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5867 sampler_ci.minLod = 1.0;
5868 sampler_ci.maxLod = 1.0;
5869 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5870 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005871 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08005872 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06005873 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005874
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005875 VkDescriptorImageInfo info = {};
5876 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005877
5878 VkWriteDescriptorSet descriptor_write;
5879 memset(&descriptor_write, 0, sizeof(descriptor_write));
Karl Schultz6addd812016-02-02 17:17:23 -07005880 descriptor_write.sType =
5881 (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005882 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005883 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06005884 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005885 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06005886 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08005887
5888 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005890 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005891
Chia-I Wuf7458c52015-10-26 21:10:41 +08005892 vkDestroySampler(m_device->device(), sampler, NULL);
5893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5894 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005895}
5896
Karl Schultz6addd812016-02-02 17:17:23 -07005897TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005898 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07005899 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005900
Karl Schultz6addd812016-02-02 17:17:23 -07005901 m_errorMonitor->SetDesiredFailureMsg(
5902 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005903 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005904
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005905 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07005906 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
5907 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005908 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005909 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
5910 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005911
5912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5914 ds_pool_ci.pNext = NULL;
5915 ds_pool_ci.maxSets = 1;
5916 ds_pool_ci.poolSizeCount = 1;
5917 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005918
5919 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005920 err =
5921 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005922 ASSERT_VK_SUCCESS(err);
5923
5924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005925 dsl_binding.binding = 0;
5926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
5927 dsl_binding.descriptorCount = 1;
5928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5929 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005930
5931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5933 ds_layout_ci.pNext = NULL;
5934 ds_layout_ci.bindingCount = 1;
5935 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005936 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
5938 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005939 ASSERT_VK_SUCCESS(err);
5940
5941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005944 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005945 alloc_info.descriptorPool = ds_pool;
5946 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07005947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
5948 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005949 ASSERT_VK_SUCCESS(err);
5950
Karl Schultz6addd812016-02-02 17:17:23 -07005951 VkSampler sampler =
5952 (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005953
5954 VkDescriptorImageInfo descriptor_info;
5955 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
5956 descriptor_info.sampler = sampler;
5957
5958 VkWriteDescriptorSet descriptor_write;
5959 memset(&descriptor_write, 0, sizeof(descriptor_write));
5960 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005961 descriptor_write.dstSet = descriptorSet;
5962 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005963 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005964 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
5965 descriptor_write.pImageInfo = &descriptor_info;
5966
5967 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5968
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005969 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005970
Chia-I Wuf7458c52015-10-26 21:10:41 +08005971 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5972 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005973}
5974
Karl Schultz6addd812016-02-02 17:17:23 -07005975TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
5976 // Create a single combined Image/Sampler descriptor and send it an invalid
5977 // imageView
5978 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005979
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5981 "Attempted write update to combined "
5982 "image sampler descriptor failed due "
Tobin Ehlis63c4b8a2016-05-09 10:29:34 -06005983 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005984
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005985 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005986 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005987 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5988 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005989
5990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5992 ds_pool_ci.pNext = NULL;
5993 ds_pool_ci.maxSets = 1;
5994 ds_pool_ci.poolSizeCount = 1;
5995 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06005996
5997 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07005998 err =
5999 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006000 ASSERT_VK_SUCCESS(err);
6001
6002 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006003 dsl_binding.binding = 0;
6004 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6005 dsl_binding.descriptorCount = 1;
6006 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6007 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006008
6009 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006010 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6011 ds_layout_ci.pNext = NULL;
6012 ds_layout_ci.bindingCount = 1;
6013 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006014 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6016 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006017 ASSERT_VK_SUCCESS(err);
6018
6019 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006020 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006021 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006022 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006023 alloc_info.descriptorPool = ds_pool;
6024 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6026 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006027 ASSERT_VK_SUCCESS(err);
6028
6029 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006030 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6031 sampler_ci.pNext = NULL;
6032 sampler_ci.magFilter = VK_FILTER_NEAREST;
6033 sampler_ci.minFilter = VK_FILTER_NEAREST;
6034 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6035 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6036 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6037 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6038 sampler_ci.mipLodBias = 1.0;
6039 sampler_ci.anisotropyEnable = VK_FALSE;
6040 sampler_ci.maxAnisotropy = 1;
6041 sampler_ci.compareEnable = VK_FALSE;
6042 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6043 sampler_ci.minLod = 1.0;
6044 sampler_ci.maxLod = 1.0;
6045 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6046 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006047
6048 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006049 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006050 ASSERT_VK_SUCCESS(err);
6051
Karl Schultz6addd812016-02-02 17:17:23 -07006052 VkImageView view =
6053 (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006054
6055 VkDescriptorImageInfo descriptor_info;
6056 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
6057 descriptor_info.sampler = sampler;
6058 descriptor_info.imageView = view;
6059
6060 VkWriteDescriptorSet descriptor_write;
6061 memset(&descriptor_write, 0, sizeof(descriptor_write));
6062 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006063 descriptor_write.dstSet = descriptorSet;
6064 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006065 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6067 descriptor_write.pImageInfo = &descriptor_info;
6068
6069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6070
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006071 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006072
Chia-I Wuf7458c52015-10-26 21:10:41 +08006073 vkDestroySampler(m_device->device(), sampler, NULL);
6074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006076}
6077
Karl Schultz6addd812016-02-02 17:17:23 -07006078TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
6079 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
6080 // into the other
6081 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006082
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6084 " binding #1 with type "
6085 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
6086 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006087
Tobin Ehlis04356f92015-10-27 16:35:27 -06006088 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07006089 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006090 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006091 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6092 ds_type_count[0].descriptorCount = 1;
6093 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6094 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006095
6096 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006097 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6098 ds_pool_ci.pNext = NULL;
6099 ds_pool_ci.maxSets = 1;
6100 ds_pool_ci.poolSizeCount = 2;
6101 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006102
6103 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006104 err =
6105 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006106 ASSERT_VK_SUCCESS(err);
6107 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006108 dsl_binding[0].binding = 0;
6109 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6110 dsl_binding[0].descriptorCount = 1;
6111 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6112 dsl_binding[0].pImmutableSamplers = NULL;
6113 dsl_binding[1].binding = 1;
6114 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6115 dsl_binding[1].descriptorCount = 1;
6116 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6117 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006118
6119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6121 ds_layout_ci.pNext = NULL;
6122 ds_layout_ci.bindingCount = 2;
6123 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006124
6125 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6127 &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006128 ASSERT_VK_SUCCESS(err);
6129
6130 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006131 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006132 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006133 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006134 alloc_info.descriptorPool = ds_pool;
6135 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006136 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6137 &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006138 ASSERT_VK_SUCCESS(err);
6139
6140 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006141 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6142 sampler_ci.pNext = NULL;
6143 sampler_ci.magFilter = VK_FILTER_NEAREST;
6144 sampler_ci.minFilter = VK_FILTER_NEAREST;
6145 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6146 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6147 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6148 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6149 sampler_ci.mipLodBias = 1.0;
6150 sampler_ci.anisotropyEnable = VK_FALSE;
6151 sampler_ci.maxAnisotropy = 1;
6152 sampler_ci.compareEnable = VK_FALSE;
6153 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6154 sampler_ci.minLod = 1.0;
6155 sampler_ci.maxLod = 1.0;
6156 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6157 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006158
6159 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006160 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006161 ASSERT_VK_SUCCESS(err);
6162
6163 VkDescriptorImageInfo info = {};
6164 info.sampler = sampler;
6165
6166 VkWriteDescriptorSet descriptor_write;
6167 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
6168 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006169 descriptor_write.dstSet = descriptorSet;
6170 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08006171 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06006172 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
6173 descriptor_write.pImageInfo = &info;
6174 // This write update should succeed
6175 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6176 // Now perform a copy update that fails due to type mismatch
6177 VkCopyDescriptorSet copy_ds_update;
6178 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6179 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6180 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06006181 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006182 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006183 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08006184 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06006185 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006187 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06006188 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07006189 m_errorMonitor->SetDesiredFailureMsg(
6190 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006191 " does not have copy update src binding of 3.");
Tobin Ehlis04356f92015-10-27 16:35:27 -06006192 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6193 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6194 copy_ds_update.srcSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006195 copy_ds_update.srcBinding =
6196 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006197 copy_ds_update.dstSet = descriptorSet;
6198 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06006199 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06006200 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6201
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006202 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006203
Tobin Ehlis04356f92015-10-27 16:35:27 -06006204 // Now perform a copy update that fails due to binding out of bounds
Karl Schultz6addd812016-02-02 17:17:23 -07006205 m_errorMonitor->SetDesiredFailureMsg(
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006206 VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
6207 "update array offset of 0 and update of "
6208 "5 descriptors oversteps total number "
6209 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006210
Tobin Ehlis04356f92015-10-27 16:35:27 -06006211 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
6212 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
6213 copy_ds_update.srcSet = descriptorSet;
6214 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006215 copy_ds_update.dstSet = descriptorSet;
6216 copy_ds_update.dstBinding = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006217 copy_ds_update.descriptorCount =
6218 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06006219 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
6220
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006221 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06006222
Chia-I Wuf7458c52015-10-26 21:10:41 +08006223 vkDestroySampler(m_device->device(), sampler, NULL);
6224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06006226}
6227
Karl Schultz6addd812016-02-02 17:17:23 -07006228TEST_F(VkLayerTest, NumSamplesMismatch) {
6229 // Create CommandBuffer where MSAA samples doesn't match RenderPass
6230 // sampleCount
6231 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006232
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006234 "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006235
Tobin Ehlis3b780662015-05-28 12:11:26 -06006236 ASSERT_NO_FATAL_FAILURE(InitState());
6237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006238 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06006239 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006240 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006241
6242 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006243 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6244 ds_pool_ci.pNext = NULL;
6245 ds_pool_ci.maxSets = 1;
6246 ds_pool_ci.poolSizeCount = 1;
6247 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06006248
Tobin Ehlis3b780662015-05-28 12:11:26 -06006249 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006250 err =
6251 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006252 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006253
Tony Barboureb254902015-07-15 12:50:33 -06006254 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006255 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06006256 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006257 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006258 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6259 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006260
Tony Barboureb254902015-07-15 12:50:33 -06006261 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6262 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6263 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006264 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006265 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006266
Tobin Ehlis3b780662015-05-28 12:11:26 -06006267 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6269 &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006270 ASSERT_VK_SUCCESS(err);
6271
6272 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006273 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006274 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006275 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006276 alloc_info.descriptorPool = ds_pool;
6277 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006278 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6279 &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006280 ASSERT_VK_SUCCESS(err);
6281
Tony Barboureb254902015-07-15 12:50:33 -06006282 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006283 pipe_ms_state_ci.sType =
6284 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6285 pipe_ms_state_ci.pNext = NULL;
6286 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
6287 pipe_ms_state_ci.sampleShadingEnable = 0;
6288 pipe_ms_state_ci.minSampleShading = 1.0;
6289 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006290
Tony Barboureb254902015-07-15 12:50:33 -06006291 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006292 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6293 pipeline_layout_ci.pNext = NULL;
6294 pipeline_layout_ci.setLayoutCount = 1;
6295 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06006296
6297 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006298 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6299 &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06006300 ASSERT_VK_SUCCESS(err);
6301
Karl Schultz6addd812016-02-02 17:17:23 -07006302 VkShaderObj vs(m_device, bindStateVertShaderText,
6303 VK_SHADER_STAGE_VERTEX_BIT, this);
6304 VkShaderObj fs(m_device, bindStateFragShaderText,
6305 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006306 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006307 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006308 VkPipelineObj pipe(m_device);
6309 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006310 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006311 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006312 pipe.SetMSAA(&pipe_ms_state_ci);
6313 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06006314
Tony Barbourfe3351b2015-07-28 10:17:20 -06006315 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6317 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06006318
Mark Young29927482016-05-04 14:38:51 -06006319 // Render triangle (the error should trigger on the attempt to draw).
6320 Draw(3, 1, 0, 0);
6321
6322 // Finalize recording of the command buffer
6323 EndCommandBuffer();
6324
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006325 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006326
Chia-I Wuf7458c52015-10-26 21:10:41 +08006327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006330}
Mark Young29927482016-05-04 14:38:51 -06006331
Mark Youngc89c6312016-03-31 16:03:20 -06006332TEST_F(VkLayerTest, NumBlendAttachMismatch) {
6333 // Create Pipeline where the number of blend attachments doesn't match the
6334 // number of color attachments. In this case, we don't add any color
6335 // blend attachments even though we have a color attachment.
6336 VkResult err;
6337
6338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Young29927482016-05-04 14:38:51 -06006339 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06006340
6341 ASSERT_NO_FATAL_FAILURE(InitState());
6342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6343 VkDescriptorPoolSize ds_type_count = {};
6344 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6345 ds_type_count.descriptorCount = 1;
6346
6347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6349 ds_pool_ci.pNext = NULL;
6350 ds_pool_ci.maxSets = 1;
6351 ds_pool_ci.poolSizeCount = 1;
6352 ds_pool_ci.pPoolSizes = &ds_type_count;
6353
6354 VkDescriptorPool ds_pool;
6355 err =
6356 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6357 ASSERT_VK_SUCCESS(err);
6358
6359 VkDescriptorSetLayoutBinding dsl_binding = {};
6360 dsl_binding.binding = 0;
6361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6362 dsl_binding.descriptorCount = 1;
6363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6364 dsl_binding.pImmutableSamplers = NULL;
6365
6366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6368 ds_layout_ci.pNext = NULL;
6369 ds_layout_ci.bindingCount = 1;
6370 ds_layout_ci.pBindings = &dsl_binding;
6371
6372 VkDescriptorSetLayout ds_layout;
6373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6374 &ds_layout);
6375 ASSERT_VK_SUCCESS(err);
6376
6377 VkDescriptorSet descriptorSet;
6378 VkDescriptorSetAllocateInfo alloc_info = {};
6379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6380 alloc_info.descriptorSetCount = 1;
6381 alloc_info.descriptorPool = ds_pool;
6382 alloc_info.pSetLayouts = &ds_layout;
6383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6384 &descriptorSet);
6385 ASSERT_VK_SUCCESS(err);
6386
6387 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
6388 pipe_ms_state_ci.sType =
6389 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6390 pipe_ms_state_ci.pNext = NULL;
6391 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
6392 pipe_ms_state_ci.sampleShadingEnable = 0;
6393 pipe_ms_state_ci.minSampleShading = 1.0;
6394 pipe_ms_state_ci.pSampleMask = NULL;
6395
6396 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6397 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6398 pipeline_layout_ci.pNext = NULL;
6399 pipeline_layout_ci.setLayoutCount = 1;
6400 pipeline_layout_ci.pSetLayouts = &ds_layout;
6401
6402 VkPipelineLayout pipeline_layout;
6403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6404 &pipeline_layout);
6405 ASSERT_VK_SUCCESS(err);
6406
6407 VkShaderObj vs(m_device, bindStateVertShaderText,
6408 VK_SHADER_STAGE_VERTEX_BIT, this);
6409 VkShaderObj fs(m_device, bindStateFragShaderText,
6410 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006411 this); // We shouldn't need a fragment shader
Mark Youngc89c6312016-03-31 16:03:20 -06006412 // but add it to be able to run on more devices
6413 VkPipelineObj pipe(m_device);
6414 pipe.AddShader(&vs);
6415 pipe.AddShader(&fs);
6416 pipe.SetMSAA(&pipe_ms_state_ci);
6417 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6418
6419 BeginCommandBuffer();
6420 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6421 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6422
Mark Young29927482016-05-04 14:38:51 -06006423 // Render triangle (the error should trigger on the attempt to draw).
6424 Draw(3, 1, 0, 0);
6425
6426 // Finalize recording of the command buffer
6427 EndCommandBuffer();
6428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006429 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06006430
6431 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6432 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6433 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6434}
Mark Young29927482016-05-04 14:38:51 -06006435
Karl Schultz6addd812016-02-02 17:17:23 -07006436TEST_F(VkLayerTest, ClearCmdNoDraw) {
6437 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
6438 // to issuing a Draw
6439 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006440
Karl Schultz6addd812016-02-02 17:17:23 -07006441 m_errorMonitor->SetDesiredFailureMsg(
Tony Barbour7e56d302016-03-02 15:12:01 -07006442 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006443 "vkCmdClearAttachments() issued on CB object ");
6444
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006445 ASSERT_NO_FATAL_FAILURE(InitState());
6446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06006447
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006448 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006449 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6450 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006451
6452 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006453 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6454 ds_pool_ci.pNext = NULL;
6455 ds_pool_ci.maxSets = 1;
6456 ds_pool_ci.poolSizeCount = 1;
6457 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006458
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006459 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006460 err =
6461 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006462 ASSERT_VK_SUCCESS(err);
6463
Tony Barboureb254902015-07-15 12:50:33 -06006464 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006465 dsl_binding.binding = 0;
6466 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6467 dsl_binding.descriptorCount = 1;
6468 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6469 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006470
Tony Barboureb254902015-07-15 12:50:33 -06006471 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006472 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6473 ds_layout_ci.pNext = NULL;
6474 ds_layout_ci.bindingCount = 1;
6475 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006476
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006477 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6479 &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006480 ASSERT_VK_SUCCESS(err);
6481
6482 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006483 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006484 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006485 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006486 alloc_info.descriptorPool = ds_pool;
6487 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006488 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6489 &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006490 ASSERT_VK_SUCCESS(err);
6491
Tony Barboureb254902015-07-15 12:50:33 -06006492 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 pipe_ms_state_ci.sType =
6494 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6495 pipe_ms_state_ci.pNext = NULL;
6496 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
6497 pipe_ms_state_ci.sampleShadingEnable = 0;
6498 pipe_ms_state_ci.minSampleShading = 1.0;
6499 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006500
Tony Barboureb254902015-07-15 12:50:33 -06006501 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006502 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6503 pipeline_layout_ci.pNext = NULL;
6504 pipeline_layout_ci.setLayoutCount = 1;
6505 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006506
6507 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006508 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6509 &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006510 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006511
Karl Schultz6addd812016-02-02 17:17:23 -07006512 VkShaderObj vs(m_device, bindStateVertShaderText,
6513 VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006514 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006515 // on more devices
6516 VkShaderObj fs(m_device, bindStateFragShaderText,
6517 VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006518
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006519 VkPipelineObj pipe(m_device);
6520 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006521 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006522 pipe.SetMSAA(&pipe_ms_state_ci);
6523 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006524
6525 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006526
Karl Schultz6addd812016-02-02 17:17:23 -07006527 // Main thing we care about for this test is that the VkImage obj we're
6528 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006529 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006530 VkClearAttachment color_attachment;
6531 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6532 color_attachment.clearValue.color.float32[0] = 1.0;
6533 color_attachment.clearValue.color.float32[1] = 1.0;
6534 color_attachment.clearValue.color.float32[2] = 1.0;
6535 color_attachment.clearValue.color.float32[3] = 1.0;
6536 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07006537 VkClearRect clear_rect = {
6538 {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006539
Karl Schultz6addd812016-02-02 17:17:23 -07006540 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1,
6541 &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006542
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006543 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006544
Chia-I Wuf7458c52015-10-26 21:10:41 +08006545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06006548}
6549
Karl Schultz6addd812016-02-02 17:17:23 -07006550TEST_F(VkLayerTest, VtxBufferBadIndex) {
6551 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006552
Karl Schultz6addd812016-02-02 17:17:23 -07006553 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07006554 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07006555 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006556
Tobin Ehlis502480b2015-06-24 15:53:07 -06006557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06006558 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06006559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06006560
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006561 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6563 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006564
6565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6567 ds_pool_ci.pNext = NULL;
6568 ds_pool_ci.maxSets = 1;
6569 ds_pool_ci.poolSizeCount = 1;
6570 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06006571
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06006572 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006573 err =
6574 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006575 ASSERT_VK_SUCCESS(err);
6576
Tony Barboureb254902015-07-15 12:50:33 -06006577 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006578 dsl_binding.binding = 0;
6579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6580 dsl_binding.descriptorCount = 1;
6581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6582 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006583
Tony Barboureb254902015-07-15 12:50:33 -06006584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6586 ds_layout_ci.pNext = NULL;
6587 ds_layout_ci.bindingCount = 1;
6588 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006589
Tobin Ehlis502480b2015-06-24 15:53:07 -06006590 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6592 &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006593 ASSERT_VK_SUCCESS(err);
6594
6595 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006596 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006597 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006598 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006599 alloc_info.descriptorPool = ds_pool;
6600 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006601 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
6602 &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006603 ASSERT_VK_SUCCESS(err);
6604
Tony Barboureb254902015-07-15 12:50:33 -06006605 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 pipe_ms_state_ci.sType =
6607 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
6608 pipe_ms_state_ci.pNext = NULL;
6609 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
6610 pipe_ms_state_ci.sampleShadingEnable = 0;
6611 pipe_ms_state_ci.minSampleShading = 1.0;
6612 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006613
Tony Barboureb254902015-07-15 12:50:33 -06006614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6616 pipeline_layout_ci.pNext = NULL;
6617 pipeline_layout_ci.setLayoutCount = 1;
6618 pipeline_layout_ci.pSetLayouts = &ds_layout;
6619 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06006620
Karl Schultz6addd812016-02-02 17:17:23 -07006621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6622 &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006623 ASSERT_VK_SUCCESS(err);
6624
Karl Schultz6addd812016-02-02 17:17:23 -07006625 VkShaderObj vs(m_device, bindStateVertShaderText,
6626 VK_SHADER_STAGE_VERTEX_BIT, this);
6627 VkShaderObj fs(m_device, bindStateFragShaderText,
6628 VK_SHADER_STAGE_FRAGMENT_BIT,
Karl Schultzbdb75952016-04-19 11:36:49 -06006629 this); // We shouldn't need a fragment shader
Karl Schultz6addd812016-02-02 17:17:23 -07006630 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006631 VkPipelineObj pipe(m_device);
6632 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006633 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006634 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006635 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06006636 pipe.SetViewport(m_viewports);
6637 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06006638 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006639
6640 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07006641 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
6642 VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06006643 // Don't care about actual data, just need to get to draw to flag error
6644 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Karl Schultz6addd812016-02-02 17:17:23 -07006645 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float),
6646 (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06006647 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06006648 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006649
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006650 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006651
Chia-I Wuf7458c52015-10-26 21:10:41 +08006652 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6653 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6654 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06006655}
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006656// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
6657TEST_F(VkLayerTest, InvalidImageLayout) {
6658 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
6659 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
6660 "images in the wrong layout when they're copied or transitioned.");
6661 // 3 in ValidateCmdBufImageLayouts
6662 // * -1 Attempt to submit cmd buf w/ deleted image
6663 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
6664 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
6665 m_errorMonitor->SetDesiredFailureMsg(
6666 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6667 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
6668
6669 ASSERT_NO_FATAL_FAILURE(InitState());
6670 // Create src & dst images to use for copy operations
6671 VkImage src_image;
6672 VkImage dst_image;
6673
6674 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6675 const int32_t tex_width = 32;
6676 const int32_t tex_height = 32;
6677
6678 VkImageCreateInfo image_create_info = {};
6679 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6680 image_create_info.pNext = NULL;
6681 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6682 image_create_info.format = tex_format;
6683 image_create_info.extent.width = tex_width;
6684 image_create_info.extent.height = tex_height;
6685 image_create_info.extent.depth = 1;
6686 image_create_info.mipLevels = 1;
6687 image_create_info.arrayLayers = 4;
6688 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6689 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
6691 image_create_info.flags = 0;
6692
6693 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
6694 ASSERT_VK_SUCCESS(err);
6695 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
6696 ASSERT_VK_SUCCESS(err);
6697
6698 BeginCommandBuffer();
6699 VkImageCopy copyRegion;
6700 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6701 copyRegion.srcSubresource.mipLevel = 0;
6702 copyRegion.srcSubresource.baseArrayLayer = 0;
6703 copyRegion.srcSubresource.layerCount = 1;
6704 copyRegion.srcOffset.x = 0;
6705 copyRegion.srcOffset.y = 0;
6706 copyRegion.srcOffset.z = 0;
6707 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6708 copyRegion.dstSubresource.mipLevel = 0;
6709 copyRegion.dstSubresource.baseArrayLayer = 0;
6710 copyRegion.dstSubresource.layerCount = 1;
6711 copyRegion.dstOffset.x = 0;
6712 copyRegion.dstOffset.y = 0;
6713 copyRegion.dstOffset.z = 0;
6714 copyRegion.extent.width = 1;
6715 copyRegion.extent.height = 1;
6716 copyRegion.extent.depth = 1;
6717 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6718 m_errorMonitor->VerifyFound();
6719 // Now cause error due to src image layout changing
6720 m_errorMonitor->SetDesiredFailureMsg(
6721 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6722 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
6723 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6724 m_errorMonitor->VerifyFound();
6725 // Final src error is due to bad layout type
6726 m_errorMonitor->SetDesiredFailureMsg(
6727 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6728 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
6729 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6730 m_errorMonitor->VerifyFound();
6731 // Now verify same checks for dst
6732 m_errorMonitor->SetDesiredFailureMsg(
6733 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6734 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
6735 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
6736 m_errorMonitor->VerifyFound();
6737 // Now cause error due to src image layout changing
6738 m_errorMonitor->SetDesiredFailureMsg(
6739 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6740 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL.");
6741 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
6742 m_errorMonitor->VerifyFound();
6743 m_errorMonitor->SetDesiredFailureMsg(
6744 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6745 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
6746 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
6747 m_errorMonitor->VerifyFound();
6748 // Now cause error due to bad image layout transition in PipelineBarrier
6749 VkImageMemoryBarrier image_barrier[1] = {};
6750 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6751 image_barrier[0].image = src_image;
6752 image_barrier[0].subresourceRange.layerCount = 2;
6753 image_barrier[0].subresourceRange.levelCount = 2;
6754 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6755 m_errorMonitor->SetDesiredFailureMsg(
6756 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6757 "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL.");
6758 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier);
6759 m_errorMonitor->VerifyFound();
6760
6761 // Finally some layout errors at RenderPass create time
6762 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
6763 VkAttachmentReference attach = {};
6764 // perf warning for GENERAL layout w/ non-DS input attachment
6765 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6766 VkSubpassDescription subpass = {};
6767 subpass.inputAttachmentCount = 1;
6768 subpass.pInputAttachments = &attach;
6769 VkRenderPassCreateInfo rpci = {};
6770 rpci.subpassCount = 1;
6771 rpci.pSubpasses = &subpass;
6772 rpci.attachmentCount = 1;
6773 VkAttachmentDescription attach_desc = {};
6774 attach_desc.format = VK_FORMAT_UNDEFINED;
6775 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -06006776 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006777 VkRenderPass rp;
6778 m_errorMonitor->SetDesiredFailureMsg(
6779 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6780 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
6781 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6782 m_errorMonitor->VerifyFound();
6783 // error w/ non-general layout
6784 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6785
6786 m_errorMonitor->SetDesiredFailureMsg(
6787 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6788 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
6789 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6790 m_errorMonitor->VerifyFound();
6791 subpass.inputAttachmentCount = 0;
6792 subpass.colorAttachmentCount = 1;
6793 subpass.pColorAttachments = &attach;
6794 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6795 // perf warning for GENERAL layout on color attachment
6796 m_errorMonitor->SetDesiredFailureMsg(
6797 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6798 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
6799 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6800 m_errorMonitor->VerifyFound();
6801 // error w/ non-color opt or GENERAL layout for color attachment
6802 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6803 m_errorMonitor->SetDesiredFailureMsg(
6804 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6805 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
6806 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6807 m_errorMonitor->VerifyFound();
6808 subpass.colorAttachmentCount = 0;
6809 subpass.pDepthStencilAttachment = &attach;
6810 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
6811 // perf warning for GENERAL layout on DS attachment
6812 m_errorMonitor->SetDesiredFailureMsg(
6813 VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6814 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
6815 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6816 m_errorMonitor->VerifyFound();
6817 // error w/ non-ds opt or GENERAL layout for color attachment
6818 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6819 m_errorMonitor->SetDesiredFailureMsg(
6820 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6821 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.");
6822 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6823 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -06006824 // For this error we need a valid renderpass so create default one
6825 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6826 attach.attachment = 0;
6827 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
6828 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
6829 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
6830 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
6831 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
6832 // Can't do a CLEAR load on READ_ONLY initialLayout
6833 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
6834 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
6835 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
6836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6837 " with invalid first layout "
6838 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
6839 "ONLY_OPTIMAL");
6840 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
6841 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -06006842
6843 vkDestroyImage(m_device->device(), src_image, NULL);
6844 vkDestroyImage(m_device->device(), dst_image, NULL);
6845}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006846#endif // DRAW_STATE_TESTS
6847
Tobin Ehlis0788f522015-05-26 16:11:58 -06006848#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -06006849#if GTEST_IS_THREADSAFE
6850struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006851 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006852 VkEvent event;
6853 bool bailout;
6854};
6855
Karl Schultz6addd812016-02-02 17:17:23 -07006856extern "C" void *AddToCommandBuffer(void *arg) {
6857 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006858
Karl Schultz6addd812016-02-02 17:17:23 -07006859 for (int i = 0; i < 10000; i++) {
6860 vkCmdSetEvent(data->commandBuffer, data->event,
6861 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006862 if (data->bailout) {
6863 break;
6864 }
6865 }
6866 return NULL;
6867}
6868
Karl Schultz6addd812016-02-02 17:17:23 -07006869TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006870 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006871
Karl Schultz6addd812016-02-02 17:17:23 -07006872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6873 "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006874
Mike Stroyanaccf7692015-05-12 16:00:45 -06006875 ASSERT_NO_FATAL_FAILURE(InitState());
6876 ASSERT_NO_FATAL_FAILURE(InitViewport());
6877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6878
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006879 // Calls AllocateCommandBuffers
6880 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006881
6882 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006883 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006884
6885 VkEventCreateInfo event_info;
6886 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -06006887 VkResult err;
6888
6889 memset(&event_info, 0, sizeof(event_info));
6890 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
6891
Chia-I Wuf7458c52015-10-26 21:10:41 +08006892 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006893 ASSERT_VK_SUCCESS(err);
6894
Mike Stroyanaccf7692015-05-12 16:00:45 -06006895 err = vkResetEvent(device(), event);
6896 ASSERT_VK_SUCCESS(err);
6897
6898 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006899 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006900 data.event = event;
6901 data.bailout = false;
6902 m_errorMonitor->SetBailout(&data.bailout);
6903 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006904 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006905 // Add many entries to command buffer from this thread at the same time.
6906 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006907
Mike Stroyan4268d1f2015-07-13 14:45:35 -06006908 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006909 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006910
Mike Stroyan10b8cb72016-01-22 15:22:03 -07006911 m_errorMonitor->SetBailout(NULL);
6912
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006913 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -06006914
Chia-I Wuf7458c52015-10-26 21:10:41 +08006915 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -06006916}
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006917#endif // GTEST_IS_THREADSAFE
6918#endif // THREADING_TESTS
6919
Chris Forbes9f7ff632015-05-25 11:13:08 +12006920#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07006921TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006923 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006924
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006925 ASSERT_NO_FATAL_FAILURE(InitState());
6926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6927
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006928 VkShaderModule module;
6929 VkShaderModuleCreateInfo moduleCreateInfo;
6930 struct icd_spv_header spv;
6931
6932 spv.magic = ICD_SPV_MAGIC;
6933 spv.version = ICD_SPV_VERSION;
6934 spv.gen_magic = 0;
6935
6936 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
6937 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006938 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006939 moduleCreateInfo.codeSize = 4;
6940 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006941 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006942
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006943 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006944}
6945
Karl Schultz6addd812016-02-02 17:17:23 -07006946TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006948 "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006949
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006950 ASSERT_NO_FATAL_FAILURE(InitState());
6951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6952
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006953 VkShaderModule module;
6954 VkShaderModuleCreateInfo moduleCreateInfo;
6955 struct icd_spv_header spv;
6956
6957 spv.magic = ~ICD_SPV_MAGIC;
6958 spv.version = ICD_SPV_VERSION;
6959 spv.gen_magic = 0;
6960
6961 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
6962 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07006963 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006964 moduleCreateInfo.codeSize = sizeof(spv) + 10;
6965 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006966 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006967
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006968 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006969}
6970
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006971#if 0
6972// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -07006973TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006975 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006976
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006977 ASSERT_NO_FATAL_FAILURE(InitState());
6978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6979
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006980 VkShaderModule module;
6981 VkShaderModuleCreateInfo moduleCreateInfo;
6982 struct icd_spv_header spv;
6983
6984 spv.magic = ICD_SPV_MAGIC;
6985 spv.version = ~ICD_SPV_VERSION;
6986 spv.gen_magic = 0;
6987
6988 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
6989 moduleCreateInfo.pNext = NULL;
6990
Karl Schultz6addd812016-02-02 17:17:23 -07006991 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006992 moduleCreateInfo.codeSize = sizeof(spv) + 10;
6993 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +08006994 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006995
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006996 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006997}
Chris Forbesb4afd0f2016-04-04 10:48:35 +12006998#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -06006999
Karl Schultz6addd812016-02-02 17:17:23 -07007000TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007002 "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007003
Chris Forbes9f7ff632015-05-25 11:13:08 +12007004 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007005 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +12007006
7007 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007008 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007009 "\n"
7010 "layout(location=0) out float x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007011 "out gl_PerVertex {\n"
7012 " vec4 gl_Position;\n"
7013 "};\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007014 "void main(){\n"
7015 " gl_Position = vec4(1);\n"
7016 " x = 0;\n"
7017 "}\n";
7018 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007019 "#version 450\n"
Chris Forbes9f7ff632015-05-25 11:13:08 +12007020 "\n"
7021 "layout(location=0) out vec4 color;\n"
7022 "void main(){\n"
7023 " color = vec4(1);\n"
7024 "}\n";
7025
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +12007028
7029 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007030 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +12007031 pipe.AddShader(&vs);
7032 pipe.AddShader(&fs);
7033
Chris Forbes9f7ff632015-05-25 11:13:08 +12007034 VkDescriptorSetObj descriptorSet(m_device);
7035 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007036 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +12007037
Tony Barbour5781e8f2015-08-04 16:23:11 -06007038 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +12007039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007040 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +12007041}
Chris Forbes9f7ff632015-05-25 11:13:08 +12007042
Karl Schultz6addd812016-02-02 17:17:23 -07007043TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007045 "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007046
Chris Forbes59cb88d2015-05-25 11:13:13 +12007047 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +12007049
7050 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007051 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007052 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007053 "out gl_PerVertex {\n"
7054 " vec4 gl_Position;\n"
7055 "};\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007056 "void main(){\n"
7057 " gl_Position = vec4(1);\n"
7058 "}\n";
7059 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007060 "#version 450\n"
Chris Forbes59cb88d2015-05-25 11:13:13 +12007061 "\n"
7062 "layout(location=0) in float x;\n"
7063 "layout(location=0) out vec4 color;\n"
7064 "void main(){\n"
7065 " color = vec4(x);\n"
7066 "}\n";
7067
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7069 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +12007070
7071 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007072 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +12007073 pipe.AddShader(&vs);
7074 pipe.AddShader(&fs);
7075
Chris Forbes59cb88d2015-05-25 11:13:13 +12007076 VkDescriptorSetObj descriptorSet(m_device);
7077 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007078 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +12007079
Tony Barbour5781e8f2015-08-04 16:23:11 -06007080 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +12007081
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007082 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +12007083}
7084
Karl Schultz6addd812016-02-02 17:17:23 -07007085TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13007086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007087 "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +13007088
7089 ASSERT_NO_FATAL_FAILURE(InitState());
7090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7091
7092 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007093 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007094 "\n"
7095 "out gl_PerVertex {\n"
7096 " vec4 gl_Position;\n"
7097 "};\n"
7098 "void main(){\n"
7099 " gl_Position = vec4(1);\n"
7100 "}\n";
7101 char const *fsSource =
7102 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007103 "\n"
7104 "in block { layout(location=0) float x; } ins;\n"
7105 "layout(location=0) out vec4 color;\n"
7106 "void main(){\n"
7107 " color = vec4(ins.x);\n"
7108 "}\n";
7109
7110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7112
7113 VkPipelineObj pipe(m_device);
7114 pipe.AddColorAttachment();
7115 pipe.AddShader(&vs);
7116 pipe.AddShader(&fs);
7117
7118 VkDescriptorSetObj descriptorSet(m_device);
7119 descriptorSet.AppendDummy();
7120 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7121
7122 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7123
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007124 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13007125}
7126
Karl Schultz6addd812016-02-02 17:17:23 -07007127TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes0036fd12016-01-26 14:19:49 +13007128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbese9928822016-02-17 14:44:52 +13007129 "Type mismatch on location 0.0: 'ptr to "
Karl Schultz6addd812016-02-02 17:17:23 -07007130 "output arr[2] of float32' vs 'ptr to "
7131 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +13007132
7133 ASSERT_NO_FATAL_FAILURE(InitState());
7134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7135
7136 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007137 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13007138 "\n"
7139 "layout(location=0) out float x[2];\n"
7140 "out gl_PerVertex {\n"
7141 " vec4 gl_Position;\n"
7142 "};\n"
7143 "void main(){\n"
7144 " x[0] = 0; x[1] = 0;\n"
7145 " gl_Position = vec4(1);\n"
7146 "}\n";
7147 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007148 "#version 450\n"
Chris Forbes0036fd12016-01-26 14:19:49 +13007149 "\n"
7150 "layout(location=0) in float x[3];\n"
7151 "layout(location=0) out vec4 color;\n"
7152 "void main(){\n"
7153 " color = vec4(x[0] + x[1] + x[2]);\n"
7154 "}\n";
7155
7156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7158
7159 VkPipelineObj pipe(m_device);
7160 pipe.AddColorAttachment();
7161 pipe.AddShader(&vs);
7162 pipe.AddShader(&fs);
7163
7164 VkDescriptorSetObj descriptorSet(m_device);
7165 descriptorSet.AppendDummy();
7166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7167
7168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7169
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007170 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +13007171}
7172
Karl Schultz6addd812016-02-02 17:17:23 -07007173TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007175 "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007176
Chris Forbesb56af562015-05-25 11:13:17 +12007177 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +12007179
7180 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007181 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007182 "\n"
7183 "layout(location=0) out int x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007184 "out gl_PerVertex {\n"
7185 " vec4 gl_Position;\n"
7186 "};\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007187 "void main(){\n"
7188 " x = 0;\n"
7189 " gl_Position = vec4(1);\n"
7190 "}\n";
7191 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007192 "#version 450\n"
Chris Forbesb56af562015-05-25 11:13:17 +12007193 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007194 "layout(location=0) in float x;\n" /* VS writes int */
Chris Forbesb56af562015-05-25 11:13:17 +12007195 "layout(location=0) out vec4 color;\n"
7196 "void main(){\n"
7197 " color = vec4(x);\n"
7198 "}\n";
7199
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +12007202
7203 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007204 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +12007205 pipe.AddShader(&vs);
7206 pipe.AddShader(&fs);
7207
Chris Forbesb56af562015-05-25 11:13:17 +12007208 VkDescriptorSetObj descriptorSet(m_device);
7209 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +12007211
Tony Barbour5781e8f2015-08-04 16:23:11 -06007212 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +12007213
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007214 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +12007215}
7216
Karl Schultz6addd812016-02-02 17:17:23 -07007217TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbesa3e85f62016-01-15 14:53:11 +13007218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007219 "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +13007220
7221 ASSERT_NO_FATAL_FAILURE(InitState());
7222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7223
7224 char const *vsSource =
7225 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007226 "\n"
7227 "out block { layout(location=0) int x; } outs;\n"
7228 "out gl_PerVertex {\n"
7229 " vec4 gl_Position;\n"
7230 "};\n"
7231 "void main(){\n"
7232 " outs.x = 0;\n"
7233 " gl_Position = vec4(1);\n"
7234 "}\n";
7235 char const *fsSource =
7236 "#version 450\n"
Chris Forbesa3e85f62016-01-15 14:53:11 +13007237 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007238 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
Chris Forbesa3e85f62016-01-15 14:53:11 +13007239 "layout(location=0) out vec4 color;\n"
7240 "void main(){\n"
7241 " color = vec4(ins.x);\n"
7242 "}\n";
7243
7244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7246
7247 VkPipelineObj pipe(m_device);
7248 pipe.AddColorAttachment();
7249 pipe.AddShader(&vs);
7250 pipe.AddShader(&fs);
7251
7252 VkDescriptorSetObj descriptorSet(m_device);
7253 descriptorSet.AppendDummy();
7254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7255
7256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7257
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007258 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13007259}
7260
7261TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
7262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7263 "location 0.0 which is not written by vertex shader");
7264
7265 ASSERT_NO_FATAL_FAILURE(InitState());
7266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7267
7268 char const *vsSource =
7269 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007270 "\n"
7271 "out block { layout(location=1) float x; } outs;\n"
7272 "out gl_PerVertex {\n"
7273 " vec4 gl_Position;\n"
7274 "};\n"
7275 "void main(){\n"
7276 " outs.x = 0;\n"
7277 " gl_Position = vec4(1);\n"
7278 "}\n";
7279 char const *fsSource =
7280 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007281 "\n"
7282 "in block { layout(location=0) float x; } ins;\n"
7283 "layout(location=0) out vec4 color;\n"
7284 "void main(){\n"
7285 " color = vec4(ins.x);\n"
7286 "}\n";
7287
7288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7290
7291 VkPipelineObj pipe(m_device);
7292 pipe.AddColorAttachment();
7293 pipe.AddShader(&vs);
7294 pipe.AddShader(&fs);
7295
7296 VkDescriptorSetObj descriptorSet(m_device);
7297 descriptorSet.AppendDummy();
7298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7299
7300 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007302 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +13007303}
7304
7305TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
7306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7307 "location 0.1 which is not written by vertex shader");
7308
7309 ASSERT_NO_FATAL_FAILURE(InitState());
7310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7311
7312 char const *vsSource =
7313 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007314 "\n"
7315 "out block { layout(location=0, component=0) float x; } outs;\n"
7316 "out gl_PerVertex {\n"
7317 " vec4 gl_Position;\n"
7318 "};\n"
7319 "void main(){\n"
7320 " outs.x = 0;\n"
7321 " gl_Position = vec4(1);\n"
7322 "}\n";
7323 char const *fsSource =
7324 "#version 450\n"
Chris Forbese9928822016-02-17 14:44:52 +13007325 "\n"
7326 "in block { layout(location=0, component=1) float x; } ins;\n"
7327 "layout(location=0) out vec4 color;\n"
7328 "void main(){\n"
7329 " color = vec4(ins.x);\n"
7330 "}\n";
7331
7332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7334
7335 VkPipelineObj pipe(m_device);
7336 pipe.AddColorAttachment();
7337 pipe.AddShader(&vs);
7338 pipe.AddShader(&fs);
7339
7340 VkDescriptorSetObj descriptorSet(m_device);
7341 descriptorSet.AppendDummy();
7342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7343
7344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007346 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +13007347}
7348
Karl Schultz6addd812016-02-02 17:17:23 -07007349TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007351 "location 0 not consumed by VS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007352
Chris Forbesde136e02015-05-25 11:13:28 +12007353 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +12007355
7356 VkVertexInputBindingDescription input_binding;
7357 memset(&input_binding, 0, sizeof(input_binding));
7358
7359 VkVertexInputAttributeDescription input_attrib;
7360 memset(&input_attrib, 0, sizeof(input_attrib));
7361 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7362
7363 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007364 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007365 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07007366 "out gl_PerVertex {\n"
7367 " vec4 gl_Position;\n"
7368 "};\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007369 "void main(){\n"
7370 " gl_Position = vec4(1);\n"
7371 "}\n";
7372 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007373 "#version 450\n"
Chris Forbesde136e02015-05-25 11:13:28 +12007374 "\n"
7375 "layout(location=0) out vec4 color;\n"
7376 "void main(){\n"
7377 " color = vec4(1);\n"
7378 "}\n";
7379
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007380 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7381 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +12007382
7383 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007384 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +12007385 pipe.AddShader(&vs);
7386 pipe.AddShader(&fs);
7387
7388 pipe.AddVertexInputBindings(&input_binding, 1);
7389 pipe.AddVertexInputAttribs(&input_attrib, 1);
7390
Chris Forbesde136e02015-05-25 11:13:28 +12007391 VkDescriptorSetObj descriptorSet(m_device);
7392 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007393 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +12007394
Tony Barbour5781e8f2015-08-04 16:23:11 -06007395 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +12007396
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007397 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +12007398}
7399
Karl Schultz6addd812016-02-02 17:17:23 -07007400TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07007401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007402 "location 0 not consumed by VS");
Chris Forbes7d83cd52016-01-15 11:32:03 +13007403
7404 ASSERT_NO_FATAL_FAILURE(InitState());
7405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7406
7407 VkVertexInputBindingDescription input_binding;
7408 memset(&input_binding, 0, sizeof(input_binding));
7409
7410 VkVertexInputAttributeDescription input_attrib;
7411 memset(&input_attrib, 0, sizeof(input_attrib));
7412 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7413
7414 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007415 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13007416 "\n"
7417 "layout(location=1) in float x;\n"
7418 "out gl_PerVertex {\n"
7419 " vec4 gl_Position;\n"
7420 "};\n"
7421 "void main(){\n"
7422 " gl_Position = vec4(x);\n"
7423 "}\n";
7424 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007425 "#version 450\n"
Chris Forbes7d83cd52016-01-15 11:32:03 +13007426 "\n"
7427 "layout(location=0) out vec4 color;\n"
7428 "void main(){\n"
7429 " color = vec4(1);\n"
7430 "}\n";
7431
7432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7434
7435 VkPipelineObj pipe(m_device);
7436 pipe.AddColorAttachment();
7437 pipe.AddShader(&vs);
7438 pipe.AddShader(&fs);
7439
7440 pipe.AddVertexInputBindings(&input_binding, 1);
7441 pipe.AddVertexInputAttribs(&input_attrib, 1);
7442
7443 VkDescriptorSetObj descriptorSet(m_device);
7444 descriptorSet.AppendDummy();
7445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7446
7447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7448
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007449 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +13007450}
7451
Karl Schultz6addd812016-02-02 17:17:23 -07007452TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
7453 m_errorMonitor->SetDesiredFailureMsg(
7454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007455 "VS consumes input at location 0 but not provided");
7456
Chris Forbes62e8e502015-05-25 11:13:29 +12007457 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +12007459
7460 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007461 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007462 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007463 "layout(location=0) in vec4 x;\n" /* not provided */
Tony Barboure804d202016-01-05 13:37:45 -07007464 "out gl_PerVertex {\n"
7465 " vec4 gl_Position;\n"
7466 "};\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007467 "void main(){\n"
7468 " gl_Position = x;\n"
7469 "}\n";
7470 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007471 "#version 450\n"
Chris Forbes62e8e502015-05-25 11:13:29 +12007472 "\n"
7473 "layout(location=0) out vec4 color;\n"
7474 "void main(){\n"
7475 " color = vec4(1);\n"
7476 "}\n";
7477
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +12007480
7481 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007482 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +12007483 pipe.AddShader(&vs);
7484 pipe.AddShader(&fs);
7485
Chris Forbes62e8e502015-05-25 11:13:29 +12007486 VkDescriptorSetObj descriptorSet(m_device);
7487 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007488 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +12007489
Tony Barbour5781e8f2015-08-04 16:23:11 -06007490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +12007491
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007492 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +12007493}
7494
Karl Schultz6addd812016-02-02 17:17:23 -07007495TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
7496 m_errorMonitor->SetDesiredFailureMsg(
7497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007498 "location 0 does not match VS input type");
7499
Chris Forbesc97d98e2015-05-25 11:13:31 +12007500 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +12007502
7503 VkVertexInputBindingDescription input_binding;
7504 memset(&input_binding, 0, sizeof(input_binding));
7505
7506 VkVertexInputAttributeDescription input_attrib;
7507 memset(&input_attrib, 0, sizeof(input_attrib));
7508 input_attrib.format = VK_FORMAT_R32_SFLOAT;
7509
7510 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007511 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007512 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07007513 "layout(location=0) in int x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07007514 "out gl_PerVertex {\n"
7515 " vec4 gl_Position;\n"
7516 "};\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007517 "void main(){\n"
7518 " gl_Position = vec4(x);\n"
7519 "}\n";
7520 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007521 "#version 450\n"
Chris Forbesc97d98e2015-05-25 11:13:31 +12007522 "\n"
7523 "layout(location=0) out vec4 color;\n"
7524 "void main(){\n"
7525 " color = vec4(1);\n"
7526 "}\n";
7527
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007528 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +12007530
7531 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08007532 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +12007533 pipe.AddShader(&vs);
7534 pipe.AddShader(&fs);
7535
7536 pipe.AddVertexInputBindings(&input_binding, 1);
7537 pipe.AddVertexInputAttribs(&input_attrib, 1);
7538
Chris Forbesc97d98e2015-05-25 11:13:31 +12007539 VkDescriptorSetObj descriptorSet(m_device);
7540 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007541 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +12007542
Tony Barbour5781e8f2015-08-04 16:23:11 -06007543 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +12007544
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007545 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +12007546}
7547
Chris Forbesc68b43c2016-04-06 11:18:47 +12007548TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
7549 m_errorMonitor->SetDesiredFailureMsg(
7550 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7551 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
7552
7553 ASSERT_NO_FATAL_FAILURE(InitState());
7554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7555
7556 char const *vsSource =
7557 "#version 450\n"
7558 "\n"
7559 "out gl_PerVertex {\n"
7560 " vec4 gl_Position;\n"
7561 "};\n"
7562 "void main(){\n"
7563 " gl_Position = vec4(1);\n"
7564 "}\n";
7565 char const *fsSource =
7566 "#version 450\n"
7567 "\n"
7568 "layout(location=0) out vec4 color;\n"
7569 "void main(){\n"
7570 " color = vec4(1);\n"
7571 "}\n";
7572
7573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7575
7576 VkPipelineObj pipe(m_device);
7577 pipe.AddColorAttachment();
7578 pipe.AddShader(&vs);
7579 pipe.AddShader(&vs);
7580 pipe.AddShader(&fs);
7581
7582 VkDescriptorSetObj descriptorSet(m_device);
7583 descriptorSet.AppendDummy();
7584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7585
7586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7587
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007588 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +12007589}
7590
Karl Schultz6addd812016-02-02 17:17:23 -07007591TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007592 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13007593
7594 ASSERT_NO_FATAL_FAILURE(InitState());
7595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7596
7597 VkVertexInputBindingDescription input_binding;
7598 memset(&input_binding, 0, sizeof(input_binding));
7599
7600 VkVertexInputAttributeDescription input_attribs[2];
7601 memset(input_attribs, 0, sizeof(input_attribs));
7602
7603 for (int i = 0; i < 2; i++) {
7604 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
7605 input_attribs[i].location = i;
7606 }
7607
7608 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007609 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007610 "\n"
7611 "layout(location=0) in mat2x4 x;\n"
Tony Barboure804d202016-01-05 13:37:45 -07007612 "out gl_PerVertex {\n"
7613 " vec4 gl_Position;\n"
7614 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007615 "void main(){\n"
7616 " gl_Position = x[0] + x[1];\n"
7617 "}\n";
7618 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007619 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007620 "\n"
7621 "layout(location=0) out vec4 color;\n"
7622 "void main(){\n"
7623 " color = vec4(1);\n"
7624 "}\n";
7625
7626 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7627 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7628
7629 VkPipelineObj pipe(m_device);
7630 pipe.AddColorAttachment();
7631 pipe.AddShader(&vs);
7632 pipe.AddShader(&fs);
7633
7634 pipe.AddVertexInputBindings(&input_binding, 1);
7635 pipe.AddVertexInputAttribs(input_attribs, 2);
7636
7637 VkDescriptorSetObj descriptorSet(m_device);
7638 descriptorSet.AppendDummy();
7639 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7640
7641 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7642
7643 /* expect success */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007644 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13007645}
7646
Chris Forbes2682b242015-11-24 11:13:14 +13007647TEST_F(VkLayerTest, CreatePipelineAttribArrayType)
7648{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007649 m_errorMonitor->ExpectSuccess();
Chris Forbes2682b242015-11-24 11:13:14 +13007650
7651 ASSERT_NO_FATAL_FAILURE(InitState());
7652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7653
7654 VkVertexInputBindingDescription input_binding;
7655 memset(&input_binding, 0, sizeof(input_binding));
7656
7657 VkVertexInputAttributeDescription input_attribs[2];
7658 memset(input_attribs, 0, sizeof(input_attribs));
7659
7660 for (int i = 0; i < 2; i++) {
7661 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
7662 input_attribs[i].location = i;
7663 }
7664
7665 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007666 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007667 "\n"
7668 "layout(location=0) in vec4 x[2];\n"
Tony Barboure804d202016-01-05 13:37:45 -07007669 "out gl_PerVertex {\n"
7670 " vec4 gl_Position;\n"
7671 "};\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007672 "void main(){\n"
7673 " gl_Position = x[0] + x[1];\n"
7674 "}\n";
7675 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12007676 "#version 450\n"
Chris Forbes2682b242015-11-24 11:13:14 +13007677 "\n"
7678 "layout(location=0) out vec4 color;\n"
7679 "void main(){\n"
7680 " color = vec4(1);\n"
7681 "}\n";
7682
7683 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7684 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7685
7686 VkPipelineObj pipe(m_device);
7687 pipe.AddColorAttachment();
7688 pipe.AddShader(&vs);
7689 pipe.AddShader(&fs);
7690
7691 pipe.AddVertexInputBindings(&input_binding, 1);
7692 pipe.AddVertexInputAttribs(input_attribs, 2);
7693
7694 VkDescriptorSetObj descriptorSet(m_device);
7695 descriptorSet.AppendDummy();
7696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7697
7698 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7699
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007700 m_errorMonitor->VerifyNotFound();
Chris Forbes2682b242015-11-24 11:13:14 +13007701}
Chris Forbes2682b242015-11-24 11:13:14 +13007702
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007703TEST_F(VkLayerTest, CreatePipelineSimplePositive)
7704{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007705 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007706
7707 ASSERT_NO_FATAL_FAILURE(InitState());
7708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7709
7710 char const *vsSource =
7711 "#version 450\n"
7712 "out gl_PerVertex {\n"
7713 " vec4 gl_Position;\n"
7714 "};\n"
7715 "void main(){\n"
7716 " gl_Position = vec4(0);\n"
7717 "}\n";
7718 char const *fsSource =
7719 "#version 450\n"
7720 "\n"
7721 "layout(location=0) out vec4 color;\n"
7722 "void main(){\n"
7723 " color = vec4(1);\n"
7724 "}\n";
7725
7726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7728
7729 VkPipelineObj pipe(m_device);
7730 pipe.AddColorAttachment();
7731 pipe.AddShader(&vs);
7732 pipe.AddShader(&fs);
7733
7734 VkDescriptorSetObj descriptorSet(m_device);
7735 descriptorSet.AppendDummy();
7736 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7737
7738 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007740 m_errorMonitor->VerifyNotFound();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007741}
7742
Chris Forbes912c9192016-04-05 17:50:35 +12007743TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch)
7744{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007745 m_errorMonitor->ExpectSuccess();
Chris Forbes912c9192016-04-05 17:50:35 +12007746
7747 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
7748
7749 ASSERT_NO_FATAL_FAILURE(InitState());
7750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7751
7752 char const *vsSource =
7753 "#version 450\n"
7754 "out gl_PerVertex {\n"
7755 " vec4 gl_Position;\n"
7756 "};\n"
7757 "layout(location=0) out vec3 x;\n"
7758 "layout(location=1) out ivec3 y;\n"
7759 "layout(location=2) out vec3 z;\n"
7760 "void main(){\n"
7761 " gl_Position = vec4(0);\n"
7762 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
7763 "}\n";
7764 char const *fsSource =
7765 "#version 450\n"
7766 "\n"
7767 "layout(location=0) out vec4 color;\n"
7768 "layout(location=0) in float x;\n"
7769 "layout(location=1) flat in int y;\n"
7770 "layout(location=2) in vec2 z;\n"
7771 "void main(){\n"
7772 " color = vec4(1 + x + y + z.x);\n"
7773 "}\n";
7774
7775 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7776 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7777
7778 VkPipelineObj pipe(m_device);
7779 pipe.AddColorAttachment();
7780 pipe.AddShader(&vs);
7781 pipe.AddShader(&fs);
7782
7783 VkDescriptorSetObj descriptorSet(m_device);
7784 descriptorSet.AppendDummy();
7785 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7786
7787 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7788
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007789 m_errorMonitor->VerifyNotFound();
Chris Forbes912c9192016-04-05 17:50:35 +12007790}
7791
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007792TEST_F(VkLayerTest, CreatePipelineTessPerVertex)
7793{
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007794 m_errorMonitor->ExpectSuccess();
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007795
7796 ASSERT_NO_FATAL_FAILURE(InitState());
7797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7798
Chris Forbesc1e852d2016-04-04 19:26:42 +12007799 if (!m_device->phy().features().tessellationShader) {
7800 printf("Device does not support tessellation shaders; skipped.\n");
7801 return;
7802 }
7803
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007804 char const *vsSource =
7805 "#version 450\n"
7806 "void main(){}\n";
7807 char const *tcsSource =
7808 "#version 450\n"
7809 "layout(location=0) out int x[];\n"
7810 "layout(vertices=3) out;\n"
7811 "void main(){\n"
7812 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
7813 " gl_TessLevelInner[0] = 1;\n"
7814 " x[gl_InvocationID] = gl_InvocationID;\n"
7815 "}\n";
7816 char const *tesSource =
7817 "#version 450\n"
7818 "layout(triangles, equal_spacing, cw) in;\n"
7819 "layout(location=0) in int x[];\n"
7820 "out gl_PerVertex { vec4 gl_Position; };\n"
7821 "void main(){\n"
7822 " gl_Position.xyz = gl_TessCoord;\n"
7823 " gl_Position.w = x[0] + x[1] + x[2];\n"
7824 "}\n";
7825 char const *fsSource =
7826 "#version 450\n"
7827 "layout(location=0) out vec4 color;\n"
7828 "void main(){\n"
7829 " color = vec4(1);\n"
7830 "}\n";
7831
7832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7833 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
7834 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
7835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7836
7837 VkPipelineInputAssemblyStateCreateInfo iasci{
7838 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
7839 nullptr,
7840 0,
7841 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
7842 VK_FALSE};
7843
Chris Forbesb4cacb62016-04-04 19:15:00 +12007844 VkPipelineTessellationStateCreateInfo tsci{
7845 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
7846 nullptr,
7847 0,
7848 3};
7849
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007850 VkPipelineObj pipe(m_device);
7851 pipe.SetInputAssembly(&iasci);
Chris Forbesb4cacb62016-04-04 19:15:00 +12007852 pipe.SetTessellation(&tsci);
Chris Forbes4ea14fc2016-04-04 18:52:54 +12007853 pipe.AddColorAttachment();
7854 pipe.AddShader(&vs);
7855 pipe.AddShader(&tcs);
7856 pipe.AddShader(&tes);
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 Forbes4ea14fc2016-04-04 18:52:54 +12007866}
7867
Chris Forbesa0ab8152016-04-20 13:34:27 +12007868TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive)
7869{
7870 m_errorMonitor->ExpectSuccess();
7871
7872 ASSERT_NO_FATAL_FAILURE(InitState());
7873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7874
7875 if (!m_device->phy().features().geometryShader) {
7876 printf("Device does not support geometry shaders; skipped.\n");
7877 return;
7878 }
7879
7880 char const *vsSource =
7881 "#version 450\n"
7882 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
7883 "void main(){\n"
7884 " vs_out.x = vec4(1);\n"
7885 "}\n";
7886 char const *gsSource =
7887 "#version 450\n"
7888 "layout(triangles) in;\n"
7889 "layout(triangle_strip, max_vertices=3) out;\n"
7890 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
7891 "out gl_PerVertex { vec4 gl_Position; };\n"
7892 "void main() {\n"
7893 " gl_Position = gs_in[0].x;\n"
7894 " EmitVertex();\n"
7895 "}\n";
7896 char const *fsSource =
7897 "#version 450\n"
7898 "layout(location=0) out vec4 color;\n"
7899 "void main(){\n"
7900 " color = vec4(1);\n"
7901 "}\n";
7902
7903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7904 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
7905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7906
7907 VkPipelineObj pipe(m_device);
7908 pipe.AddColorAttachment();
7909 pipe.AddShader(&vs);
7910 pipe.AddShader(&gs);
7911 pipe.AddShader(&fs);
7912
7913 VkDescriptorSetObj descriptorSet(m_device);
7914 descriptorSet.AppendDummy();
7915 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7916
7917 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7918
7919 m_errorMonitor->VerifyNotFound();
7920}
7921
Chris Forbesa0193bc2016-04-04 19:19:47 +12007922TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch)
7923{
7924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7925 "is per-vertex in tessellation control shader stage "
7926 "but per-patch in tessellation evaluation shader stage");
7927
7928 ASSERT_NO_FATAL_FAILURE(InitState());
7929 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7930
Chris Forbesc1e852d2016-04-04 19:26:42 +12007931 if (!m_device->phy().features().tessellationShader) {
7932 printf("Device does not support tessellation shaders; skipped.\n");
7933 return;
7934 }
7935
Chris Forbesa0193bc2016-04-04 19:19:47 +12007936 char const *vsSource =
7937 "#version 450\n"
7938 "void main(){}\n";
7939 char const *tcsSource =
7940 "#version 450\n"
7941 "layout(location=0) out int x[];\n"
7942 "layout(vertices=3) out;\n"
7943 "void main(){\n"
7944 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
7945 " gl_TessLevelInner[0] = 1;\n"
7946 " x[gl_InvocationID] = gl_InvocationID;\n"
7947 "}\n";
7948 char const *tesSource =
7949 "#version 450\n"
7950 "layout(triangles, equal_spacing, cw) in;\n"
7951 "layout(location=0) patch in int x;\n"
7952 "out gl_PerVertex { vec4 gl_Position; };\n"
7953 "void main(){\n"
7954 " gl_Position.xyz = gl_TessCoord;\n"
7955 " gl_Position.w = x;\n"
7956 "}\n";
7957 char const *fsSource =
7958 "#version 450\n"
7959 "layout(location=0) out vec4 color;\n"
7960 "void main(){\n"
7961 " color = vec4(1);\n"
7962 "}\n";
7963
7964 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7965 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
7966 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
7967 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7968
7969 VkPipelineInputAssemblyStateCreateInfo iasci{
7970 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
7971 nullptr,
7972 0,
7973 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
7974 VK_FALSE};
7975
7976 VkPipelineTessellationStateCreateInfo tsci{
7977 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
7978 nullptr,
7979 0,
7980 3};
7981
7982 VkPipelineObj pipe(m_device);
7983 pipe.SetInputAssembly(&iasci);
7984 pipe.SetTessellation(&tsci);
7985 pipe.AddColorAttachment();
7986 pipe.AddShader(&vs);
7987 pipe.AddShader(&tcs);
7988 pipe.AddShader(&tes);
7989 pipe.AddShader(&fs);
7990
7991 VkDescriptorSetObj descriptorSet(m_device);
7992 descriptorSet.AppendDummy();
7993 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
7994
7995 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
7996
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007997 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +12007998}
7999
Karl Schultz6addd812016-02-02 17:17:23 -07008000TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
8001 m_errorMonitor->SetDesiredFailureMsg(
8002 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008003 "Duplicate vertex input binding descriptions for binding 0");
8004
Chris Forbes280ba2c2015-06-12 11:16:41 +12008005 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06008006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +12008007
8008 /* Two binding descriptions for binding 0 */
8009 VkVertexInputBindingDescription input_bindings[2];
8010 memset(input_bindings, 0, sizeof(input_bindings));
8011
8012 VkVertexInputAttributeDescription input_attrib;
8013 memset(&input_attrib, 0, sizeof(input_attrib));
8014 input_attrib.format = VK_FORMAT_R32_SFLOAT;
8015
8016 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008017 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008018 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008019 "layout(location=0) in float x;\n" /* attrib provided float */
Tony Barboure804d202016-01-05 13:37:45 -07008020 "out gl_PerVertex {\n"
8021 " vec4 gl_Position;\n"
8022 "};\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008023 "void main(){\n"
8024 " gl_Position = vec4(x);\n"
8025 "}\n";
8026 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008027 "#version 450\n"
Chris Forbes280ba2c2015-06-12 11:16:41 +12008028 "\n"
8029 "layout(location=0) out vec4 color;\n"
8030 "void main(){\n"
8031 " color = vec4(1);\n"
8032 "}\n";
8033
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008034 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8035 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +12008036
8037 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +08008038 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +12008039 pipe.AddShader(&vs);
8040 pipe.AddShader(&fs);
8041
8042 pipe.AddVertexInputBindings(input_bindings, 2);
8043 pipe.AddVertexInputAttribs(&input_attrib, 1);
8044
Chris Forbes280ba2c2015-06-12 11:16:41 +12008045 VkDescriptorSetObj descriptorSet(m_device);
8046 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +12008048
Tony Barbour5781e8f2015-08-04 16:23:11 -06008049 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +12008050
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008051 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +12008052}
Chris Forbes8f68b562015-05-25 11:13:32 +12008053
Chris Forbes35efec72016-04-21 14:32:08 +12008054TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) {
8055 m_errorMonitor->ExpectSuccess();
8056
8057 ASSERT_NO_FATAL_FAILURE(InitState());
8058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8059
8060 if (!m_device->phy().features().tessellationShader) {
8061 printf("Device does not support 64bit vertex attributes; skipped.\n");
8062 return;
8063 }
8064
8065 VkVertexInputBindingDescription input_bindings[1];
8066 memset(input_bindings, 0, sizeof(input_bindings));
8067
8068 VkVertexInputAttributeDescription input_attribs[4];
8069 memset(input_attribs, 0, sizeof(input_attribs));
8070 input_attribs[0].location = 0;
8071 input_attribs[0].offset = 0;
8072 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8073 input_attribs[1].location = 2;
8074 input_attribs[1].offset = 32;
8075 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8076 input_attribs[2].location = 4;
8077 input_attribs[2].offset = 64;
8078 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8079 input_attribs[3].location = 6;
8080 input_attribs[3].offset = 96;
8081 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
8082
8083 char const *vsSource =
8084 "#version 450\n"
8085 "\n"
8086 "layout(location=0) in dmat4 x;\n"
8087 "out gl_PerVertex {\n"
8088 " vec4 gl_Position;\n"
8089 "};\n"
8090 "void main(){\n"
8091 " gl_Position = vec4(x[0][0]);\n"
8092 "}\n";
8093 char const *fsSource =
8094 "#version 450\n"
8095 "\n"
8096 "layout(location=0) out vec4 color;\n"
8097 "void main(){\n"
8098 " color = vec4(1);\n"
8099 "}\n";
8100
8101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8103
8104 VkPipelineObj pipe(m_device);
8105 pipe.AddColorAttachment();
8106 pipe.AddShader(&vs);
8107 pipe.AddShader(&fs);
8108
8109 pipe.AddVertexInputBindings(input_bindings, 1);
8110 pipe.AddVertexInputAttribs(input_attribs, 4);
8111
8112 VkDescriptorSetObj descriptorSet(m_device);
8113 descriptorSet.AppendDummy();
8114 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8115
8116 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8117
8118 m_errorMonitor->VerifyNotFound();
8119}
8120
Karl Schultz6addd812016-02-02 17:17:23 -07008121TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008123 "Attachment 0 not written by FS");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008124
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008125 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008126
8127 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008128 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008129 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008130 "out gl_PerVertex {\n"
8131 " vec4 gl_Position;\n"
8132 "};\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008133 "void main(){\n"
8134 " gl_Position = vec4(1);\n"
8135 "}\n";
8136 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008137 "#version 450\n"
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008138 "\n"
8139 "void main(){\n"
8140 "}\n";
8141
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8143 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008144
8145 VkPipelineObj pipe(m_device);
8146 pipe.AddShader(&vs);
8147 pipe.AddShader(&fs);
8148
Chia-I Wu08accc62015-07-07 11:50:03 +08008149 /* set up CB 0, not written */
8150 pipe.AddColorAttachment();
8151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008152
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008153 VkDescriptorSetObj descriptorSet(m_device);
8154 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008155 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008156
Tony Barbour5781e8f2015-08-04 16:23:11 -06008157 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008159 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +12008160}
8161
Karl Schultz6addd812016-02-02 17:17:23 -07008162TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Karl Schultz6addd812016-02-02 17:17:23 -07008163 m_errorMonitor->SetDesiredFailureMsg(
Mark Lobodzinski510e20d2016-02-11 09:26:16 -07008164 VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008165 "FS writes to output location 1 with no matching attachment");
8166
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008167 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008168
8169 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008170 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008171 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008172 "out gl_PerVertex {\n"
8173 " vec4 gl_Position;\n"
8174 "};\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008175 "void main(){\n"
8176 " gl_Position = vec4(1);\n"
8177 "}\n";
8178 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008179 "#version 450\n"
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008180 "\n"
8181 "layout(location=0) out vec4 x;\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008182 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008183 "void main(){\n"
8184 " x = vec4(1);\n"
8185 " y = vec4(1);\n"
8186 "}\n";
8187
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008188 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8189 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008190
8191 VkPipelineObj pipe(m_device);
8192 pipe.AddShader(&vs);
8193 pipe.AddShader(&fs);
8194
Chia-I Wu08accc62015-07-07 11:50:03 +08008195 /* set up CB 0, not written */
8196 pipe.AddColorAttachment();
8197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008198 /* FS writes CB 1, but we don't configure it */
8199
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008200 VkDescriptorSetObj descriptorSet(m_device);
8201 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008202 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008203
Tony Barbour5781e8f2015-08-04 16:23:11 -06008204 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008205
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008206 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +12008207}
8208
Karl Schultz6addd812016-02-02 17:17:23 -07008209TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008211 "does not match FS output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008212
Chris Forbesa36d69e2015-05-25 11:13:44 +12008213 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008214
8215 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008216 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008217 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008218 "out gl_PerVertex {\n"
8219 " vec4 gl_Position;\n"
8220 "};\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008221 "void main(){\n"
8222 " gl_Position = vec4(1);\n"
8223 "}\n";
8224 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008225 "#version 450\n"
Chris Forbesa36d69e2015-05-25 11:13:44 +12008226 "\n"
Karl Schultz6addd812016-02-02 17:17:23 -07008227 "layout(location=0) out ivec4 x;\n" /* not UNORM */
Chris Forbesa36d69e2015-05-25 11:13:44 +12008228 "void main(){\n"
8229 " x = ivec4(1);\n"
8230 "}\n";
8231
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +12008234
8235 VkPipelineObj pipe(m_device);
8236 pipe.AddShader(&vs);
8237 pipe.AddShader(&fs);
8238
Chia-I Wu08accc62015-07-07 11:50:03 +08008239 /* set up CB 0; type is UNORM by default */
8240 pipe.AddColorAttachment();
8241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008242
Chris Forbesa36d69e2015-05-25 11:13:44 +12008243 VkDescriptorSetObj descriptorSet(m_device);
8244 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +12008246
Tony Barbour5781e8f2015-08-04 16:23:11 -06008247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +12008248
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008249 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +12008250}
Chris Forbes7b1b8932015-06-05 14:43:36 +12008251
Karl Schultz6addd812016-02-02 17:17:23 -07008252TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008254 "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008255
Chris Forbes556c76c2015-08-14 12:04:59 +12008256 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +12008257
8258 char const *vsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008259 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008260 "\n"
Tony Barboure804d202016-01-05 13:37:45 -07008261 "out gl_PerVertex {\n"
8262 " vec4 gl_Position;\n"
8263 "};\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008264 "void main(){\n"
8265 " gl_Position = vec4(1);\n"
8266 "}\n";
8267 char const *fsSource =
Chris Forbes38467712016-04-04 17:28:05 +12008268 "#version 450\n"
Chris Forbes556c76c2015-08-14 12:04:59 +12008269 "\n"
8270 "layout(location=0) out vec4 x;\n"
8271 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
8272 "void main(){\n"
8273 " x = vec4(bar.y);\n"
8274 "}\n";
8275
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06008276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +12008278
Chris Forbes556c76c2015-08-14 12:04:59 +12008279 VkPipelineObj pipe(m_device);
8280 pipe.AddShader(&vs);
8281 pipe.AddShader(&fs);
8282
8283 /* set up CB 0; type is UNORM by default */
8284 pipe.AddColorAttachment();
8285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8286
8287 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008288 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +12008289
8290 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8291
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008292 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +12008293}
8294
Chris Forbes5c59e902016-02-26 16:56:09 +13008295TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
8296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8297 "not declared in layout");
8298
8299 ASSERT_NO_FATAL_FAILURE(InitState());
8300
8301 char const *vsSource =
8302 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13008303 "\n"
8304 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
8305 "out gl_PerVertex {\n"
8306 " vec4 gl_Position;\n"
8307 "};\n"
8308 "void main(){\n"
8309 " gl_Position = vec4(consts.x);\n"
8310 "}\n";
8311 char const *fsSource =
8312 "#version 450\n"
Chris Forbes5c59e902016-02-26 16:56:09 +13008313 "\n"
8314 "layout(location=0) out vec4 x;\n"
8315 "void main(){\n"
8316 " x = vec4(1);\n"
8317 "}\n";
8318
8319 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
8320 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8321
8322 VkPipelineObj pipe(m_device);
8323 pipe.AddShader(&vs);
8324 pipe.AddShader(&fs);
8325
8326 /* set up CB 0; type is UNORM by default */
8327 pipe.AddColorAttachment();
8328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8329
8330 VkDescriptorSetObj descriptorSet(m_device);
8331 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
8332
8333 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
8334
8335 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008336 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +13008337}
8338
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008339#endif // SHADER_CHECKER_TESTS
8340
8341#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -06008342TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Karl Schultz6addd812016-02-02 17:17:23 -07008343 m_errorMonitor->SetDesiredFailureMsg(
8344 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008345 "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008346
8347 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008348
8349 // Create an image
8350 VkImage image;
8351
Karl Schultz6addd812016-02-02 17:17:23 -07008352 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8353 const int32_t tex_width = 32;
8354 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008355
8356 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008357 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8358 image_create_info.pNext = NULL;
8359 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8360 image_create_info.format = tex_format;
8361 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008362 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -07008363 image_create_info.extent.depth = 1;
8364 image_create_info.mipLevels = 1;
8365 image_create_info.arrayLayers = 1;
8366 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8367 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8368 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8369 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008370
8371 // Introduce error by sending down a bogus width extent
8372 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008373 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008374
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008375 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -06008376}
8377
Mark Youngc48c4c12016-04-11 14:26:49 -06008378TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
8379 m_errorMonitor->SetDesiredFailureMsg(
8380 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8381 "CreateImage extents is 0 for at least one required dimension");
8382
8383 ASSERT_NO_FATAL_FAILURE(InitState());
8384
8385 // Create an image
8386 VkImage image;
8387
8388 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8389 const int32_t tex_width = 32;
8390 const int32_t tex_height = 32;
8391
8392 VkImageCreateInfo image_create_info = {};
8393 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8394 image_create_info.pNext = NULL;
8395 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8396 image_create_info.format = tex_format;
8397 image_create_info.extent.width = tex_width;
8398 image_create_info.extent.height = tex_height;
8399 image_create_info.extent.depth = 1;
8400 image_create_info.mipLevels = 1;
8401 image_create_info.arrayLayers = 1;
8402 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8403 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8404 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8405 image_create_info.flags = 0;
8406
8407 // Introduce error by sending down a bogus width extent
8408 image_create_info.extent.width = 0;
8409 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
8410
8411 m_errorMonitor->VerifyFound();
8412}
8413
Karl Schultz6addd812016-02-02 17:17:23 -07008414TEST_F(VkLayerTest, UpdateBufferAlignment) {
8415 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mike Stroyana3082432015-09-25 13:39:21 -06008416
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008418 "dstOffset, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008419
Mike Stroyana3082432015-09-25 13:39:21 -06008420 ASSERT_NO_FATAL_FAILURE(InitState());
8421
8422 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8423 vk_testing::Buffer buffer;
8424 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
8425
8426 BeginCommandBuffer();
8427 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008428 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008429 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008430
Mike Stroyana3082432015-09-25 13:39:21 -06008431 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008433 "dataSize, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008434
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008435 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008436 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008437 EndCommandBuffer();
8438}
8439
Karl Schultz6addd812016-02-02 17:17:23 -07008440TEST_F(VkLayerTest, FillBufferAlignment) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008442 "dstOffset, is not a multiple of 4");
Mike Stroyana3082432015-09-25 13:39:21 -06008443
8444 ASSERT_NO_FATAL_FAILURE(InitState());
8445
8446 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8447 vk_testing::Buffer buffer;
8448 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
8449
8450 BeginCommandBuffer();
8451 // Introduce failure by using offset that is not multiple of 4
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008452 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008453 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008454
Mike Stroyana3082432015-09-25 13:39:21 -06008455 // Introduce failure by using size that is not multiple of 4
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008457 "size, is not a multiple of 4");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008458
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008459 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008460
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008461 m_errorMonitor->VerifyFound();
8462
Mike Stroyana3082432015-09-25 13:39:21 -06008463 EndCommandBuffer();
8464}
8465
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008466#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +12008467
Tobin Ehliscde08892015-09-22 10:11:37 -06008468#if IMAGE_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -07008469TEST_F(VkLayerTest, InvalidImageView) {
8470 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -06008471
Karl Schultz6addd812016-02-02 17:17:23 -07008472 m_errorMonitor->SetDesiredFailureMsg(
8473 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008474 "vkCreateImageView called with baseMipLevel 10 ");
8475
Tobin Ehliscde08892015-09-22 10:11:37 -06008476 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -06008477
Mike Stroyana3082432015-09-25 13:39:21 -06008478 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -07008479 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -06008480
Karl Schultz6addd812016-02-02 17:17:23 -07008481 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8482 const int32_t tex_width = 32;
8483 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -06008484
8485 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8487 image_create_info.pNext = NULL;
8488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8489 image_create_info.format = tex_format;
8490 image_create_info.extent.width = tex_width;
8491 image_create_info.extent.height = tex_height;
8492 image_create_info.extent.depth = 1;
8493 image_create_info.mipLevels = 1;
8494 image_create_info.arrayLayers = 1;
8495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8496 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8497 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8498 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -06008499
Chia-I Wuf7458c52015-10-26 21:10:41 +08008500 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -06008501 ASSERT_VK_SUCCESS(err);
8502
8503 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008504 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8505 image_view_create_info.image = image;
8506 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8507 image_view_create_info.format = tex_format;
8508 image_view_create_info.subresourceRange.layerCount = 1;
8509 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
8510 image_view_create_info.subresourceRange.levelCount = 1;
8511 image_view_create_info.subresourceRange.aspectMask =
8512 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -06008513
8514 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07008515 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
8516 &view);
Tobin Ehliscde08892015-09-22 10:11:37 -06008517
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008518 m_errorMonitor->VerifyFound();
Tobin Ehliscde08892015-09-22 10:11:37 -06008519}
Mike Stroyana3082432015-09-25 13:39:21 -06008520
Karl Schultz6addd812016-02-02 17:17:23 -07008521TEST_F(VkLayerTest, InvalidImageViewAspect) {
8522 VkResult err;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008523
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07008524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07008525 "vkCreateImageView: Color image "
8526 "formats must have ONLY the "
8527 "VK_IMAGE_ASPECT_COLOR_BIT set");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008528
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008529 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008530
8531 // Create an image and try to create a view with an invalid aspectMask
Karl Schultz6addd812016-02-02 17:17:23 -07008532 VkImage image;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008533
Karl Schultz6addd812016-02-02 17:17:23 -07008534 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8535 const int32_t tex_width = 32;
8536 const int32_t tex_height = 32;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008537
8538 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008539 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8540 image_create_info.pNext = NULL;
8541 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8542 image_create_info.format = tex_format;
8543 image_create_info.extent.width = tex_width;
8544 image_create_info.extent.height = tex_height;
8545 image_create_info.extent.depth = 1;
8546 image_create_info.mipLevels = 1;
8547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8548 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8549 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8550 image_create_info.flags = 0;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008551
Chia-I Wuf7458c52015-10-26 21:10:41 +08008552 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008553 ASSERT_VK_SUCCESS(err);
8554
8555 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008556 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8557 image_view_create_info.image = image;
8558 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
8559 image_view_create_info.format = tex_format;
8560 image_view_create_info.subresourceRange.baseMipLevel = 0;
8561 image_view_create_info.subresourceRange.levelCount = 1;
8562 // Cause an error by setting an invalid image aspect
8563 image_view_create_info.subresourceRange.aspectMask =
8564 VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008565
8566 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07008567 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
8568 &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008569
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008570 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -06008571}
8572
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008573TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07008574 VkResult err;
8575 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06008576
Karl Schultz6addd812016-02-02 17:17:23 -07008577 m_errorMonitor->SetDesiredFailureMsg(
8578 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008579 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008580
Mike Stroyana3082432015-09-25 13:39:21 -06008581 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06008582
8583 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07008584 VkImage srcImage;
8585 VkImage dstImage;
8586 VkDeviceMemory srcMem;
8587 VkDeviceMemory destMem;
8588 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06008589
8590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8592 image_create_info.pNext = NULL;
8593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8594 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
8595 image_create_info.extent.width = 32;
8596 image_create_info.extent.height = 32;
8597 image_create_info.extent.depth = 1;
8598 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008599 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -07008600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8602 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8603 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008604
Karl Schultz6addd812016-02-02 17:17:23 -07008605 err =
8606 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008607 ASSERT_VK_SUCCESS(err);
8608
Karl Schultz6addd812016-02-02 17:17:23 -07008609 err =
8610 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06008611 ASSERT_VK_SUCCESS(err);
8612
8613 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008614 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008615 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8616 memAlloc.pNext = NULL;
8617 memAlloc.allocationSize = 0;
8618 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008619
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06008620 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008621 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008622 pass =
8623 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06008624 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008625 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008626 ASSERT_VK_SUCCESS(err);
8627
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008628 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06008629 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07008630 pass =
8631 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008632 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008633 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06008634 ASSERT_VK_SUCCESS(err);
8635
8636 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
8637 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008638 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06008639 ASSERT_VK_SUCCESS(err);
8640
8641 BeginCommandBuffer();
8642 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008643 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06008644 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06008645 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008646 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -06008647 copyRegion.srcOffset.x = 0;
8648 copyRegion.srcOffset.y = 0;
8649 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08008650 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008651 copyRegion.dstSubresource.mipLevel = 0;
8652 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06008653 // Introduce failure by forcing the dst layerCount to differ from src
8654 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008655 copyRegion.dstOffset.x = 0;
8656 copyRegion.dstOffset.y = 0;
8657 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06008658 copyRegion.extent.width = 1;
8659 copyRegion.extent.height = 1;
8660 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07008661 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
8662 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06008663 EndCommandBuffer();
8664
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008665 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06008666
Chia-I Wuf7458c52015-10-26 21:10:41 +08008667 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008668 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08008669 vkFreeMemory(m_device->device(), srcMem, NULL);
8670 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06008671}
8672
Tony Barbourd6673642016-05-05 14:46:39 -06008673TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
8674
8675 TEST_DESCRIPTION("Creating images with unsuported formats ");
8676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8679 VkImageObj image(m_device);
8680 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8681 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8682 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8683 VK_IMAGE_TILING_OPTIMAL, 0);
8684 ASSERT_TRUE(image.initialized());
8685
8686 VkFormat unsupported = VK_FORMAT_UNDEFINED;
8687 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
8688 VkFormat format = static_cast<VkFormat>(f);
8689 VkFormatProperties fProps = m_device->format_properties(format);
8690 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 &&
8691 fProps.optimalTilingFeatures == 0) {
8692 unsupported = format;
8693 break;
8694 }
8695 }
8696 if (unsupported != VK_FORMAT_UNDEFINED) {
8697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8698 "vkCreateImage parameter, "
8699 "VkFormat pCreateInfo->format, "
8700 "contains unsupported format");
8701 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
8702 VkImageCreateInfo image_create_info;
8703 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8704 image_create_info.pNext = NULL;
8705 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8706 image_create_info.format = unsupported;
8707 image_create_info.extent.width = 32;
8708 image_create_info.extent.height = 32;
8709 image_create_info.extent.depth = 1;
8710 image_create_info.mipLevels = 1;
8711 image_create_info.arrayLayers = 1;
8712 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8713 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8714 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8715 image_create_info.flags = 0;
8716
8717 VkImage localImage;
8718 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
8719 m_errorMonitor->VerifyFound();
8720
8721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8722 "vkCreateRenderPass parameter, "
8723 "VkFormat in "
8724 "pCreateInfo->pAttachments");
8725 // Create renderpass with unsupported format - Expect FORMAT_UNSUPPORTED
8726 VkAttachmentDescription att;
8727 att.format = unsupported;
8728 att.samples = VK_SAMPLE_COUNT_1_BIT;
8729 att.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
8730 att.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
8731 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
8732 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
8733 att.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8734 att.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8735
8736 VkRenderPassCreateInfo rp_info = {};
8737 VkRenderPass rp;
8738 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8739 rp_info.attachmentCount = 1;
8740 rp_info.pAttachments = &att;
8741 rp_info.subpassCount = 0;
8742 rp_info.pSubpasses = NULL;
8743 vkCreateRenderPass(m_device->handle(), &rp_info, NULL, &rp);
8744 m_errorMonitor->VerifyFound();
8745 }
8746}
8747
8748TEST_F(VkLayerTest, ImageLayerViewTests) {
8749 VkResult ret;
8750 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
8751
8752 ASSERT_NO_FATAL_FAILURE(InitState());
8753
8754 VkImageObj image(m_device);
8755 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8756 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8757 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8758 VK_IMAGE_TILING_OPTIMAL, 0);
8759 ASSERT_TRUE(image.initialized());
8760
8761 VkImageView imgView;
8762 VkImageViewCreateInfo imgViewInfo = {};
8763 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8764 imgViewInfo.image = image.handle();
8765 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
8766 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8767 imgViewInfo.subresourceRange.layerCount = 1;
8768 imgViewInfo.subresourceRange.baseMipLevel = 0;
8769 imgViewInfo.subresourceRange.levelCount = 1;
8770 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8771
8772 m_errorMonitor->SetDesiredFailureMsg(
8773 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8774 "vkCreateImageView called with baseMipLevel");
8775 // View can't have baseMipLevel >= image's mipLevels - Expect
8776 // VIEW_CREATE_ERROR
8777 imgViewInfo.subresourceRange.baseMipLevel = 1;
8778 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8779 m_errorMonitor->VerifyFound();
8780 imgViewInfo.subresourceRange.baseMipLevel = 0;
8781
8782 m_errorMonitor->SetDesiredFailureMsg(
8783 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8784 "vkCreateImageView called with baseArrayLayer");
8785 // View can't have baseArrayLayer >= image's arraySize - Expect
8786 // VIEW_CREATE_ERROR
8787 imgViewInfo.subresourceRange.baseArrayLayer = 1;
8788 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8789 m_errorMonitor->VerifyFound();
8790 imgViewInfo.subresourceRange.baseArrayLayer = 0;
8791
8792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8793 "vkCreateImageView called with 0 in "
8794 "pCreateInfo->subresourceRange."
8795 "levelCount");
8796 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
8797 imgViewInfo.subresourceRange.levelCount = 0;
8798 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8799 m_errorMonitor->VerifyFound();
8800 imgViewInfo.subresourceRange.levelCount = 1;
8801
8802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8803 "vkCreateImageView called with 0 in "
8804 "pCreateInfo->subresourceRange."
8805 "layerCount");
8806 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
8807 imgViewInfo.subresourceRange.layerCount = 0;
8808 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8809 m_errorMonitor->VerifyFound();
8810 imgViewInfo.subresourceRange.layerCount = 1;
8811
8812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8813 "but both must be color formats");
8814 // Can't use depth format for view into color image - Expect INVALID_FORMAT
8815 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
8816 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8817 m_errorMonitor->VerifyFound();
8818 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8819
8820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8821 "Formats MUST be IDENTICAL unless "
8822 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
8823 "was set on image creation.");
8824 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
8825 // VIEW_CREATE_ERROR
8826 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
8827 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8828 m_errorMonitor->VerifyFound();
8829 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
8830
8831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8832 "can support ImageViews with "
8833 "differing formats but they must be "
8834 "in the same compatibility class.");
8835 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
8836 // VIEW_CREATE_ERROR
8837 VkImageCreateInfo mutImgInfo = image.create_info();
8838 VkImage mutImage;
8839 mutImgInfo.format = VK_FORMAT_R8_UINT;
8840 assert(
8841 m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures &
8842 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
8843 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
8844 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
8845 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
8846 ASSERT_VK_SUCCESS(ret);
8847 imgViewInfo.image = mutImage;
8848 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
8849 m_errorMonitor->VerifyFound();
8850 imgViewInfo.image = image.handle();
8851 vkDestroyImage(m_device->handle(), mutImage, NULL);
8852}
8853
8854TEST_F(VkLayerTest, MiscImageLayerTests) {
8855
8856 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
8857
8858 ASSERT_NO_FATAL_FAILURE(InitState());
8859
8860 VkImageObj image(m_device);
8861 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
8862 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
8863 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
8864 VK_IMAGE_TILING_OPTIMAL, 0);
8865 ASSERT_TRUE(image.initialized());
8866
8867 m_errorMonitor->SetDesiredFailureMsg(
8868 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8869 "number of layers in image subresource is zero");
8870 vk_testing::Buffer buffer;
8871 VkMemoryPropertyFlags reqs = 0;
8872 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
8873 VkBufferImageCopy region = {};
8874 region.bufferRowLength = 128;
8875 region.bufferImageHeight = 128;
8876 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8877 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
8878 region.imageSubresource.layerCount = 0;
8879 region.imageExtent.height = 4;
8880 region.imageExtent.width = 4;
8881 region.imageExtent.depth = 1;
8882 m_commandBuffer->BeginCommandBuffer();
8883 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
8884 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
8885 1, &region);
8886 m_errorMonitor->VerifyFound();
8887 region.imageSubresource.layerCount = 1;
8888
8889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8890 "aspectMasks for each region must "
8891 "specify only COLOR or DEPTH or "
8892 "STENCIL");
8893 // Expect MISMATCHED_IMAGE_ASPECT
8894 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
8895 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(),
8896 image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
8897 1, &region);
8898 m_errorMonitor->VerifyFound();
8899 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8900
8901 m_errorMonitor->SetDesiredFailureMsg(
8902 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8903 "If the format of srcImage is a depth, stencil, depth stencil or "
8904 "integer-based format then filter must be VK_FILTER_NEAREST");
8905 // Expect INVALID_FILTER
8906 VkImageObj intImage1(m_device);
8907 intImage1.init(128, 128, VK_FORMAT_R8_UINT,
8908 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
8909 0);
8910 VkImageObj intImage2(m_device);
8911 intImage2.init(128, 128, VK_FORMAT_R8_UINT,
8912 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL,
8913 0);
8914 VkImageBlit blitRegion = {};
8915 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8916 blitRegion.srcSubresource.baseArrayLayer = 0;
8917 blitRegion.srcSubresource.layerCount = 1;
8918 blitRegion.srcSubresource.mipLevel = 0;
8919 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8920 blitRegion.dstSubresource.baseArrayLayer = 0;
8921 blitRegion.dstSubresource.layerCount = 1;
8922 blitRegion.dstSubresource.mipLevel = 0;
8923
8924 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(),
8925 intImage1.layout(), intImage2.handle(), intImage2.layout(),
8926 16, &blitRegion, VK_FILTER_LINEAR);
8927 m_errorMonitor->VerifyFound();
8928
8929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8930 "called with 0 in ppMemoryBarriers");
8931 VkImageMemoryBarrier img_barrier;
8932 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8933 img_barrier.pNext = NULL;
8934 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8935 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8936 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8937 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8938 img_barrier.image = image.handle();
8939 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8940 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8941 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8942 img_barrier.subresourceRange.baseArrayLayer = 0;
8943 img_barrier.subresourceRange.baseMipLevel = 0;
8944 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
8945 img_barrier.subresourceRange.layerCount = 0;
8946 img_barrier.subresourceRange.levelCount = 1;
8947 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(),
8948 VK_PIPELINE_STAGE_HOST_BIT,
8949 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
8950 nullptr, 1, &img_barrier);
8951 m_errorMonitor->VerifyFound();
8952 img_barrier.subresourceRange.layerCount = 1;
8953}
8954
8955TEST_F(VkLayerTest, ImageFormatLimits) {
8956
8957 TEST_DESCRIPTION("Exceed the limits of image format ");
8958
8959 m_errorMonitor->SetDesiredFailureMsg(
8960 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8961 "CreateImage extents exceed allowable limits for format");
8962 VkImageCreateInfo image_create_info = {};
8963 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8964 image_create_info.pNext = NULL;
8965 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8966 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
8967 image_create_info.extent.width = 32;
8968 image_create_info.extent.height = 32;
8969 image_create_info.extent.depth = 1;
8970 image_create_info.mipLevels = 1;
8971 image_create_info.arrayLayers = 1;
8972 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8973 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8974 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8975 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8976 image_create_info.flags = 0;
8977
8978 VkImage nullImg;
8979 VkImageFormatProperties imgFmtProps;
8980 vkGetPhysicalDeviceImageFormatProperties(
8981 gpu(), image_create_info.format, image_create_info.imageType,
8982 image_create_info.tiling, image_create_info.usage,
8983 image_create_info.flags, &imgFmtProps);
8984 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
8985 // Expect INVALID_FORMAT_LIMITS_VIOLATION
8986 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
8987 m_errorMonitor->VerifyFound();
8988 image_create_info.extent.depth = 1;
8989
8990 m_errorMonitor->SetDesiredFailureMsg(
8991 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8992 "exceeds allowable maximum supported by format of");
8993 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
8994 // Expect INVALID_FORMAT_LIMITS_VIOLATION
8995 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
8996 m_errorMonitor->VerifyFound();
8997 image_create_info.mipLevels = 1;
8998
8999 m_errorMonitor->SetDesiredFailureMsg(
9000 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9001 "exceeds allowable maximum supported by format of");
9002 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
9003 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9004 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9005 m_errorMonitor->VerifyFound();
9006 image_create_info.arrayLayers = 1;
9007
9008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9009 "is not supported by format");
9010 int samples = imgFmtProps.sampleCounts >> 1;
9011 image_create_info.samples = (VkSampleCountFlagBits)samples;
9012 // Expect INVALID_FORMAT_LIMITS_VIOLATION
9013 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9014 m_errorMonitor->VerifyFound();
9015 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9016
9017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9018 "pCreateInfo->initialLayout, must be "
9019 "VK_IMAGE_LAYOUT_UNDEFINED or "
9020 "VK_IMAGE_LAYOUT_PREINITIALIZED");
9021 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9022 // Expect INVALID_LAYOUT
9023 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
9024 m_errorMonitor->VerifyFound();
9025 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9026}
9027
Karl Schultz6addd812016-02-02 17:17:23 -07009028TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -06009029 VkResult err;
9030 bool pass;
9031
9032 // Create color images with different format sizes and try to copy between them
9033 m_errorMonitor->SetDesiredFailureMsg(
9034 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9035 "vkCmdCopyImage called with unmatched source and dest image format sizes");
9036
9037 ASSERT_NO_FATAL_FAILURE(InitState());
9038
9039 // Create two images of different types and try to copy between them
9040 VkImage srcImage;
9041 VkImage dstImage;
9042 VkDeviceMemory srcMem;
9043 VkDeviceMemory destMem;
9044 VkMemoryRequirements memReqs;
9045
9046 VkImageCreateInfo image_create_info = {};
9047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9048 image_create_info.pNext = NULL;
9049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9050 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9051 image_create_info.extent.width = 32;
9052 image_create_info.extent.height = 32;
9053 image_create_info.extent.depth = 1;
9054 image_create_info.mipLevels = 1;
9055 image_create_info.arrayLayers = 1;
9056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9058 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9059 image_create_info.flags = 0;
9060
9061 err =
9062 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
9063 ASSERT_VK_SUCCESS(err);
9064
9065 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
9066 // Introduce failure by creating second image with a different-sized format.
9067 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
9068
9069 err =
9070 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
9071 ASSERT_VK_SUCCESS(err);
9072
9073 // Allocate memory
9074 VkMemoryAllocateInfo memAlloc = {};
9075 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9076 memAlloc.pNext = NULL;
9077 memAlloc.allocationSize = 0;
9078 memAlloc.memoryTypeIndex = 0;
9079
9080 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
9081 memAlloc.allocationSize = memReqs.size;
9082 pass =
9083 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
9084 ASSERT_TRUE(pass);
9085 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
9086 ASSERT_VK_SUCCESS(err);
9087
9088 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
9089 memAlloc.allocationSize = memReqs.size;
9090 pass =
9091 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
9092 ASSERT_TRUE(pass);
9093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
9094 ASSERT_VK_SUCCESS(err);
9095
9096 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9097 ASSERT_VK_SUCCESS(err);
9098 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
9099 ASSERT_VK_SUCCESS(err);
9100
9101 BeginCommandBuffer();
9102 VkImageCopy copyRegion;
9103 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9104 copyRegion.srcSubresource.mipLevel = 0;
9105 copyRegion.srcSubresource.baseArrayLayer = 0;
9106 copyRegion.srcSubresource.layerCount = 0;
9107 copyRegion.srcOffset.x = 0;
9108 copyRegion.srcOffset.y = 0;
9109 copyRegion.srcOffset.z = 0;
9110 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9111 copyRegion.dstSubresource.mipLevel = 0;
9112 copyRegion.dstSubresource.baseArrayLayer = 0;
9113 copyRegion.dstSubresource.layerCount = 0;
9114 copyRegion.dstOffset.x = 0;
9115 copyRegion.dstOffset.y = 0;
9116 copyRegion.dstOffset.z = 0;
9117 copyRegion.extent.width = 1;
9118 copyRegion.extent.height = 1;
9119 copyRegion.extent.depth = 1;
9120 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9121 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
9122 EndCommandBuffer();
9123
9124 m_errorMonitor->VerifyFound();
9125
9126 vkDestroyImage(m_device->device(), srcImage, NULL);
9127 vkDestroyImage(m_device->device(), dstImage, NULL);
9128 vkFreeMemory(m_device->device(), srcMem, NULL);
9129 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009130}
9131
Karl Schultz6addd812016-02-02 17:17:23 -07009132TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
9133 VkResult err;
9134 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009135
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009136 // Create a color image and a depth/stencil image and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009137 m_errorMonitor->SetDesiredFailureMsg(
9138 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009139 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009140
Mike Stroyana3082432015-09-25 13:39:21 -06009141 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009142
9143 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009144 VkImage srcImage;
9145 VkImage dstImage;
9146 VkDeviceMemory srcMem;
9147 VkDeviceMemory destMem;
9148 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009149
9150 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009151 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9152 image_create_info.pNext = NULL;
9153 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9154 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9155 image_create_info.extent.width = 32;
9156 image_create_info.extent.height = 32;
9157 image_create_info.extent.depth = 1;
9158 image_create_info.mipLevels = 1;
9159 image_create_info.arrayLayers = 1;
9160 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9161 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
9162 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9163 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009164
Karl Schultz6addd812016-02-02 17:17:23 -07009165 err =
9166 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009167 ASSERT_VK_SUCCESS(err);
9168
Karl Schultzbdb75952016-04-19 11:36:49 -06009169 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
9170
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009171 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -07009172 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -06009173 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
9174 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009175
Karl Schultz6addd812016-02-02 17:17:23 -07009176 err =
9177 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009178 ASSERT_VK_SUCCESS(err);
9179
9180 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009181 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009182 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9183 memAlloc.pNext = NULL;
9184 memAlloc.allocationSize = 0;
9185 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009186
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009187 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009188 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009189 pass =
9190 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009191 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009192 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009193 ASSERT_VK_SUCCESS(err);
9194
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009195 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009196 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009197 pass =
9198 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009199 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009200 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009201 ASSERT_VK_SUCCESS(err);
9202
9203 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9204 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009205 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009206 ASSERT_VK_SUCCESS(err);
9207
9208 BeginCommandBuffer();
9209 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009210 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009211 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009212 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009213 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009214 copyRegion.srcOffset.x = 0;
9215 copyRegion.srcOffset.y = 0;
9216 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009217 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009218 copyRegion.dstSubresource.mipLevel = 0;
9219 copyRegion.dstSubresource.baseArrayLayer = 0;
9220 copyRegion.dstSubresource.layerCount = 0;
9221 copyRegion.dstOffset.x = 0;
9222 copyRegion.dstOffset.y = 0;
9223 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009224 copyRegion.extent.width = 1;
9225 copyRegion.extent.height = 1;
9226 copyRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009227 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9228 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009229 EndCommandBuffer();
9230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009231 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009232
Chia-I Wuf7458c52015-10-26 21:10:41 +08009233 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009234 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009235 vkFreeMemory(m_device->device(), srcMem, NULL);
9236 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009237}
9238
Karl Schultz6addd812016-02-02 17:17:23 -07009239TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
9240 VkResult err;
9241 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009242
Karl Schultz6addd812016-02-02 17:17:23 -07009243 m_errorMonitor->SetDesiredFailureMsg(
9244 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009245 "vkCmdResolveImage called with source sample count less than 2.");
9246
Mike Stroyana3082432015-09-25 13:39:21 -06009247 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009248
9249 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07009250 VkImage srcImage;
9251 VkImage dstImage;
9252 VkDeviceMemory srcMem;
9253 VkDeviceMemory destMem;
9254 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009255
9256 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9258 image_create_info.pNext = NULL;
9259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9260 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9261 image_create_info.extent.width = 32;
9262 image_create_info.extent.height = 1;
9263 image_create_info.extent.depth = 1;
9264 image_create_info.mipLevels = 1;
9265 image_create_info.arrayLayers = 1;
9266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9268 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
9269 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009270
Karl Schultz6addd812016-02-02 17:17:23 -07009271 err =
9272 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009273 ASSERT_VK_SUCCESS(err);
9274
Karl Schultz6addd812016-02-02 17:17:23 -07009275 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009276
Karl Schultz6addd812016-02-02 17:17:23 -07009277 err =
9278 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009279 ASSERT_VK_SUCCESS(err);
9280
9281 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009282 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009283 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9284 memAlloc.pNext = NULL;
9285 memAlloc.allocationSize = 0;
9286 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009287
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009288 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009289 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009290 pass =
9291 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009292 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009293 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009294 ASSERT_VK_SUCCESS(err);
9295
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009296 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009297 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009298 pass =
9299 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009300 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009301 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009302 ASSERT_VK_SUCCESS(err);
9303
9304 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9305 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009306 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009307 ASSERT_VK_SUCCESS(err);
9308
9309 BeginCommandBuffer();
9310 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009311 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9312 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009313 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009314 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009315 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009316 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009317 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009318 resolveRegion.srcOffset.x = 0;
9319 resolveRegion.srcOffset.y = 0;
9320 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009321 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009322 resolveRegion.dstSubresource.mipLevel = 0;
9323 resolveRegion.dstSubresource.baseArrayLayer = 0;
9324 resolveRegion.dstSubresource.layerCount = 0;
9325 resolveRegion.dstOffset.x = 0;
9326 resolveRegion.dstOffset.y = 0;
9327 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009328 resolveRegion.extent.width = 1;
9329 resolveRegion.extent.height = 1;
9330 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009331 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9332 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009333 EndCommandBuffer();
9334
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009335 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009336
Chia-I Wuf7458c52015-10-26 21:10:41 +08009337 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009338 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009339 vkFreeMemory(m_device->device(), srcMem, NULL);
9340 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009341}
9342
Karl Schultz6addd812016-02-02 17:17:23 -07009343TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
9344 VkResult err;
9345 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009346
Karl Schultz6addd812016-02-02 17:17:23 -07009347 m_errorMonitor->SetDesiredFailureMsg(
9348 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009349 "vkCmdResolveImage called with dest sample count greater than 1.");
9350
Mike Stroyana3082432015-09-25 13:39:21 -06009351 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009352
Chris Forbesa7530692016-05-08 12:35:39 +12009353 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -07009354 VkImage srcImage;
9355 VkImage dstImage;
9356 VkDeviceMemory srcMem;
9357 VkDeviceMemory destMem;
9358 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009359
9360 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009361 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9362 image_create_info.pNext = NULL;
9363 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9364 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9365 image_create_info.extent.width = 32;
9366 image_create_info.extent.height = 1;
9367 image_create_info.extent.depth = 1;
9368 image_create_info.mipLevels = 1;
9369 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +12009370 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07009371 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9372 // Note: Some implementations expect color attachment usage for any
9373 // multisample surface
9374 image_create_info.usage =
9375 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9376 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009377
Karl Schultz6addd812016-02-02 17:17:23 -07009378 err =
9379 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009380 ASSERT_VK_SUCCESS(err);
9381
Karl Schultz6addd812016-02-02 17:17:23 -07009382 // Note: Some implementations expect color attachment usage for any
9383 // multisample surface
9384 image_create_info.usage =
9385 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009386
Karl Schultz6addd812016-02-02 17:17:23 -07009387 err =
9388 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009389 ASSERT_VK_SUCCESS(err);
9390
9391 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009392 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009393 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9394 memAlloc.pNext = NULL;
9395 memAlloc.allocationSize = 0;
9396 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009397
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009398 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009399 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009400 pass =
9401 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009402 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009403 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009404 ASSERT_VK_SUCCESS(err);
9405
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009406 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009407 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009408 pass =
9409 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009410 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009411 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009412 ASSERT_VK_SUCCESS(err);
9413
9414 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9415 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009416 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009417 ASSERT_VK_SUCCESS(err);
9418
9419 BeginCommandBuffer();
9420 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009421 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9422 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009423 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009424 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009425 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009426 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009427 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009428 resolveRegion.srcOffset.x = 0;
9429 resolveRegion.srcOffset.y = 0;
9430 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009431 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009432 resolveRegion.dstSubresource.mipLevel = 0;
9433 resolveRegion.dstSubresource.baseArrayLayer = 0;
9434 resolveRegion.dstSubresource.layerCount = 0;
9435 resolveRegion.dstOffset.x = 0;
9436 resolveRegion.dstOffset.y = 0;
9437 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009438 resolveRegion.extent.width = 1;
9439 resolveRegion.extent.height = 1;
9440 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009441 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9442 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009443 EndCommandBuffer();
9444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009445 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009446
Chia-I Wuf7458c52015-10-26 21:10:41 +08009447 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009448 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009449 vkFreeMemory(m_device->device(), srcMem, NULL);
9450 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009451}
9452
Karl Schultz6addd812016-02-02 17:17:23 -07009453TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
9454 VkResult err;
9455 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009456
Karl Schultz6addd812016-02-02 17:17:23 -07009457 m_errorMonitor->SetDesiredFailureMsg(
9458 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009459 "vkCmdResolveImage called with unmatched source and dest formats.");
9460
Mike Stroyana3082432015-09-25 13:39:21 -06009461 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009462
9463 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009464 VkImage srcImage;
9465 VkImage dstImage;
9466 VkDeviceMemory srcMem;
9467 VkDeviceMemory destMem;
9468 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009469
9470 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9472 image_create_info.pNext = NULL;
9473 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9474 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9475 image_create_info.extent.width = 32;
9476 image_create_info.extent.height = 1;
9477 image_create_info.extent.depth = 1;
9478 image_create_info.mipLevels = 1;
9479 image_create_info.arrayLayers = 1;
9480 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
9481 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9482 // Note: Some implementations expect color attachment usage for any
9483 // multisample surface
9484 image_create_info.usage =
9485 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9486 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009487
Karl Schultz6addd812016-02-02 17:17:23 -07009488 err =
9489 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009490 ASSERT_VK_SUCCESS(err);
9491
Karl Schultz6addd812016-02-02 17:17:23 -07009492 // Set format to something other than source image
9493 image_create_info.format = VK_FORMAT_R32_SFLOAT;
9494 // Note: Some implementations expect color attachment usage for any
9495 // multisample surface
9496 image_create_info.usage =
9497 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009499
Karl Schultz6addd812016-02-02 17:17:23 -07009500 err =
9501 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009502 ASSERT_VK_SUCCESS(err);
9503
9504 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009505 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009506 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9507 memAlloc.pNext = NULL;
9508 memAlloc.allocationSize = 0;
9509 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009510
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009511 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009512 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009513 pass =
9514 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009515 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009516 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009517 ASSERT_VK_SUCCESS(err);
9518
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009519 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009520 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009521 pass =
9522 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009523 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009525 ASSERT_VK_SUCCESS(err);
9526
9527 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9528 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009529 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009530 ASSERT_VK_SUCCESS(err);
9531
9532 BeginCommandBuffer();
9533 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009534 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9535 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009536 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009537 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009538 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009539 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009540 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009541 resolveRegion.srcOffset.x = 0;
9542 resolveRegion.srcOffset.y = 0;
9543 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009544 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009545 resolveRegion.dstSubresource.mipLevel = 0;
9546 resolveRegion.dstSubresource.baseArrayLayer = 0;
9547 resolveRegion.dstSubresource.layerCount = 0;
9548 resolveRegion.dstOffset.x = 0;
9549 resolveRegion.dstOffset.y = 0;
9550 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009551 resolveRegion.extent.width = 1;
9552 resolveRegion.extent.height = 1;
9553 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009554 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9555 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009556 EndCommandBuffer();
9557
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009558 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009559
Chia-I Wuf7458c52015-10-26 21:10:41 +08009560 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009561 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009562 vkFreeMemory(m_device->device(), srcMem, NULL);
9563 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009564}
9565
Karl Schultz6addd812016-02-02 17:17:23 -07009566TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
9567 VkResult err;
9568 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -06009569
Karl Schultz6addd812016-02-02 17:17:23 -07009570 m_errorMonitor->SetDesiredFailureMsg(
9571 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009572 "vkCmdResolveImage called with unmatched source and dest image types.");
9573
Mike Stroyana3082432015-09-25 13:39:21 -06009574 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -06009575
9576 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -07009577 VkImage srcImage;
9578 VkImage dstImage;
9579 VkDeviceMemory srcMem;
9580 VkDeviceMemory destMem;
9581 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -06009582
9583 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009584 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9585 image_create_info.pNext = NULL;
9586 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9587 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
9588 image_create_info.extent.width = 32;
9589 image_create_info.extent.height = 1;
9590 image_create_info.extent.depth = 1;
9591 image_create_info.mipLevels = 1;
9592 image_create_info.arrayLayers = 1;
9593 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
9594 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9595 // Note: Some implementations expect color attachment usage for any
9596 // multisample surface
9597 image_create_info.usage =
9598 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9599 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009600
Karl Schultz6addd812016-02-02 17:17:23 -07009601 err =
9602 vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009603 ASSERT_VK_SUCCESS(err);
9604
Karl Schultz6addd812016-02-02 17:17:23 -07009605 image_create_info.imageType = VK_IMAGE_TYPE_1D;
9606 // Note: Some implementations expect color attachment usage for any
9607 // multisample surface
9608 image_create_info.usage =
9609 VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9610 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009611
Karl Schultz6addd812016-02-02 17:17:23 -07009612 err =
9613 vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009617 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009618 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9619 memAlloc.pNext = NULL;
9620 memAlloc.allocationSize = 0;
9621 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009622
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -06009623 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009624 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009625 pass =
9626 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009627 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009628 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009629 ASSERT_VK_SUCCESS(err);
9630
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009631 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -06009632 memAlloc.allocationSize = memReqs.size;
Karl Schultz6addd812016-02-02 17:17:23 -07009633 pass =
9634 m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06009635 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009636 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -06009637 ASSERT_VK_SUCCESS(err);
9638
9639 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
9640 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009641 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -06009642 ASSERT_VK_SUCCESS(err);
9643
9644 BeginCommandBuffer();
9645 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -07009646 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
9647 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -06009648 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009649 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -06009650 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -06009651 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009652 resolveRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009653 resolveRegion.srcOffset.x = 0;
9654 resolveRegion.srcOffset.y = 0;
9655 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +08009656 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009657 resolveRegion.dstSubresource.mipLevel = 0;
9658 resolveRegion.dstSubresource.baseArrayLayer = 0;
9659 resolveRegion.dstSubresource.layerCount = 0;
9660 resolveRegion.dstOffset.x = 0;
9661 resolveRegion.dstOffset.y = 0;
9662 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -06009663 resolveRegion.extent.width = 1;
9664 resolveRegion.extent.height = 1;
9665 resolveRegion.extent.depth = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07009666 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage,
9667 VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -06009668 EndCommandBuffer();
9669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009670 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -06009671
Chia-I Wuf7458c52015-10-26 21:10:41 +08009672 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009673 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009674 vkFreeMemory(m_device->device(), srcMem, NULL);
9675 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -06009676}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009677
Karl Schultz6addd812016-02-02 17:17:23 -07009678TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009679 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -07009680 // to using a DS format, then cause it to hit error due to COLOR_BIT not
9681 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009682 // The image format check comes 2nd in validation so we trigger it first,
9683 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -07009684 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009685
Karl Schultz6addd812016-02-02 17:17:23 -07009686 m_errorMonitor->SetDesiredFailureMsg(
9687 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009688 "Combination depth/stencil image formats can have only the ");
9689
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009690 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009691
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009693 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
9694 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009695
9696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9698 ds_pool_ci.pNext = NULL;
9699 ds_pool_ci.maxSets = 1;
9700 ds_pool_ci.poolSizeCount = 1;
9701 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009702
9703 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07009704 err =
9705 vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009706 ASSERT_VK_SUCCESS(err);
9707
9708 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009709 dsl_binding.binding = 0;
9710 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
9711 dsl_binding.descriptorCount = 1;
9712 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9713 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009714
9715 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009716 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9717 ds_layout_ci.pNext = NULL;
9718 ds_layout_ci.bindingCount = 1;
9719 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009720 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009721 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
9722 &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009723 ASSERT_VK_SUCCESS(err);
9724
9725 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009726 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009727 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009728 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009729 alloc_info.descriptorPool = ds_pool;
9730 alloc_info.pSetLayouts = &ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07009731 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info,
9732 &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009733 ASSERT_VK_SUCCESS(err);
9734
Karl Schultz6addd812016-02-02 17:17:23 -07009735 VkImage image_bad;
9736 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009737 // One bad format and one good format for Color attachment
Karl Schultz6addd812016-02-02 17:17:23 -07009738 const VkFormat tex_format_bad = VK_FORMAT_D32_SFLOAT_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009739 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07009740 const int32_t tex_width = 32;
9741 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009742
9743 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009744 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9745 image_create_info.pNext = NULL;
9746 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9747 image_create_info.format = tex_format_bad;
9748 image_create_info.extent.width = tex_width;
9749 image_create_info.extent.height = tex_height;
9750 image_create_info.extent.depth = 1;
9751 image_create_info.mipLevels = 1;
9752 image_create_info.arrayLayers = 1;
9753 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9754 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9755 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
9756 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
9757 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009758
Karl Schultz6addd812016-02-02 17:17:23 -07009759 err =
9760 vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009761 ASSERT_VK_SUCCESS(err);
9762 image_create_info.format = tex_format_good;
Karl Schultz6addd812016-02-02 17:17:23 -07009763 image_create_info.usage =
9764 VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
9765 err = vkCreateImage(m_device->device(), &image_create_info, NULL,
9766 &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009767 ASSERT_VK_SUCCESS(err);
9768
9769 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009770 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9771 image_view_create_info.image = image_bad;
9772 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
9773 image_view_create_info.format = tex_format_bad;
9774 image_view_create_info.subresourceRange.baseArrayLayer = 0;
9775 image_view_create_info.subresourceRange.baseMipLevel = 0;
9776 image_view_create_info.subresourceRange.layerCount = 1;
9777 image_view_create_info.subresourceRange.levelCount = 1;
9778 image_view_create_info.subresourceRange.aspectMask =
9779 VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009780
9781 VkImageView view;
Karl Schultz6addd812016-02-02 17:17:23 -07009782 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL,
9783 &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009784
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009785 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009786
Chia-I Wuf7458c52015-10-26 21:10:41 +08009787 vkDestroyImage(m_device->device(), image_bad, NULL);
9788 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08009789 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9790 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009791}
Tobin Ehliscde08892015-09-22 10:11:37 -06009792#endif // IMAGE_TESTS
9793
Tony Barbour300a6082015-04-07 13:44:53 -06009794int main(int argc, char **argv) {
9795 int result;
9796
Cody Northrop8e54a402016-03-08 22:25:52 -07009797#ifdef ANDROID
9798 int vulkanSupport = InitVulkan();
9799 if (vulkanSupport == 0)
9800 return 1;
9801#endif
9802
Tony Barbour300a6082015-04-07 13:44:53 -06009803 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -06009804 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -06009805
9806 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
9807
9808 result = RUN_ALL_TESTS();
9809
Tony Barbour6918cd52015-04-09 12:58:51 -06009810 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -06009811 return result;
9812}